Escolar Documentos
Profissional Documentos
Cultura Documentos
– pluggable look-and-feels
Slide credits to CMPUT 301, Department of e.g., Motif, windows,…
Computing Science
University of Alberta 2 3
4 5 © O’Reilly 1999 6
1
Swing Containers Top-Level Containers
• Java • Notes: • JFrame example:
Documentation: – Container objects group components, – contains a single component JRootPane, which
– http://java.sun.com/j2se/1.4.
1/docs/api/javax/swing/pack arranging them for display with a layout has a JMenuBar (optional) and a content pane
age-summary.html
manager. – theFrame.setJMenuBar( theMenuBar )
• SwingSet: – theFrame.setContentPane( thePanel )
– http://java.sun.com/products
/javawebstart/demos.html
– add non-menu components to this content
pane
• Quick tutorial: – theFrame.getContentPane().add( aButton )
– http://java.sun.com/docs/bo
oks/tutorial/uiswing/start/swi
ngTour.html
7 8 9
10 11 12
2
Events Events Event Handling
• class MyListener implements ActionListener {
• Handling: …
public void actionPerformed( ActionEvent event ) {
listener interface
– create a component // react to event
– e.g., a JButton …
}
– add it to the GUI }
– e.g., to a JPanel • …
– register a listener to be notified when the // instantiate event listener
1..* 1..* ActionListener listener = new MyListener();
event source event listener
component generates an event …
// instantiate event source
– e.g., interface ActionListener JButton button = new JButton( “Hello” );
…
– define the callback method // register event listener with event source
– e.g., actionPerformed() button.addActionListener( listener );
13 14 15
actionPerformed ()
16 17 18
3
Event Handling Event Handling Event Handling
19 20 21
22 23 24
4
Model/View/Controller Model/View/Controller Model/View/Controller
25 26 27
– separate threads?
28 29 30
5
Model/View/Controller Model/View/Controller Pluggable Look-and-Feel
– UIManager.setLookAndFeel(
“javax.swing.plaf.metal.MetalLookAndFeel”
);
31 32 33
component
34 35 36
6
Pluggable Look-and-Feel Model/View/Controller
37 38