Errors, GUIs, and Patterns Dr. Doug Twitchell August 30, 2005
Development Cycle
GUI - Frames import javax.swing.*; // use JFrame public class EmptyFrame{ public static void main(String[] args) { // declare the object JFrame frame = new JFrame(); // invoke its services frame.setTitle("EmptyFrame"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLocation(250, 100); frame.setSize(150, 200); frame.setVisible(true); }
GUI - Frames import javax.swing.*; // use JFrame public class EmptyFrame{ public static void main(String[] args) { // declare the object JFrame frame = new JFrame(); // invoke its services frame.setTitle("EmptyFrame"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLocation(250, 100); frame.setSize(150, 200); frame.setVisible(true); }
Patterns
Command Invocation Pattern >. >( >); karel.turnLeft() frame.setSize(100, 200)
Object instantiation Pattern > > = new >( >); City ny = new City() Robot billyBob = new Robot(ny, 4, 5, Direction.EAST); JFrame frame = new Frame(); Thing blob = new Thing(ny, 3, 5);
Sequential Execution Pattern >. >( >); karel.turnLeft() karel.move(); karel.turnLeft();
Java Program Pattern import >; public class > { public static void main(String[] args) { > }
Java Program Pattern import javax.swing.*; // use JFrame public class EmptyFrame{ public static void main(String[] args) { // declare the object JFrame frame = new JFrame(); // invoke its services frame.setTitle("EmptyFrame"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLocation(250, 100); frame.setSize(150, 200); frame.setVisible(true); }
Display a Frame Pattern import javax.swing.*; public class > { public static void main(String[] args) { //declare objects to show JFrame > = new JFrame(); JPanel > = new JPanel(); //set the frame’s contents to display the panel >.setContentPane( >); //set up and show the frame >.setTitle(“ >); >.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE); >.setLocation( >, >); >.setSize( >, >); >.setVisible(true): }
Display a Frame Pattern import javax.swing.*; // use JFrame public class EmptyFrame{ public static void main(String[] args) { // declare the object JFrame frame = new JFrame(); // invoke its services frame.setTitle("EmptyFrame"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLocation(250, 100); frame.setSize(150, 200); frame.setVisible(true); }