-
Notifications
You must be signed in to change notification settings - Fork 0
/
P9.java
71 lines (66 loc) · 1.79 KB
/
P9.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
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.*;
public class P9 extends JFrame implements ActionListener
{
private JMenuItem one;
private JMenuItem two;
private JMenuItem three;
private JMenuItem four;
private JTextArea l;
public P9()
{
FlowLayout f=new FlowLayout();
JMenuBar menubar=new JMenuBar();
JMenu menu=new JMenu("Shop");
l=new JTextArea(null,1,5);
JPanel p=new JPanel();
add(p);
l.setLayout(new FlowLayout());
p.add(l);
one=new JMenuItem("Apple");
two=new JMenuItem("Ball");
three=new JMenuItem("Cat");
four=new JMenuItem("Dog");
menubar.add(menu);
menu.add(one);
menu.add(two);
menu.add(three);
menu.add(four);
one.addActionListener(this);
two.addActionListener(this);
three.addActionListener(this);
four.addActionListener(this);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setJMenuBar(menubar);
setSize(300,150);
setLayout(new FlowLayout());
setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()== one)
{
l.setText(one.getText());
}
else if(e.getSource()== two)
{
l.setText(two.getText());
}
else if(e.getSource()== three)
{
l.setText(three.getText());
}
else if(e.getSource()== four)
{
l.setText(four.getText());
}
}
public static void main(String args[])
{
new P9();
}
}