BreezyGUI package during the labs. You should also
have the directory on the CD that comes with the book.
We have posted a tutorial on using
Symantec Cafe with the BreezyGUI package. The only
requirement is that the BreezyGUI directory be in
the same directory with the project that you are developing. The
tutorial builds a project for the program discussed on page 37 in
your textbook.
During this lab you will build a few standalone applications that have
a graphical user interface (using the BreezyGUI package).
At the end of this lab you should be in very good shape to start working
on your assignments.
1. A simple Tester program (Tester.java)
import java.awt.*;
import BreezyGUI.*;
public class Tester extends GBFrame {
public static void main(String[] args) {
System.out.println("This is a test.");
GBFrame.pause();
}
}
2. A simple Counter program (Counter.java)
import java.awt.*;
import BreezyGUI.*;
public class Counter extends GBFrame {
Label result = addLabel ("Counter starts at 0 " , 1, 1, 1, 1);
Button action = addButton("Add 1", 2, 1, 1, 1);
int counter; // this variable is visible to buttonClicked
public void buttonClicked (Button buttonObj) {
counter = counter + 1;
result.setText("Counter is now: " + counter);
}
public static void main(String[] args) {
Frame f = new Counter();
f.setSize(200, 100);
f.setVisible(true);
}
}
3. An Add/Subtract program (NewCounter.java) In this program you use two buttons.
import java.awt.*;
import BreezyGUI.*;
public class NewCounter extends GBFrame {
Label result = addLabel ("Counter starts at 0 " , 1, 1, 2, 1);
Button aButton = addButton("Add 1", 2, 1, 1, 1);
Button sButton = addButton("Sub 1", 2, 2, 1, 1);
int counter; // this variable is visible to buttonClicked
public void buttonClicked (Button buttonObj) {
if (buttonObj == aButton) {
counter = counter + 1;
result.setText("Counter is now: " + counter);
} else {
counter = counter - 1;
result.setText("Counter is now: " + counter);
}
}
public static void main(String[] args) {
Frame f = new NewCounter();
f.setSize(200, 100);
f.setVisible(true);
}
}
4. A simple Echo program (with messageBoxes)
import java.awt.*;
import BreezyGUI.*;
public class Echo extends GBFrame {
Label msgLabel = addLabel ("Input:", 1, 1, 1, 1);
TextField msgField = addTextField ("" , 1, 2, 1, 1);
Button postButton = addButton ("Post" , 2, 1, 2, 1);
public void buttonClicked (Button b) {
messageBox(msgField.getText());
}
public static void main(String[] args) {
Frame x = new Echo();
x.setSize(100, 100);
x.setVisible(true);
}
}
5. Putting it all together (to some extent)
import java.awt.*;
import BreezyGUI.*;
public class Five extends GBFrame {
Label a = addLabel ("Name: ", 1, 1, 1, 1);
TextField b = addTextField ("" , 1, 2, 1, 1);
Label c = addLabel ("Age" , 2, 1, 1, 1);
IntegerField d = addIntegerField ( 0 , 2, 2, 1, 1);
Button e = addButton ("Report", 3, 1, 2, 1);
public void buttonClicked (Button buttonObj) {
messageBox (
b.getText() + " is " + d.getNumber() + " years old."
);
}
public static void main(String[] args) {
Frame f = new Five();
f.setSize(200, 100);
f.setVisible(true);
}
}