Presentation is loading. Please wait.

Presentation is loading. Please wait.

Component-Based Software Engineering GUI Basics Paul J Krause.

Similar presentations


Presentation on theme: "Component-Based Software Engineering GUI Basics Paul J Krause."— Presentation transcript:

1 Component-Based Software Engineering GUI Basics Paul J Krause

2 Swing Overview  Components in the Abstract Windowing Toolkit (AWT) rely on the local platform’s GUI capabilities  Most Swing components are light-weight components - not “weighed-down” by the local platform’s GUI capabilities

3 Swing Overview java.lang.Object java.awt.Component java.awt.Container javax.swing.JComponent add( ) setlayout( ) setBorder( ) setOpaque( ) setToolTipText( ) paint( ) repaint( )

4 GUI Building in Swing  Need at least one top-level container  This is the root of a “containment hierarchy” this consists of all the Swing components that appear within that container this consists of all the Swing components that appear within that container  Often, the root will be a Jframe

5 JFrame

6 Pattern for Using JFrame import java.awt.*; import java.awt.event.*; import javax.swing.*; public class MyFrame extends JFrame { public MyFrame( ) { Container c = getContentPane(); c.setFlowLayout( new FlowLayout() ); c.add( Name of component here ); }

7 main method public static void main( String args[ ] ) { MyFrame test = new MyFrame( ); test.setSize( length, width ); test.show( ); }

8 Inner Class for event handling private class ActionEventHandler implements ActionListener { public void actionPerformed( ActionEvent e ) { if ( e.getSource( ) == exitButton ) System.exit(0); else if ( e.getSource( ) == something else ) { do something else } }}

9 Listening for actions public class MyFrame extends JFrame { public MyFrame( ) { public MyFrame( ) { Container c = getContentPane(); Container c = getContentPane(); c.setFlowLayout( new FlowLayout() ); c.setFlowLayout( new FlowLayout() ); ActionEventHandler handler = new ActionEventHandler( ); ActionEventHandler handler = new ActionEventHandler( ); JButton exitButton = new JButton( “Exit” ); JButton exitButton = new JButton( “Exit” ); exitButton.addActionListener( handler ); exitButton.addActionListener( handler ); c.add( exitButton ); c.add( exitButton );}

10 TimeTestWindow demo

11 Using NetBeans  Building a GUI is much easier and quicker using a visual development environment  Will illustrate this using NetBeans  Example taken from Chapter 8 of NetBeans - The Definitive Guide by Tim Boudreau, Jesse Glick, Simeon Greene, Vaughn Spurlin & Jack Woehr, O’Reilly

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38


Download ppt "Component-Based Software Engineering GUI Basics Paul J Krause."

Similar presentations


Ads by Google