我用java编了个计算器的面板,
第一行是一个TextField
第二行是Backspace、CE、C
第3行是MC 7 8 9 / sqrt
第3行是MR 4 5 6 * %
第3行是MS 1 2 3 - 1/X
第3行是M+ 0 +/- . + =
程序如下,各位高手帮帮忙 谢谢~~
import java.awt.*;
public class Jisuanqi extends Frame{
public Jisuanqi(){
GridBagLayout grid=new GridBagLayout();
GridBagConstraints c=new GridBagConstraints();
setLayout(grid);
c.fill=GridBagConstraints.BOTH;
c.gridwidth=GridBagConstraints.REMAINDER;
add(new TextField());
c.gridwidth=2;
add(new Button("Backspace"));
add(new Button("CE"));
c.gridwidth=GridBagConstraints.REMAINDER;
add(new Button("C"));
c.gridwidth=1;
add(new Button("MC"));
add(new Button("7"));
add(new Button("8"));
add(new Button("9"));
add(new Button("/"));
c.gridwidth=GridBagConstraints.REMAINDER;
add(new Button("sqrt"));
add(new Button("MR"));
add(new Button("4"));
add(new Button("5"));
add(new Button("6"));
add(new Button("*"));
c.gridwidth=GridBagConstraints.REMAINDER;
add(new Button("%"));
add(new Button("MS"));
add(new Button("1"));
add(new Button("2"));
add(new Button("3"));
add(new Button("-"));
c.gridwidth=GridBagConstraints.REMAINDER;
add(new Button("1/x"));
add(new Button("M+"));
add(new Button("0"));
add(new Button("+/-"));
add(new Button("."));
add(new Button("+"));
c.gridwidth=GridBagConstraints.REMAINDER;
add(new Button("="));
}
public static void main(String args[]){
Jisuanqi fr=new Jisuanqi();
fr.setTitle("计算器");
fr.pack();
fr.setVisible(true);
}
}