Complete Source Code.
- By Chris Carpenter
- April 24, 2001
Java for Small Spaces
Developing Java for small spaces
Chris Carpenter
Complete Source Code.
import com.sun.kjava.*;
public class UITest extends Spotlet
{
public static Button exitButton;
public static Button clearButton;
public static Graphics graphics =
Graphics.getGraphics();
public TextField textFieldOne;
public TextField textFieldTwo;
}
Slider slider;
public static void main(String args[])
{
UITest ui = new UITest();
ui.paint();
}
public UITest()
{
register(NO_EVENT_OPTIONS);
graphics.clearScreen();
textFieldOne = new TextField
("Solution", 5, 10, 100, 20);
textFieldOne.setUpperCase(true);
textFieldTwo = new TextField
("Solution2", 5, 50, 100, 20);
textFieldTwo.setUpperCase(true);
slider = new Slider(5, 100, 100, 0, 1000, 0);
textFieldOne.setFocus();
exitButton = new Button("Exit", 115, 145);
clearButton = new Button("Clear Text Fields", 5, 145);
}
public void paint()
{
exitButton.paint();
clearButton.paint();
graphics.drawRectangle(0, 0, 160, 80, 0, graphics.PLAIN);
textFieldOne.paint();
textFieldTwo.paint();
slider.paint();
}
public void keyDown(int key)
{
if (textFieldOne.hasFocus()) {
textFieldOne.handleKeyDown(key);
}
if (textFieldTwo.hasFocus()) {
textFieldTwo.handleKeyDown(key);
}
}
public void penMove(int x, int y)
{
if (slider.contains(x, y)) {
slider.handlePenMove(x, y);
}
}
public void penDown(int x, int y)
{
if (exitButton.pressed(x, y)) {
System.exit(0);
}
if (clearButton.pressed(x, y)) {
textFieldOne.setText("");
textFieldOne.paint();
textFieldTwo.setText("");
textFieldTwo.paint();
}
if (slider.contains(x, y)) {
slider.handlePenDown(x, y);
}
if (textFieldOne.pressed(x, y) &&
(!textFieldOne.hasFocus())) {
textFieldTwo.loseFocus();
textFieldOne.setFocus();
}
if (textFieldTwo.pressed(x, y) &&
(!textFieldTwo.hasFocus())) {
textFieldOne.loseFocus();
textFieldTwo.setFocus();
}
}
About the Author
Chris Carpenter is a software engineer and architect at RoleModel Software, Inc. in Holly Springs, NC. He can be contacted at [email protected].