swing · 2004-02-29 · poelman & associates, inc. (c) 2003 1 swing a quick tutorial on...
TRANSCRIPT
![Page 1: Swing · 2004-02-29 · Poelman & Associates, Inc. (c) 2003 1 Swing A Quick Tutorial on Programming Swing Applications](https://reader031.vdocuments.us/reader031/viewer/2022011907/5f4c32192c70ab04826748bd/html5/thumbnails/1.jpg)
Poelman & Associates, Inc. (c) 2003 1
Swing
A Quick Tutorial on Programming Swing Applications
![Page 2: Swing · 2004-02-29 · Poelman & Associates, Inc. (c) 2003 1 Swing A Quick Tutorial on Programming Swing Applications](https://reader031.vdocuments.us/reader031/viewer/2022011907/5f4c32192c70ab04826748bd/html5/thumbnails/2.jpg)
Poelman & Associates, Inc. (c) 2003 2
MVC – Model View Controller• Swing is based on this design pattern• It means separating the implementation of
an application into layers or components:– The Model - the data structure that
represents something (like a customer info rec)
– The Controller - the user interface logic for manipulating it
– The View - the display of that data structure to the user.
![Page 3: Swing · 2004-02-29 · Poelman & Associates, Inc. (c) 2003 1 Swing A Quick Tutorial on Programming Swing Applications](https://reader031.vdocuments.us/reader031/viewer/2022011907/5f4c32192c70ab04826748bd/html5/thumbnails/3.jpg)
Poelman & Associates, Inc. (c) 2003 3
What is Swing?
• A set of classes (part of JFC) that support platform independent GUI (Graphical User Interface)
• Successor to the original Java GUI classes (AWT) which didn’t work very well (they had platform dependencies that really made it a difficult API to use)
• AWT wasn’t very “sexy”
![Page 4: Swing · 2004-02-29 · Poelman & Associates, Inc. (c) 2003 1 Swing A Quick Tutorial on Programming Swing Applications](https://reader031.vdocuments.us/reader031/viewer/2022011907/5f4c32192c70ab04826748bd/html5/thumbnails/4.jpg)
Poelman & Associates, Inc. (c) 2003 4
Swing
• Visible “widgets” - windows, buttons, combo boxes, trees, tables, checkboxes, text fields, menus, …
• Containers of components – applets, dialogs, windows and frames
• Supporting classes and utility methods
![Page 5: Swing · 2004-02-29 · Poelman & Associates, Inc. (c) 2003 1 Swing A Quick Tutorial on Programming Swing Applications](https://reader031.vdocuments.us/reader031/viewer/2022011907/5f4c32192c70ab04826748bd/html5/thumbnails/5.jpg)
Poelman & Associates, Inc. (c) 2003 5
Some important Swing visible component classes
• JApplet **• JButton• JCheckBox• JColorChooser• JComboBox• JDialog **• JFileChooser• JFormattedTextField• JFrame **• JLabel• JList• JMenu• JMenuBar• JMenuItem• JPanel
• JPasswordField• JPopupMenu• JProgressBar• JRadioButton• JScrollBar• JSlider• JSpinner• JTable• JTextArea• JTextField• JToggleButton• JToolBar• JTree• JWindow **
• ** means a top level containers
![Page 6: Swing · 2004-02-29 · Poelman & Associates, Inc. (c) 2003 1 Swing A Quick Tutorial on Programming Swing Applications](https://reader031.vdocuments.us/reader031/viewer/2022011907/5f4c32192c70ab04826748bd/html5/thumbnails/6.jpg)
Poelman & Associates, Inc. (c) 2003 6
Using netbeans to create a JDialog
![Page 7: Swing · 2004-02-29 · Poelman & Associates, Inc. (c) 2003 1 Swing A Quick Tutorial on Programming Swing Applications](https://reader031.vdocuments.us/reader031/viewer/2022011907/5f4c32192c70ab04826748bd/html5/thumbnails/7.jpg)
Poelman & Associates, Inc. (c) 2003 7
adding fields
![Page 8: Swing · 2004-02-29 · Poelman & Associates, Inc. (c) 2003 1 Swing A Quick Tutorial on Programming Swing Applications](https://reader031.vdocuments.us/reader031/viewer/2022011907/5f4c32192c70ab04826748bd/html5/thumbnails/8.jpg)
Poelman & Associates, Inc. (c) 2003 8
![Page 9: Swing · 2004-02-29 · Poelman & Associates, Inc. (c) 2003 1 Swing A Quick Tutorial on Programming Swing Applications](https://reader031.vdocuments.us/reader031/viewer/2022011907/5f4c32192c70ab04826748bd/html5/thumbnails/9.jpg)
Poelman & Associates, Inc. (c) 2003 9
my empty CustomerInfoDialog:JDialog
![Page 10: Swing · 2004-02-29 · Poelman & Associates, Inc. (c) 2003 1 Swing A Quick Tutorial on Programming Swing Applications](https://reader031.vdocuments.us/reader031/viewer/2022011907/5f4c32192c70ab04826748bd/html5/thumbnails/10.jpg)
Poelman & Associates, Inc. (c) 2003 10
code created
![Page 11: Swing · 2004-02-29 · Poelman & Associates, Inc. (c) 2003 1 Swing A Quick Tutorial on Programming Swing Applications](https://reader031.vdocuments.us/reader031/viewer/2022011907/5f4c32192c70ab04826748bd/html5/thumbnails/11.jpg)
Poelman & Associates, Inc. (c) 2003 11
To kill a zombie or running process in netbeans right click and choose: ”terminate”
![Page 12: Swing · 2004-02-29 · Poelman & Associates, Inc. (c) 2003 1 Swing A Quick Tutorial on Programming Swing Applications](https://reader031.vdocuments.us/reader031/viewer/2022011907/5f4c32192c70ab04826748bd/html5/thumbnails/12.jpg)
Poelman & Associates, Inc. (c) 2003 12
executing the class displays:
![Page 13: Swing · 2004-02-29 · Poelman & Associates, Inc. (c) 2003 1 Swing A Quick Tutorial on Programming Swing Applications](https://reader031.vdocuments.us/reader031/viewer/2022011907/5f4c32192c70ab04826748bd/html5/thumbnails/13.jpg)
Poelman & Associates, Inc. (c) 2003 13
Editing a dialog
• 1St select a layout manager for the dialog
![Page 14: Swing · 2004-02-29 · Poelman & Associates, Inc. (c) 2003 1 Swing A Quick Tutorial on Programming Swing Applications](https://reader031.vdocuments.us/reader031/viewer/2022011907/5f4c32192c70ab04826748bd/html5/thumbnails/14.jpg)
Poelman & Associates, Inc. (c) 2003 14
select component
edit properties
![Page 15: Swing · 2004-02-29 · Poelman & Associates, Inc. (c) 2003 1 Swing A Quick Tutorial on Programming Swing Applications](https://reader031.vdocuments.us/reader031/viewer/2022011907/5f4c32192c70ab04826748bd/html5/thumbnails/15.jpg)
Poelman & Associates, Inc. (c) 2003 15
changing the layout manager
![Page 16: Swing · 2004-02-29 · Poelman & Associates, Inc. (c) 2003 1 Swing A Quick Tutorial on Programming Swing Applications](https://reader031.vdocuments.us/reader031/viewer/2022011907/5f4c32192c70ab04826748bd/html5/thumbnails/16.jpg)
Poelman & Associates, Inc. (c) 2003 16
what layout manager should I use?
• Start with the absolute and then experiment when you feel comfortable (or hire a graphic artist and let them worry about it ;-).
![Page 17: Swing · 2004-02-29 · Poelman & Associates, Inc. (c) 2003 1 Swing A Quick Tutorial on Programming Swing Applications](https://reader031.vdocuments.us/reader031/viewer/2022011907/5f4c32192c70ab04826748bd/html5/thumbnails/17.jpg)
Poelman & Associates, Inc. (c) 2003 17
Adding other components to the view - JTextFields
![Page 18: Swing · 2004-02-29 · Poelman & Associates, Inc. (c) 2003 1 Swing A Quick Tutorial on Programming Swing Applications](https://reader031.vdocuments.us/reader031/viewer/2022011907/5f4c32192c70ab04826748bd/html5/thumbnails/18.jpg)
Poelman & Associates, Inc. (c) 2003 18
execute the class
![Page 19: Swing · 2004-02-29 · Poelman & Associates, Inc. (c) 2003 1 Swing A Quick Tutorial on Programming Swing Applications](https://reader031.vdocuments.us/reader031/viewer/2022011907/5f4c32192c70ab04826748bd/html5/thumbnails/19.jpg)
Poelman & Associates, Inc. (c) 2003 19
Adding a combo box
![Page 20: Swing · 2004-02-29 · Poelman & Associates, Inc. (c) 2003 1 Swing A Quick Tutorial on Programming Swing Applications](https://reader031.vdocuments.us/reader031/viewer/2022011907/5f4c32192c70ab04826748bd/html5/thumbnails/20.jpg)
Poelman & Associates, Inc. (c) 2003 20
edit the model property for the combo box
type in state abbreviations
separatedby commas
![Page 21: Swing · 2004-02-29 · Poelman & Associates, Inc. (c) 2003 1 Swing A Quick Tutorial on Programming Swing Applications](https://reader031.vdocuments.us/reader031/viewer/2022011907/5f4c32192c70ab04826748bd/html5/thumbnails/21.jpg)
Poelman & Associates, Inc. (c) 2003 21
![Page 22: Swing · 2004-02-29 · Poelman & Associates, Inc. (c) 2003 1 Swing A Quick Tutorial on Programming Swing Applications](https://reader031.vdocuments.us/reader031/viewer/2022011907/5f4c32192c70ab04826748bd/html5/thumbnails/22.jpg)
Poelman & Associates, Inc. (c) 2003 22
preferred size property
hor , vert
![Page 23: Swing · 2004-02-29 · Poelman & Associates, Inc. (c) 2003 1 Swing A Quick Tutorial on Programming Swing Applications](https://reader031.vdocuments.us/reader031/viewer/2022011907/5f4c32192c70ab04826748bd/html5/thumbnails/23.jpg)
Poelman & Associates, Inc. (c) 2003 23
MVC
Model – View – Controller Design Pattern
![Page 24: Swing · 2004-02-29 · Poelman & Associates, Inc. (c) 2003 1 Swing A Quick Tutorial on Programming Swing Applications](https://reader031.vdocuments.us/reader031/viewer/2022011907/5f4c32192c70ab04826748bd/html5/thumbnails/24.jpg)
Poelman & Associates, Inc. (c) 2003 24
Design Patterns• A design pattern is a way of designing code that benefits from experience of
other developers – see GoF (Gang of Four) on Patterns• Design patterns are “rules of thumb” & best practices• A GUI is based on many design patterns
– 3D Pliancy– Feedback– Icons– Menus– Pointing– Mnemonics & Accelerators– Many more …
• A pattern usually has a name (and several aliases), a context, a problem it addresses, a description of the solution, hints of when to use it and when not to.
• See http://www.csc.calpoly.edu/~dbutler/tutorials/winter96/patterns/ , http://choices.cs.uiuc.edu/sane/dpatterns.html#dp and http://www.stanford.edu/~borchers/hcipatterns
![Page 25: Swing · 2004-02-29 · Poelman & Associates, Inc. (c) 2003 1 Swing A Quick Tutorial on Programming Swing Applications](https://reader031.vdocuments.us/reader031/viewer/2022011907/5f4c32192c70ab04826748bd/html5/thumbnails/25.jpg)
Poelman & Associates, Inc. (c) 2003 25
MVC – Model View Controller pattern
• Swing components are designed as MVC components– Model = data or object that is the to be
visually represented– View = one or more visual representations of
that data/object– Controller = code to manage input to the
model
![Page 26: Swing · 2004-02-29 · Poelman & Associates, Inc. (c) 2003 1 Swing A Quick Tutorial on Programming Swing Applications](https://reader031.vdocuments.us/reader031/viewer/2022011907/5f4c32192c70ab04826748bd/html5/thumbnails/26.jpg)
Poelman & Associates, Inc. (c) 2003 26
MVC
• © Sun 2002
![Page 27: Swing · 2004-02-29 · Poelman & Associates, Inc. (c) 2003 1 Swing A Quick Tutorial on Programming Swing Applications](https://reader031.vdocuments.us/reader031/viewer/2022011907/5f4c32192c70ab04826748bd/html5/thumbnails/27.jpg)
Poelman & Associates, Inc. (c) 2003 27
MVC in Swing Components
• The Swing component class is the viewand controller
• A separate class is the model• Most components come with a default
model• You can set the model to your own model
for a control• Several controls could share a model!
![Page 28: Swing · 2004-02-29 · Poelman & Associates, Inc. (c) 2003 1 Swing A Quick Tutorial on Programming Swing Applications](https://reader031.vdocuments.us/reader031/viewer/2022011907/5f4c32192c70ab04826748bd/html5/thumbnails/28.jpg)
Poelman & Associates, Inc. (c) 2003 28
![Page 29: Swing · 2004-02-29 · Poelman & Associates, Inc. (c) 2003 1 Swing A Quick Tutorial on Programming Swing Applications](https://reader031.vdocuments.us/reader031/viewer/2022011907/5f4c32192c70ab04826748bd/html5/thumbnails/29.jpg)
Poelman & Associates, Inc. (c) 2003 29
Creating icons using the blank icon to start with
![Page 30: Swing · 2004-02-29 · Poelman & Associates, Inc. (c) 2003 1 Swing A Quick Tutorial on Programming Swing Applications](https://reader031.vdocuments.us/reader031/viewer/2022011907/5f4c32192c70ab04826748bd/html5/thumbnails/30.jpg)
Poelman & Associates, Inc. (c) 2003 30
Change the properties of the button to use you icon
![Page 31: Swing · 2004-02-29 · Poelman & Associates, Inc. (c) 2003 1 Swing A Quick Tutorial on Programming Swing Applications](https://reader031.vdocuments.us/reader031/viewer/2022011907/5f4c32192c70ab04826748bd/html5/thumbnails/31.jpg)
Poelman & Associates, Inc. (c) 2003 31
Pushing the buttons changes the displayed prices.
![Page 32: Swing · 2004-02-29 · Poelman & Associates, Inc. (c) 2003 1 Swing A Quick Tutorial on Programming Swing Applications](https://reader031.vdocuments.us/reader031/viewer/2022011907/5f4c32192c70ab04826748bd/html5/thumbnails/32.jpg)
Poelman & Associates, Inc. (c) 2003 32
A different and better layout
![Page 33: Swing · 2004-02-29 · Poelman & Associates, Inc. (c) 2003 1 Swing A Quick Tutorial on Programming Swing Applications](https://reader031.vdocuments.us/reader031/viewer/2022011907/5f4c32192c70ab04826748bd/html5/thumbnails/33.jpg)
Poelman & Associates, Inc. (c) 2003 33
JTree
JFrame
JFileChooser
JTable
JPasswordField
JSlider
JButton
JProgressBar
![Page 34: Swing · 2004-02-29 · Poelman & Associates, Inc. (c) 2003 1 Swing A Quick Tutorial on Programming Swing Applications](https://reader031.vdocuments.us/reader031/viewer/2022011907/5f4c32192c70ab04826748bd/html5/thumbnails/34.jpg)
Poelman & Associates, Inc. (c) 2003 34
private javax.swing.JPasswordField jPasswordField1;
private javax.swing.JTree jTree1;
private javax.swing.JSlider jSlider1;
private javax.swing.JProgressBar jProgressBar1;
private javax.swing.JTable jTable1;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton1;
private javax.swing.JFileChooser jFileChooser1;
private javax.swing.JLabel jLabel1;
![Page 35: Swing · 2004-02-29 · Poelman & Associates, Inc. (c) 2003 1 Swing A Quick Tutorial on Programming Swing Applications](https://reader031.vdocuments.us/reader031/viewer/2022011907/5f4c32192c70ab04826748bd/html5/thumbnails/35.jpg)
Poelman & Associates, Inc. (c) 2003 35
Swing based MenuLookDemo
![Page 36: Swing · 2004-02-29 · Poelman & Associates, Inc. (c) 2003 1 Swing A Quick Tutorial on Programming Swing Applications](https://reader031.vdocuments.us/reader031/viewer/2022011907/5f4c32192c70ab04826748bd/html5/thumbnails/36.jpg)
Poelman & Associates, Inc. (c) 2003 36
TopLevelWindows.java
![Page 37: Swing · 2004-02-29 · Poelman & Associates, Inc. (c) 2003 1 Swing A Quick Tutorial on Programming Swing Applications](https://reader031.vdocuments.us/reader031/viewer/2022011907/5f4c32192c70ab04826748bd/html5/thumbnails/37.jpg)
Poelman & Associates, Inc. (c) 2003 37
TopLevelWindows.javapackage SwingSamples;import javax.swing.*;public class TopLevelWindows{
public static void main(String args[]){
JFrame myJFrame = new JFrame("The JFrame");myJFrame.setSize(300,300);myJFrame.setLocation(100,100);
JWindow myJWindow = new JWindow();myJWindow.setSize(300,300);myJWindow.setLocation(500, 100);
myJFrame.setVisible(true);myJWindow.setVisible(true);
}}
![Page 38: Swing · 2004-02-29 · Poelman & Associates, Inc. (c) 2003 1 Swing A Quick Tutorial on Programming Swing Applications](https://reader031.vdocuments.us/reader031/viewer/2022011907/5f4c32192c70ab04826748bd/html5/thumbnails/38.jpg)
Poelman & Associates, Inc. (c) 2003 38
Top Level Containers
• Must have a top level container in Swing• You must add components to the
associated content pane
![Page 39: Swing · 2004-02-29 · Poelman & Associates, Inc. (c) 2003 1 Swing A Quick Tutorial on Programming Swing Applications](https://reader031.vdocuments.us/reader031/viewer/2022011907/5f4c32192c70ab04826748bd/html5/thumbnails/39.jpg)
Poelman & Associates, Inc. (c) 2003 39
ContentPaneExample.java
package SwingSamples;
import java.awt.*;import javax.swing.*;
public class ContentPaneExample{
public static void main(String args[]){
JFrame myJFrame = new JFrame("JFrame");myJFrame.setLocation(100,100);
Container myContentPane = myJFrame.getContentPane();myContentPane.setLayout(new FlowLayout());myContentPane.add(new JLabel("One"));myContentPane.add(new JLabel("Two"));
myJFrame.pack(); //reformats the layout to the minimum size to fit everything
myJFrame.setVisible(true);}
}
Without the pack()
With the pack()
![Page 40: Swing · 2004-02-29 · Poelman & Associates, Inc. (c) 2003 1 Swing A Quick Tutorial on Programming Swing Applications](https://reader031.vdocuments.us/reader031/viewer/2022011907/5f4c32192c70ab04826748bd/html5/thumbnails/40.jpg)
Poelman & Associates, Inc. (c) 2003 40
ContentPaneExample2.java
package SwingSamples;
import java.awt.*;import javax.swing.*;
public class ContentPaneExample2 {
public static void main(String args[]){
JFrame myJFrame = new JFrame("JFrame");myJFrame.setLocation(100,100);
Container myContentPane = new JPanel();
myContentPane.add(new JLabel("One"));myContentPane.add(new JLabel("Two"));
myJFrame.setContentPane(myContentPane);myJFrame.pack(); myJFrame.setVisible(true);
}
}
![Page 41: Swing · 2004-02-29 · Poelman & Associates, Inc. (c) 2003 1 Swing A Quick Tutorial on Programming Swing Applications](https://reader031.vdocuments.us/reader031/viewer/2022011907/5f4c32192c70ab04826748bd/html5/thumbnails/41.jpg)
Poelman & Associates, Inc. (c) 2003 41
Events• Swing uses them to communicate
between swing components.• An event is just a method call on the
receiving object by the sending object. The method passes the event object.addActionListener(ActionListener listener);removeActionListener(ActionListener listener);
• An object registers to receive events. The method that gets called is:actionPerformed(ActionEvent e);
![Page 42: Swing · 2004-02-29 · Poelman & Associates, Inc. (c) 2003 1 Swing A Quick Tutorial on Programming Swing Applications](https://reader031.vdocuments.us/reader031/viewer/2022011907/5f4c32192c70ab04826748bd/html5/thumbnails/42.jpg)
Poelman & Associates, Inc. (c) 2003 42
Events• In Swing they are multicast – 1 to many
possible. Manes multiple method calls by the send basically.
• Order isn’t defined, though.• Events are immutable to the receiver.• Events may be queued as in the keyboard
event queue.• Multiple events maybe compressed into
one as in mouse movements.
![Page 43: Swing · 2004-02-29 · Poelman & Associates, Inc. (c) 2003 1 Swing A Quick Tutorial on Programming Swing Applications](https://reader031.vdocuments.us/reader031/viewer/2022011907/5f4c32192c70ab04826748bd/html5/thumbnails/43.jpg)
Poelman & Associates, Inc. (c) 2003 43
Event Modifier Flags• SHIFT_MASK
• CTRL_MASK
• META_MASK
• ALT_MASK
• BUTTON1_MASK
• BUTTON2_MASK
• BUTTON3_MASK
• Detect when certain keys are also pressed.int modifierFlags = myEvent.getModifiers();if ((modifierFlags & InputEvent.CRTL_MASK)!=0)
System.println.out(“Pressing the contrl key”);
![Page 44: Swing · 2004-02-29 · Poelman & Associates, Inc. (c) 2003 1 Swing A Quick Tutorial on Programming Swing Applications](https://reader031.vdocuments.us/reader031/viewer/2022011907/5f4c32192c70ab04826748bd/html5/thumbnails/44.jpg)
Poelman & Associates, Inc. (c) 2003 44
Event Types• ComponentEvent //resized,moved, shown, hidden
• FocusEvent //gained, lost
• KeyEvent //typed, pressed, released
• MouseEvent //clicked, pressed, released,//entered, exited
• ContainerEvent //componentAdded componentRemoved
• ActionEvent //fired by: JButton, JChekBox, …
• AdjustmentEvent //fired by: JScrollBar
• Many more ….
![Page 45: Swing · 2004-02-29 · Poelman & Associates, Inc. (c) 2003 1 Swing A Quick Tutorial on Programming Swing Applications](https://reader031.vdocuments.us/reader031/viewer/2022011907/5f4c32192c70ab04826748bd/html5/thumbnails/45.jpg)
Poelman & Associates, Inc. (c) 2003 45
Event Adapter Classes• Map incoming events to a method to invoke on the
model to achieve the function.• Separates the View & Controller from the Model (MVC)• Prebuilt adapter has stubbed out methods for events.
You only implement the ones you are interested. You do this by extending the adapter and overiding the methods you need.
• Follows a general design pattern of called “adapter”.• MouseAdapter, MouseInputAdapter,
MouseMotionAdapter, KeyAdapter, ComponentAdapter, ContainerAdapter, DragSourceAdapter, DropTargetAdapter, FocusAdapter, WindowAdapter, …
![Page 46: Swing · 2004-02-29 · Poelman & Associates, Inc. (c) 2003 1 Swing A Quick Tutorial on Programming Swing Applications](https://reader031.vdocuments.us/reader031/viewer/2022011907/5f4c32192c70ab04826748bd/html5/thumbnails/46.jpg)
Poelman & Associates, Inc. (c) 2003 46
AWT Robot!
• Used to simulate keyboard and mouse programmatically.
• It places events in the native system queues for the platform you are on (not just the java queue).
• Used for recording and replaying activities in regression testing and other uses.
![Page 47: Swing · 2004-02-29 · Poelman & Associates, Inc. (c) 2003 1 Swing A Quick Tutorial on Programming Swing Applications](https://reader031.vdocuments.us/reader031/viewer/2022011907/5f4c32192c70ab04826748bd/html5/thumbnails/47.jpg)
Poelman & Associates, Inc. (c) 2003 47
Multithreading and Swing• Swing components always execute on a
single thread within your application. Not the main thread of your application, either.
• Swing components are NOT multithread safe!
• This is done for speed but influences how you must design for them.
• We can ignore this for protoyping UIs but not for design of applications.
![Page 48: Swing · 2004-02-29 · Poelman & Associates, Inc. (c) 2003 1 Swing A Quick Tutorial on Programming Swing Applications](https://reader031.vdocuments.us/reader031/viewer/2022011907/5f4c32192c70ab04826748bd/html5/thumbnails/48.jpg)
Poelman & Associates, Inc. (c) 2003 48
Swing Components
![Page 49: Swing · 2004-02-29 · Poelman & Associates, Inc. (c) 2003 1 Swing A Quick Tutorial on Programming Swing Applications](https://reader031.vdocuments.us/reader031/viewer/2022011907/5f4c32192c70ab04826748bd/html5/thumbnails/49.jpg)
Poelman & Associates, Inc. (c) 2003 49
Sample dialog with a few controls. MySampleOfSwingControls1.java
![Page 50: Swing · 2004-02-29 · Poelman & Associates, Inc. (c) 2003 1 Swing A Quick Tutorial on Programming Swing Applications](https://reader031.vdocuments.us/reader031/viewer/2022011907/5f4c32192c70ab04826748bd/html5/thumbnails/50.jpg)
Poelman & Associates, Inc. (c) 2003 50
JButton
java.lang.Object
|
+--java.awt.Component
|
+--java.awt.Container
|
+--javax.swing.JComponent
|
+--javax.swing.AbstractButton
|
+--javax.swing.JButton
![Page 51: Swing · 2004-02-29 · Poelman & Associates, Inc. (c) 2003 1 Swing A Quick Tutorial on Programming Swing Applications](https://reader031.vdocuments.us/reader031/viewer/2022011907/5f4c32192c70ab04826748bd/html5/thumbnails/51.jpg)
Poelman & Associates, Inc. (c) 2003 51
JButton
• Used for a command• Push and shows a state change visually (pliancy)• Has a name, label text,
![Page 52: Swing · 2004-02-29 · Poelman & Associates, Inc. (c) 2003 1 Swing A Quick Tutorial on Programming Swing Applications](https://reader031.vdocuments.us/reader031/viewer/2022011907/5f4c32192c70ab04826748bd/html5/thumbnails/52.jpg)
Poelman & Associates, Inc. (c) 2003 52
Adding items to the List
![Page 53: Swing · 2004-02-29 · Poelman & Associates, Inc. (c) 2003 1 Swing A Quick Tutorial on Programming Swing Applications](https://reader031.vdocuments.us/reader031/viewer/2022011907/5f4c32192c70ab04826748bd/html5/thumbnails/53.jpg)
Poelman & Associates, Inc. (c) 2003 53
Add items to the model for the list
![Page 54: Swing · 2004-02-29 · Poelman & Associates, Inc. (c) 2003 1 Swing A Quick Tutorial on Programming Swing Applications](https://reader031.vdocuments.us/reader031/viewer/2022011907/5f4c32192c70ab04826748bd/html5/thumbnails/54.jpg)
Poelman & Associates, Inc. (c) 2003 54
Changing the border of a list box
![Page 55: Swing · 2004-02-29 · Poelman & Associates, Inc. (c) 2003 1 Swing A Quick Tutorial on Programming Swing Applications](https://reader031.vdocuments.us/reader031/viewer/2022011907/5f4c32192c70ab04826748bd/html5/thumbnails/55.jpg)
Poelman & Associates, Inc. (c) 2003 55
A Titled Border for a List Box
![Page 56: Swing · 2004-02-29 · Poelman & Associates, Inc. (c) 2003 1 Swing A Quick Tutorial on Programming Swing Applications](https://reader031.vdocuments.us/reader031/viewer/2022011907/5f4c32192c70ab04826748bd/html5/thumbnails/56.jpg)
Poelman & Associates, Inc. (c) 2003 56
List Box Selection Modes• Single• Multiple_Interval• Single_Interval
![Page 57: Swing · 2004-02-29 · Poelman & Associates, Inc. (c) 2003 1 Swing A Quick Tutorial on Programming Swing Applications](https://reader031.vdocuments.us/reader031/viewer/2022011907/5f4c32192c70ab04826748bd/html5/thumbnails/57.jpg)
Poelman & Associates, Inc. (c) 2003 57
Setting the Button group on a radio button
![Page 58: Swing · 2004-02-29 · Poelman & Associates, Inc. (c) 2003 1 Swing A Quick Tutorial on Programming Swing Applications](https://reader031.vdocuments.us/reader031/viewer/2022011907/5f4c32192c70ab04826748bd/html5/thumbnails/58.jpg)
Poelman & Associates, Inc. (c) 2003 58
Setting the Mnemonics
![Page 59: Swing · 2004-02-29 · Poelman & Associates, Inc. (c) 2003 1 Swing A Quick Tutorial on Programming Swing Applications](https://reader031.vdocuments.us/reader031/viewer/2022011907/5f4c32192c70ab04826748bd/html5/thumbnails/59.jpg)
Poelman & Associates, Inc. (c) 2003 59
Final Dialog Version
![Page 60: Swing · 2004-02-29 · Poelman & Associates, Inc. (c) 2003 1 Swing A Quick Tutorial on Programming Swing Applications](https://reader031.vdocuments.us/reader031/viewer/2022011907/5f4c32192c70ab04826748bd/html5/thumbnails/60.jpg)
Poelman & Associates, Inc. (c) 2003 60
JComboBox• Two styles in the app –
non-editable and editable• If you use the editable
type you should check the input of the user to make sure it is acceptable.
• You can change the style by changing the editable property.
![Page 61: Swing · 2004-02-29 · Poelman & Associates, Inc. (c) 2003 1 Swing A Quick Tutorial on Programming Swing Applications](https://reader031.vdocuments.us/reader031/viewer/2022011907/5f4c32192c70ab04826748bd/html5/thumbnails/61.jpg)
Poelman & Associates, Inc. (c) 2003 61
Creating a JavaGUI -> SampleForms -> Application
![Page 62: Swing · 2004-02-29 · Poelman & Associates, Inc. (c) 2003 1 Swing A Quick Tutorial on Programming Swing Applications](https://reader031.vdocuments.us/reader031/viewer/2022011907/5f4c32192c70ab04826748bd/html5/thumbnails/62.jpg)
Poelman & Associates, Inc. (c) 2003 62
Menu and Menu item hierarchy that defines the menus for the app
![Page 63: Swing · 2004-02-29 · Poelman & Associates, Inc. (c) 2003 1 Swing A Quick Tutorial on Programming Swing Applications](https://reader031.vdocuments.us/reader031/viewer/2022011907/5f4c32192c70ab04826748bd/html5/thumbnails/63.jpg)
Poelman & Associates, Inc. (c) 2003 63
The default menus
![Page 64: Swing · 2004-02-29 · Poelman & Associates, Inc. (c) 2003 1 Swing A Quick Tutorial on Programming Swing Applications](https://reader031.vdocuments.us/reader031/viewer/2022011907/5f4c32192c70ab04826748bd/html5/thumbnails/64.jpg)
Poelman & Associates, Inc. (c) 2003 64
![Page 65: Swing · 2004-02-29 · Poelman & Associates, Inc. (c) 2003 1 Swing A Quick Tutorial on Programming Swing Applications](https://reader031.vdocuments.us/reader031/viewer/2022011907/5f4c32192c70ab04826748bd/html5/thumbnails/65.jpg)
Poelman & Associates, Inc. (c) 2003 65
Copy and paste a menu into the hierarchy
![Page 66: Swing · 2004-02-29 · Poelman & Associates, Inc. (c) 2003 1 Swing A Quick Tutorial on Programming Swing Applications](https://reader031.vdocuments.us/reader031/viewer/2022011907/5f4c32192c70ab04826748bd/html5/thumbnails/66.jpg)
Poelman & Associates, Inc. (c) 2003 66
This shows 2 Edit menus