Presentation is loading. Please wait.

Presentation is loading. Please wait.

An Introduction to Software Engineering Principals Using Java’s Swing Libraries.

Similar presentations


Presentation on theme: "An Introduction to Software Engineering Principals Using Java’s Swing Libraries."— Presentation transcript:

1 An Introduction to Software Engineering Principals Using Java’s Swing Libraries

2 How to Approach a Programming Project Divide and Conquer Large problems must be broken into small parts. Then the small parts can be solved one at a time. Top-down design is one divide and conquer technique for developing an algorithm. Top-down design is similar to outlining. An algorithm is a collection of instructions (possibly not from any programming language) that perform some task. divide and conquer plan (design) before implementing program with style The Object of Java, David D. Riley © Addison Wesley pub.

3 Top Level Algorithm for making a cheese pizza The Object of Java, David D. Riley © Addison Wesley pub. Subtask 1.Using a premixed ball of crust dough, flatten the dough to the desired thickness. 2.Pour two cups of pizza sauce onto the crust 3.Spread the sauce evenly across the crust 4.Set pizza oven to 400 degrees Fahrenheit and cook pizza for 15 minutes.

4 First Define our objects – –Dough (crust) –Sauce –Cheese –Oven Next look for classes already developed: Java.sun.org (good resource)

5 Dough _____ > +Dough() > +void flattenToDesiredThickness() +void spreadTopping() +void placeInOven(PizzaOven) +void removeAfter15Minutes()

6 PizzaOven ________ > +PizzaOven() > +void turnOnAtZeroDegrees() +void turnOff() +void increaseTemp100Degrees()

7 Sauce _____ > +Sauce() > +void pourInto(MeasuringCup)

8 Cheese ______ > +void Cheese() > +void pourInto(MeasuringCup)

9 MeasuringCup ____________ > +MeasuringCup() > +void pourOnto(Dough)

10 Second Level Algorithm Use of parameters stems from the need to involve multiple objects in a single method. Exp: act of pouring pizza sauce -> measuring cup involves 1. The sauce 2. The cup. This permits one object to be passed to a method performed upon the second object. Another Exp: crust.placeInOven( oven );

11 Now refine each of the subtasks: –1 Using a premixed ball of crust dough, flatten the dough to the desired thickness. crust = new Dough( ); crust.flattenToDesiredThickness( ); –2 Pour two cups of pizza sauce onto the crust sauceCup = new MeasuringCup( ); mySauce = new Sauce( ); mySauce.pourInto( sauceCup ); sauceCup.pourOnto( crust ); mySauce.pourInto( sauceCup ); sauceCup.pourOnto( crust );

12 3.Spread the sauce evenly across the crust. crust.spreadTopping( ); 4.Spread three cups of mozz cheese on top cheeseCup = new MeasuringCup( ); //4.2Use cheeseCup to spread 3 cups on the pizza 5.Set pizza oven to 400 degrees and cook 15 min. oven = new PizzaOven(); oven.turnOnAtZeroDegrees( ); //5.3 set the temp to 400 degrees crust.placeInOven( oven ); crust.removeAfter15minutes( ); oven.turnOff( );

13 Second level names new objects: –crust –sauceCup –mySauce –cheeseCup –oven Next level is needed to add steps 4.2 and 5.3 one more refinement step finishes your project. Final code on page 60 Fig 3.9 of your book

14 Swing import java.swing.*; Use code warrior Sometimes will import java.awt.*; And java.awt.event.*; Swing components use the awt infrastructure. Event model governs how a component reacts to events, such as button clicks etc..

15 Every program must contain at least one top-level Swing container. JFrame, JDialog, and for applets JApplets JFrame – implements a single main window JDialog – implements a second window JApplet – implements an applet’s display area in a browser window

16 import javax.swing.*; public class HelloWorldSwing { public static void main(String[] args) { JFrame frame = new JFrame("HelloWorldSwing"); final JLabel label = new JLabel("Hello World"); frame.getContentPane().add(label); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E); frame.pack(); frame.setVisible(true); }

17 Now – take a look at http://java.sun.com/docs/books/tutorial/uiswing/mini/i ndex.html Read this tutorial and answer questions at the end – hand in a text file to the G drive. Due date: End of Class – Monday 3/3/2003


Download ppt "An Introduction to Software Engineering Principals Using Java’s Swing Libraries."

Similar presentations


Ads by Google