SENEZCONSOLE Tutorial - How to use awesome SENEZCONSOLE

ninetimesdissemblingΛογισμικό & κατασκευή λογ/κού

10 Νοε 2012 (πριν από 4 χρόνια και 11 μήνες)

301 εμφανίσεις

By Senez

Updated mr Hanley
10/20/2009

1

Making a reusable classes folder


On your computer, make a new folder
on your C:
\

drive called Reusable
Classes


Copy the latest versions of the 4 Senez
Console files to this directory


SenezConsole.class


Cstyle.class


SenezReader.class


SenezConsole$1.class

2

Telling your IDE about SC


If you are using
NetBeans
,


Select your project and then choose File…Project Properties


Choose Libraries, then click Add Jar/Folder


Highlight the C:
\
Reusable Classes Folder and Choose Open


Reusable Classes will now be listed under the Compile Time
Libraries


YOU MUST DO THIS FOR EACH PROJECT!!!!!!!!!!!




3

If you are using JBuilder 2006

In the main toolbar:



Tools


Configure


JDKs…

STEP 1

4

How to add SenezConsole to your project!

Click the Add button



STEP 2

5

How to add SenezConsole to your project!

STEP 3

Find the Reusable
classes folder and
click OK

Then click OK on the
Configure JDK’s
window to return to
the project

This folder can be
found at

C:
\
Reusable Classes

Note: make sure you take the whole classes folder!

6

How to add SenezConsole to your project!

STEP 4

Click on the Make
Project button near
the top

Note:

If get errors, make sure you added that folder for the right DK, and if you did it
wrong, just change the JDK, and add the classes folder again (if you don’t know
how to do this, just ask Senez or Hanley)

7

Starting from a new project

Create a new instance of
SenezConsole

Use ‘sc’ instead of
‘System.out’

Use ‘sc.input’ instead of
Scanner or EasyReader

Note:

You can easily do this by using the search and replace feature of JBuilder. You can
find this in the Edit menu.

Ex: delete line 6, and then change every line, like line 7, from ‘scan’ to ‘sc.input’,
like in line 5


Its easy!!

8

Converting from a finished
project

Make an instance of
SenezConsole

The usual name is ‘sc’, but
you can use whatever you
want

Note:

If your program is entirely in the main method, you have to instantiate
SenezConsole inside the main. Other than that, it is always a good idea to make it
a global (outside of any methods)

Ex: moving line 2 to a new line in between lines 3 and 4

STEP 1

9

Converting from a finished
project

You need to replace all
‘System.out’ lines with ‘sc’

(or whatever you called it)


You don’t need to keep the
old line, this is just to show
you what has to be changed

Note:

You can easily do this by using the search and replace feature of JBuilder. You can
find this in the Edit menu.

Ex: change every line, like line 4, from ‘System.out’ to ‘sc’, like in line 5


STEP 2

10

Converting from a finished
project

You need to delete all
Scanner or EasyReader
instances.

Instead of using the
Scanner or EasyReader,
use ‘sc.input’

Note:

When changing the Scanner to ‘sc.input’, make sure you also change the line from
‘nextInt’ to ‘readInt’, or ‘nextWord’ to ‘readWord’, because my methods are different

Ex: delete line 6, and then change every line, like line 7, from ‘scan’ to ‘sc.input’,
like in line 5


FINAL STEP

11

Using SenezConsole

General

public void setBackgroundColor(Color col)


changes the color of the console’s background


public void setTextColor(Color col)


changes the color of the console’s text


public void setFont(Font f)


changes the font used in the console


public void setFontSize(int s)


changes the size of the font being used in the console


12

Using SenezConsole

Printing text

public void print(…)


prints parameters to screen


public void println(…)


prints parameters to screen and drops to new line



13

Using SenezConsole

Reading input with SenezReader

public char readChar()


returns the last char that was typed

public double readDouble()


returns the last double that was typed

public int readInt()


returns the last int that was typed

public String readLine()


returns the last entire line that was typed (may contain
spaces)

public String readWord()


returns the last word that was typed (no spaces)


14

Code Samples

//simple printing

public class Example1 {


public static void main(String[] args) {


SenezConsole sc = new SenezConsole();


sc.println("Hello, world");


}

}

15

More Code Samples

//simple input reading

public class Example2 {


public static void main(String[] args) {


SenezConsole sc = new SenezConsole();


sc.print("What is your first name
-

");


String name = sc.input.readWord();


sc.println("Hello, " + name);


}

}

16

More Code Samples

//advanced SenezReader

public class Example3 {


public static void main(String[] args) {


SenezConsole sc = new SenezConsole();


char c = sc.input.readChar();


double d = sc.input.readDouble();


int i = sc.input.readInt();


String l = sc.input.readLine();


String w = sc.input.readWord();


}

}

17

More Code Samples

//other methods

import java.awt.*;

public class Example1 {


public static void main(String[] args) {


SenezConsole sc = new SenezConsole();


sc.setBackgroundColor(Color.blue);


sc.setTextColor(Color.yellow);


}

}

18