forked from jreycid/JavaDebugging
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJMenuFrame.java
More file actions
62 lines (61 loc) · 1.89 KB
/
Copy pathJMenuFrame.java
File metadata and controls
62 lines (61 loc) · 1.89 KB
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
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.Color;
public class JMenuFrame extends JFrame implements
ActionListener
{
private JMenuBar mainBar = new JMenuBar();
private JMenu menu1 = new JMenu("File");
private JMenu menu2 = new JMenu("Colors");
private JMenuItem exit = new JMenuItem("Exit");
private JMenu bright = new JMenu("Bright");
private JMenuItem dark = new JMenuItem("Dark");
private JMenuItem white = new JMenuItem("White");
private JMenuItem pink = new JMenuItem("Pink");
private JMenuItem yellow = new JMenuItem("Yellow");
private JLabel label = new JLabel("Hello");
public JMenuFrame()
{
setLayout(new FlowLayout());
setJMenuBar(mainBar);
mainBar.add(menu1);
mainBar.add(menu2);
menu1.add(exit);
menu2.add(bright);
menu2.add(dark);
menu2.add(white);
bright.add(pink);
bright.add(yellow);
exit.addActionListener(this);
dark.addActionListener(this);
white.addActionListener(this);
pink.addActionListener(this);
yellow.addActionListener(this);
add(label);
label.setFont(new Font("Arial", Font.BOLD, 26));
}
@Override
public void actionPerformed(ActionEvent e)
{
Object source = e.getSource();
Container con = getContentPane();
if(source == exit)
System.exit(0);
else if(source == dark)
con.setBackground(Color.BLACK);
else if(source == white)
con.setBackground(Color.WHITE);
else if(source == pink)
con.setBackground(Color.PINK);
else con.setBackground(Color.YELLOW);
}
public static void main(String[] args)
{
JMenuFrame mFrame = new JMenuFrame();
final int WIDTH = 250;
final int HEIGHT = 200;
mFrame.setSize(WIDTH, HEIGHT);
mFrame.setVisible(true);
}
}