publicclassButtonTest{publicstaticvoidmain(String[]args){ButtonFrameframe=newButtonFrame();frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);frame.setVisible(true);}}c...
public class ButtonTest {
public static void main(String[] args) {
ButtonFrame frame = new ButtonFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
class ButtonFrame extends JFrame {
public ButtonFrame() {
setTitle("计算器");
int DEFAULT_WIDTH = 0;
int DEFAULT_HEIGHT = 0;
setSize(DEFAULT_WIDTH,DEFAULT_HEIGHT);
ButtonPanel panel=new ButtonPanel();
add(panel);
}
public static final int DEFAULT_WIDTH = 400;
public static final int DEFAULT_HEIGHT = 300;
class ButtonPanel extends JPanel {
public ButtonPanel() {
JButton oneButton = new JButton("1");
JButton twoButton = new JButton("2");
JButton thrButton = new JButton("3");
JButton fouButton = new JButton("4");
JButton firButton = new JButton("5");
JButton sexButton = new JButton("6");
JButton sevButton = new JButton("7");
JButton egiButton = new JButton("8");
JButton ninButton = new JButton("9");
add(oneButton);
add(twoButton);
add(thrButton);
add(fouButton);
add(firButton);
add(sexButton);
add(sevButton);
add(egiButton);
add(ninButton);
}
}
}
谁给看一下哪错了。并改正下。就是要在一个面板上显示1-9几个按钮
展开