
























































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Notes; Professor: France; Class: Software Development Methods; Subject: Computer Science; University: Colorado State University; Term: Fall 2007;
Typology: Study notes
1 / 64
This page cannot be seen from the preview
Don't miss anything!

























































menu bar
button
combo box
menus
scroll bars
An area where uneditable text or icons can be displayed.
An area in which the user inputs data from the keyboard. The area can alsodisplay information.
An area that triggers an event when clicked with the mouse.
A GUI component that is either selected or not selected.
A drop-down list of items from which the user can make a selection byclicking an item in the list or possibly by typing into the box.
An area containing a list of items from which the user can make a selectionby clicking on any element in the list. Multiple elements can be selected.
A container in which components can be placed and organized.
-^
-^
are lightweight.
-^
public
class
LightWeightButton
extends
Component
public
void
paint(Graphics
g)
Java code
goes here */
Swing componentsnames start with ‘J’.
-^
-^
AWT.
-^
JLabelJLabelJLabelJLabel
3
import
java.awt.*;
4
import
java.awt.event.*;
5
import
javax.swing.*;
6 7
public class
LabelTest
extends
JFrame {
8
private
JLabel label1, label2, label3;
9 10
// set up GUI
11
public
LabelTest()
12
{
13
super
(^ "Testing JLabel"
);
1415
// get content pane and set its layout
17
setLayout(
new
FlowLayout() );
1819
// JLabel constructor with a string argument
20
label1 =
new
JLabel(
"Label with text"
);
21
label1.setToolTipText(
"This is label1"
);
22
add( label1 );
23
50 51
}^ // end class LabelTest
// construct textfield with default text,// 20 visible elements and no event handler textField3 =
new
JTextField(
"Uneditable text field"
,^20
);
textField3.setEditable(
false
);
add( textField3 ); // construct passwordfield with default text passwordField =
new
JPasswordField(
"Hidden text"
);
add( passwordField ); // register event handlers TextFieldHandler handler =
new
TextFieldHandler();
textField1.addActionListener( handler );textField2.addActionListener( handler );textField3.addActionListener( handler );passwordField.addActionListener( handler );setSize(
325
,^100
);
setVisible(
true
);
}^ // end constructor TextFieldTest public static void
main( String args[] )
{ TextFieldTest application =
new
TextFieldTest();
application.setDefaultCloseOperation(
JFrame.EXIT_ON_CLOSE
);
}
// private inner class for event handling private class
TextFieldHandler
implements
ActionListener {
// process textfield events public void
actionPerformed( ActionEvent event )
{ String string =
// user pressed Enter in JTextField textField1 if^ ( event.getSource() == textField1 )string =
"textField1: "
// user pressed Enter in JTextField textField2 else if
( event.getSource() == textField2 ) string =
"textField2: "
// user pressed Enter in JTextField textField3 else if
( event.getSource() == textField3 ) string =
"textField3: "
// user pressed Enter in JTextField passwordField else if
( event.getSource() == passwordField ) { string =
"passwordField: "
new
String( passwordField.getPassword() );
}
-^
addActionListener
TextFieldTest.java
actionPerformed
?
» Event ID specifies event type that occurred