-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlist_component.java
More file actions
32 lines (28 loc) · 929 Bytes
/
list_component.java
File metadata and controls
32 lines (28 loc) · 929 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import java.awt.*;
import java.awt.event.*;
public class ListExample {
public static void main(String[] args) {
Frame frame = new Frame("List Example");
List list = new List(4, false);
list.add("Item 1");
list.add("Item 2");
list.add("Item 3");
list.add("Item 4");
Button button = new Button("Show Selected");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println("Selected Item: " + list.getSelectedItem());
}
});
frame.add(list);
frame.add(button);
frame.setSize(300, 200);
frame.setLayout(new FlowLayout());
frame.setVisible(true);
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent we) {
System.exit(0);
}
});
}
}