本帖最后由 杨兴庭 于 2013-7-16 17:45 编辑
- import java.awt.*;
- import java.applet.*;
- import java.awt.event.*;
- import javax.swing.*;
- public class Calculator1 extends Frame
- { private static String[] KEYS={"0","1","2","3",
- "4","5","6","7",
- "8","9","+","-",
- "*","/","=","%"};
- private Panel keys;
- private Panel text;
- public Calculator1(String title)
- {super(title);
- setSize(200,200);
- setLocation(100,100);
- setKeys();
- setText();
- setLayout(new BorderLayout(3,3));
- add(keys,BorderLayout.CENTER);
- add(text,BorderLayout.NORTH );
- addWindowListener(new WindowAdapter()
- {
- public void windowClosing(WindowEvent e)
- {
- System.exit(0);
- }
- });
- }
- public void setKeys()
- {
- Panel keys=new Panel();
- keys.setLayout(new GridLayout(4,4,3,3));
- for(int i=0;i<KEYS.length;i++)
- {
- keys.add(new JButton(KEYS[i]));
- }
- }
- public void setText()
- {
- Panel text=new Panel();
- TextField f=new TextField(25);
- text.add(f);
- }
- public static void main(String[] args) throws HeadlessException
- { Calculator1 f=new Calculator1("计算器");
- f.pack();
- f.show();
- }
- }
复制代码 |