123. }
124.
125. });
126. context.add(numPanel,"Center");
127.
128. // 操作面板
129. opPanel.setSize(50,300);
130. opPanel.setLayout(new GridLayout(4,1,5,5)); 131. opPanel.add(btnPlus);
132. opPanel.add(btnMinus);
133. opPanel.add(btnX);
134. opPanel.add(btnEqu);
135. btnPlus.addActionListener(btnListener); 136. btnPlus.addKeyListener(keyListener);
137. btnMinus.addActionListener(btnListener); 138. btnMinus.addKeyListener(keyListener); 139. btnX.addActionListener(btnListener); 140. btnX.addKeyListener(keyListener); 141. btnEqu.addActionListener(new ActionListener(){
142.
143. public void
actionPerformed(ActionEvent e) {
144. pressEqualButton(); 145. }
146.
147. });
148. btnEqu.addKeyListener(keyListener); 149. context.add(opPanel,"East");
150. }
151.
152. /**
153. * 创建数字按钮
154. * @param n 按钮上的数字
155. * @return 创建的按钮
156. */
157. public JButton getNumberButton(final int n){ 158. JButton btn = new JButton(String.valueOf(n));
159. btn.setSize(30,50);
160. btn.addActionListener(btnListener); 161. btn.addKeyListener(keyListener);
162. return btn;
163. }