forked from mohammedabdulbari/Java-SE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ListBoxDemo.java
76 lines (59 loc) · 1.47 KB
/
ListBoxDemo.java
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package listboxdemo;
import java.awt.*;
import java.awt.event.*;
class MyFrame extends Frame implements ItemListener,ActionListener
{
List l;
Choice c;
TextArea ta;
MyFrame()
{
super("ListBox Demo");
l=new List(4,true);
c=new Choice();
ta=new TextArea(20,30);
l.add("Monday");
l.add("TuesDay");
l.add("Wednesday");
l.add("Thursday");
l.add("Friday");
l.add("Saturday");
l.add("Sunday");
c.add("Juanuary");
c.add("February");
c.add("March");
c.add("April");
setLayout(new FlowLayout());
add(l);
add(c);
add(ta);
l.addItemListener(this);
c.addItemListener(this);
l.addActionListener(this);
}
public void itemStateChanged(ItemEvent ie)
{
if(ie.getSource()==l)
ta.setText(l.getSelectedItem());
else
ta.setText(c.getSelectedItem());
}
public void actionPerformed(ActionEvent ae)
{
String list[]=l.getSelectedItems();
String txt="";
for(String x:list)
txt+=x+"\n";
ta.setText(txt);
l.addItem(txt);
}
}
public class ListBoxDemo
{
public static void main(String[] args)
{
MyFrame f=new MyFrame();
f.setSize(500,500);
f.setVisible(true);
}
}