您的位置:首页 > 其它

swing版本计算器排版问题

2013-10-12 15:20 169 查看
package Swing_exercise;

import java.awt.*;

import javax.swing.*;

public class Calc extends JFrame {

JPanel mainPanle, show, rightPanel;

JTextField showIn;

JButton[] jbs = new JButton[9];
JButton zero = new JButton("0");
JButton add1 = new JButton("+");
JButton less = new JButton("-");
JButton muit = new JButton("*");
JButton div = new JButton("/");
JButton point = new JButton(".");
JButton equal = new JButton("=");

Calc() {
mainPanle = new JPanel(new GridLayout(4, 3, 10, 10));
show = new JPanel(new FlowLayout());
rightPanel = new JPanel(new GridLayout(4, 1, 10, 10));

for (int i = 0; i < 9; i++) {
jbs[i] = new JButton(String.valueOf(i + 1));

}
for (int i = 0; i < 9; i++) {
mainPanle.add(jbs[i]);
}
mainPanle.add(point);
mainPanle.add(zero);
mainPanle.add(equal);

showIn = new JTextField(20);
show.add(showIn);

add1.setForeground(Color.gray);
add1.setBackground(Color.black);
add1.setFont(new Font("黑体", Font.BOLD, 8));

rightPanel.add(add1);
rightPanel.add(less);
rightPanel.add(muit);
rightPanel.add(div);

this.add(show, BorderLayout.NORTH);
this.add(mainPanle);
this.add(rightPanel, BorderLayout.EAST);

this.setResizable(false);
this.setVisible(true);
this.setBounds(400, 300, 250, 320);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);

}

public static void main(String[] args) {
new Calc();

}

}




怎么在JFrame上 对左右两个JPanel的间距进行设置??
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: