本帖最后由 冯超 于 2013-5-5 19:19 编辑
看图1 和图2
知识点:swing
输入:3 和4 点击那个button按钮,则显示结果!
界面我已经做好,就差一些监听事件,代码如下:- package day1;
- import javax.swing.JButton;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.JPanel;
- import javax.swing.JTextField;
- public class test1 {
- /**
- * @param args
- */
- final static int WIDTH = 320;
- final static int HEIGHT = 240;
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- JFrame jf = new JFrame("计算器");
- jf.setSize(WIDTH,HEIGHT);
- jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- jf.setVisible(true);
-
- JPanel jp = new JPanel();
- jf.setContentPane(jp);
- component(jp);
- //text.setBorder(BorderFactory.createLineBorder(Color.black));
- }
- public static void component(JPanel jp) {
- JTextField text1 = new JTextField (15); //创建文本框
- JLabel method = new JLabel("*"); //创建标签
- JTextField text2 = new JTextField (15);
- JButton method1 = new JButton("="); //创建标签
- JTextField text3 = new JTextField (15);
- text1.setText("请输出第一个数字:");
- text2.setText("请输出第二个数字:");
- text3.setText("结果");
- jp.add(text1);
- jp.add(method);
- jp.add(text2);
- jp.add(method1);
- jp.add(text3);
- }
- }
复制代码 |
|