|
1 | 1 | import java.awt.Color;
|
| 2 | +import java.awt.Font; |
2 | 3 |
|
3 | 4 | import javax.swing.JButton;
|
4 | 5 | import javax.swing.JFrame;
|
5 | 6 | import javax.swing.JLabel;
|
6 | 7 | import javax.swing.SwingConstants;
|
7 | 8 |
|
| 9 | + |
| 10 | + |
8 | 11 | public class Calc {
|
9 |
| - |
| 12 | + |
10 | 13 | Calc(){
|
11 |
| - |
12 |
| - JFrame jf=new JFrame("Calculator"); |
13 |
| - jf.setSize(450,450); |
| 14 | + JFrame jf=new JFrame("Java Calculator"); |
| 15 | + jf.setSize(450,510); |
14 | 16 | jf.setLocation(350, 80);
|
15 | 17 | jf.setLayout(null);
|
16 | 18 | jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
17 | 19 | jf.setVisible(true);
|
18 | 20 |
|
19 | 21 | JLabel Displaylabel=new JLabel("Sample Display");
|
20 | 22 | Displaylabel.setHorizontalAlignment(SwingConstants.RIGHT);
|
21 |
| - Displaylabel.setBounds(20,20,440,50); |
22 |
| - Displaylabel.setBackground(Color.white); |
23 |
| - Displaylabel.setForeground(Color.black); |
| 23 | + Displaylabel.setBounds(20,20,400,70); |
| 24 | + Displaylabel.setBackground(Color.gray); |
| 25 | + Displaylabel.setForeground(Color.white); |
24 | 26 | Displaylabel.setOpaque(true);
|
25 | 27 | jf.add(Displaylabel);
|
26 | 28 |
|
27 | 29 | JButton Mcbutton = new JButton("MC");
|
28 | 30 | Mcbutton.setBounds(20,120,60,60);
|
29 | 31 | jf.add(Mcbutton);
|
30 | 32 |
|
| 33 | + |
| 34 | + JButton Percentagebutton = new JButton("%"); |
| 35 | + Percentagebutton.setBounds(20,190,60,60); |
| 36 | + jf.add(Percentagebutton); |
| 37 | + Percentagebutton.setFont(new Font("Arial", Font.PLAIN, 20)); |
| 38 | + |
| 39 | + JButton Mrbutton = new JButton("MR"); |
| 40 | + Mrbutton.setBounds(100,120,60,60); |
| 41 | + jf.add(Mrbutton); |
| 42 | + |
31 | 43 | JButton Sevenbutton = new JButton("7");
|
32 |
| - Sevenbutton.setBounds(100,120,60,60); |
| 44 | + Sevenbutton.setBounds(100,190,60,60); |
33 | 45 | jf.add(Sevenbutton);
|
| 46 | + Sevenbutton.setFont(new Font("Arial", Font.PLAIN, 30)); |
| 47 | + |
| 48 | + JButton Mminusbutton = new JButton("M-"); |
| 49 | + Mminusbutton.setBounds(180,120,60,60); |
| 50 | + jf.add(Mminusbutton); |
34 | 51 |
|
35 | 52 | JButton Eightbutton = new JButton("8");
|
36 |
| - Eightbutton.setBounds(180,120,60,60); |
| 53 | + Eightbutton.setBounds(180,190,60,60); |
37 | 54 | jf.add(Eightbutton);
|
| 55 | + Eightbutton.setFont(new Font("Arial", Font.PLAIN, 30)); |
| 56 | + |
| 57 | + JButton Mplusbutton = new JButton("M+"); |
| 58 | + Mplusbutton.setBounds(260,120,60,60); |
| 59 | + jf.add(Mplusbutton); |
38 | 60 |
|
39 | 61 | JButton Ninebutton = new JButton("9");
|
40 |
| - Ninebutton.setBounds(260,120,60,60); |
| 62 | + Ninebutton.setBounds(260,190,60,60); |
41 | 63 | jf.add(Ninebutton);
|
| 64 | + Ninebutton.setFont(new Font("Arial", Font.PLAIN, 30)); |
| 65 | + |
| 66 | + JButton Rootbutton = new JButton("Root"); |
| 67 | + Rootbutton.setBounds(340,120,60,60); |
| 68 | + jf.add(Rootbutton); |
| 69 | + Rootbutton.setFont(new Font("Arial", Font.PLAIN, 30)); |
| 70 | + |
42 | 71 |
|
43 | 72 | JButton Divisionbutton = new JButton("/");
|
44 |
| - Divisionbutton.setBounds(340,120,60,60); |
| 73 | + Divisionbutton.setBounds(340,190,60,60); |
45 | 74 | jf.add(Divisionbutton);
|
| 75 | + Divisionbutton.setFont(new Font("Arial", Font.PLAIN, 30)); |
| 76 | + |
46 | 77 |
|
47 | 78 | JButton Plusorminusbutton = new JButton("+/-");
|
48 |
| - Plusorminusbutton.setBounds(20,190,60,60); |
| 79 | + Plusorminusbutton.setBounds(20,260,60,60); |
49 | 80 | jf.add(Plusorminusbutton);
|
| 81 | + Plusorminusbutton.setFont(new Font("Arial", Font.PLAIN,20)); |
50 | 82 |
|
51 | 83 | JButton Fourbutton = new JButton("4");
|
52 |
| - Fourbutton.setBounds(100,190,60,60); |
| 84 | + Fourbutton.setBounds(100,260,60,60); |
53 | 85 | jf.add(Fourbutton);
|
| 86 | + Fourbutton.setFont(new Font("Arial", Font.PLAIN, 30)); |
54 | 87 |
|
55 | 88 | JButton Fivebutton = new JButton("5");
|
56 |
| - Fivebutton.setBounds(180,190,60,60); |
| 89 | + Fivebutton.setBounds(180,260,60,60); |
57 | 90 | jf.add(Fivebutton);
|
| 91 | + Fivebutton.setFont(new Font("Arial", Font.PLAIN, 30)); |
58 | 92 |
|
59 | 93 |
|
60 | 94 |
|
61 | 95 | JButton Sixbutton = new JButton("6");
|
62 |
| - Sixbutton.setBounds(260,190,60,60); |
| 96 | + Sixbutton.setBounds(260,260,60,60); |
63 | 97 | jf.add(Sixbutton);
|
| 98 | + Sixbutton.setFont(new Font("Arial", Font.PLAIN, 30)); |
64 | 99 |
|
65 | 100 | JButton Multibutton = new JButton("X");
|
66 |
| - Multibutton.setBounds(340,190,60,60); |
| 101 | + Multibutton.setBounds(340,260,60,60); |
67 | 102 | jf.add(Multibutton);
|
| 103 | + Multibutton.setFont(new Font("Arial", Font.PLAIN, 30)); |
68 | 104 |
|
69 | 105 |
|
70 | 106 | JButton Cebutton = new JButton("CE");
|
71 |
| - Cebutton.setBounds(20,260,60,60); |
| 107 | + Cebutton.setBounds(20,330,60,60); |
72 | 108 | jf.add(Cebutton);
|
73 | 109 |
|
74 | 110 |
|
75 | 111 | JButton Onebutton = new JButton("1");
|
76 |
| - Onebutton.setBounds(100,260,60,60); |
| 112 | + Onebutton.setBounds(100,330,60,60); |
77 | 113 | jf.add(Onebutton);
|
| 114 | + Onebutton.setFont(new Font("Arial", Font.PLAIN, 30)); |
| 115 | + |
78 | 116 |
|
79 | 117 | JButton Twobutton = new JButton("2");
|
80 |
| - Twobutton.setBounds(180,260,60,60); |
| 118 | + Twobutton.setBounds(180,330,60,60); |
81 | 119 | jf.add(Twobutton);
|
| 120 | + Twobutton.setFont(new Font("Arial", Font.PLAIN, 30)); |
82 | 121 |
|
83 | 122 | JButton Threebutton = new JButton("3");
|
84 |
| - Threebutton.setBounds(260,260,60,60); |
| 123 | + Threebutton.setBounds(260,330,60,60); |
85 | 124 | jf.add(Threebutton);
|
| 125 | + Threebutton.setFont(new Font("Arial", Font.PLAIN, 30)); |
| 126 | + |
86 | 127 |
|
87 | 128 | JButton Subtractbutton = new JButton("-");
|
88 |
| - Subtractbutton.setBounds(340,260,60,60); |
| 129 | + Subtractbutton.setBounds(340,330,60,60); |
89 | 130 | jf.add(Subtractbutton);
|
| 131 | + Subtractbutton.setFont(new Font("Arial", Font.PLAIN, 30)); |
90 | 132 |
|
91 | 133 | JButton Acbutton = new JButton("AC");
|
92 |
| - Acbutton.setBounds(20,330,60,60); |
| 134 | + Acbutton.setBounds(20,400,60,60); |
93 | 135 | jf.add(Acbutton);
|
94 | 136 |
|
95 | 137 | JButton Zerobutton = new JButton("0");
|
96 |
| - Zerobutton.setBounds(100,330,60,60); |
| 138 | + Zerobutton.setBounds(100,400,60,60); |
97 | 139 | jf.add(Zerobutton);
|
| 140 | + Zerobutton.setFont(new Font("Arial", Font.PLAIN, 30)); |
98 | 141 |
|
99 | 142 | JButton Pointbutton = new JButton(".");
|
100 |
| - Pointbutton.setBounds(180,330,60,60); |
| 143 | + Pointbutton.setBounds(180,400,60,60); |
101 | 144 | jf.add(Pointbutton);
|
| 145 | + Pointbutton.setFont(new Font("Arial", Font.PLAIN, 30)); |
| 146 | + |
102 | 147 |
|
103 | 148 | JButton Equalbutton = new JButton("=");
|
104 |
| - Equalbutton.setBounds(260,330,60,60); |
| 149 | + Equalbutton.setBounds(260,400,60,60); |
105 | 150 | jf.add(Equalbutton);
|
| 151 | + Equalbutton.setFont(new Font("Arial", Font.PLAIN, 30)); |
| 152 | + |
106 | 153 |
|
107 | 154 | JButton Plusbutton = new JButton("+");
|
108 |
| - Plusbutton.setBounds(340,330,60,60); |
| 155 | + Plusbutton.setBounds(340,400,60,60); |
109 | 156 | jf.add(Plusbutton);
|
| 157 | + Plusbutton.setFont(new Font("Arial", Font.PLAIN, 30)); |
110 | 158 |
|
111 |
| - |
112 |
| - |
113 |
| - |
114 | 159 | }
|
115 |
| - |
116 | 160 | public static void main(String[] args) {
|
117 |
| - |
118 |
| - /*Calc C=new Calc();*/ |
119 |
| - |
120 | 161 | new Calc();
|
121 | 162 | }
|
122 |
| - |
123 | 163 | }
|
0 commit comments