Java语言如何模拟一个简单的计算器程序,用eclpse工具的步骤?

Java语言如何模拟一个简单的计算器程序,用eclpse工具的步骤?Java语言如何模拟一个简单的计算器程序,用eclpse工具的步骤?

1个回答

import java.awt.GridLayout;
import java.awt.LayoutManager;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class Hw2 {

public static void main(String[] args) {
    JFrame jf = new JFrame("简易计算器");
    jf.setLayout(null);//一定要精确布局!!!!!!!!!!!!!!!!!
    JPanel contentPane1 = new JPanel();
    contentPane1.setLayout(null);//上面的文本
    JPanel contentPane2 = new JPanel();
    contentPane2.setLayout(new GridLayout());//下面的网格布局
    //建立文本框
    JTextField jt = new JTextField();
    jt.setBounds(0, 0, 300, 50);
    jt.setEditable(false);
    contentPane1.add(jt);
    //建立girdlayout
    JButton jb[] = new JButton[16];
    String numbers[] = {
            "1","2","3","+","4","5","6","-","7","8","9","*","0",".","=","/"
    };

    GridLayout grid= new GridLayout(4,4);
    contentPane2.setLayout(grid);
    for(int i = 0 ; i < 16 ; i++){
        jb[i]=new JButton(numbers[i]);
        contentPane2.add(jb[i]);    
    }

    contentPane2.setBounds(0, 50, 300, 270);


    jf.add(contentPane1);
    jf.add(contentPane2);
    jf.setBounds(300, 350,300 , 350);
    jf.setVisible(true);
    jf.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    jf.setResizable(false);

}

}

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问