Repository navigation
Expand file tree
/
Copy pathPanelTest.java
More file actions
70 lines (59 loc) · 1.55 KB
/
Copy pathPanelTest.java
File metadata and controls
70 lines (59 loc) · 1.55 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
63
64
65
66
67
68
69
70
/**
* @(#)PanelTest.java
*
*
* @author
* @version 1.00 2015/5/14
*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class PanelTest extends JFrame implements ActionListener
{
private JPanel panel;
private JLabel output;
private JButton[] buttons;
private JButton clear;
public PanelTest()
{
panel = new JPanel();
output = new JLabel(" ");
buttons = new JButton[12];
clear = new JButton("clear");
for (int i = 0; i <= 9; i ++)
buttons[i] = new JButton(""+i);
buttons[10] = new JButton("#");
buttons[11] = new JButton("*");
clear = new JButton("CLEAR");
setSize(400,400);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setTitle("Calculator");
panel.setLayout(new GridLayout(4,3));
for (int i = 1; i <=9; i ++)
panel.add(buttons[i]);
panel.add(buttons[10]);
panel.add(buttons[0]);
panel.add(buttons[11]);
Container pane = this.getContentPane();
this.setLayout(new BorderLayout());
pane.add(output, BorderLayout.NORTH);
pane.add(clear, BorderLayout.SOUTH);
pane.add(panel, BorderLayout.CENTER);
for (int i = 0; i < 12; i ++)
buttons[i].addActionListener(this);
clear.addActionListener(this);
setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
if (e.getActionCommand().equals("CLEAR"))
output.setText(" ");
else
{
String content = e.getActionCommand();
output.setText(output.getText()+content);
}
}
public static void main (String args[])
{new PanelTest();}
}