150 likes | 318 Views
Early GUIs with Java. As presented in Java: Complete Course in Programming and Problem Solving by Lambert and Osborne. Advantages of Early GUIs. Realistic GUIs are fun to create and generate student enthusiasm Students are accustomed to using GUI-based programs
E N D
EarlyGUIs with Java As presented in Java: Complete Course in Programming and Problem Solving by Lambert and Osborne
Advantages of Early GUIs • Realistic GUIs are fun to create and generate student enthusiasm • Students are accustomed to using GUI-based programs • User interface design is an important part of program development
But . . . • GUIs are too hard to create in Java • The abstract windowing toolkit (AWT) is too complicated • So doing GUIs would distract from core programming concepts
Abstraction to the Rescue • We use Java’s power of abstraction to simplify GUI creation • We call the result BreezyGUI
A Simple Program Using BreezyGUI The user enters the radius in the upper field and selects the Compute button. Code on next slide.
import java.awt.*; • import BreezyGUI.*; • public class CircleArea extends GBFrame{ • Label radiusLabel = addLabel ("Radius",1,1,1,1); • DoubleField radiusField = addDoubleField (0,1,2,1,1); • Label areaLabel = addLabel ("Area",2,1,1,1); • DoubleField areaField = addDoubleField (0,2,2,1,1); • Button computeButton = addButton ("Compute",3,1,2,1); • public void buttonClicked (Button buttonObj){ • double radius, area; • radius = radiusField.getNumber(); • area = 3.14 * radius * radius; • areaField.setNumber (area); • areaField.setPrecision (2); • } • public static void main (String[] args){ • Frame frm = new CircleArea(); • frm.setSize (200, 150); • frm.setVisible (true); • } • } Lay out the GUI objects Handle the user events Open the window and start the program
Transition to Full AWT Is Easy Students are now familiar with • structure of event driven programs • behavior of basic window components • designing GUI based applications In addition • BreezyGUI is an extension of Java’s AWT • and the book shows one how to make the transition
BreezyGUI Highlights Supports • applications, applets, and dialogs • common window components • drop down menus • mouse events And it’s actually easier to use than terminal I/O
BreezyGUI in Many Courses • Has been used in CS0, CS1, CS2, and more advanced courses • Useful in any course where direct use of AWT is not required
And Now for Some Examples taken from Java: Complete Course in Programming and Problem Solving