编写java程序,创建一个框架并将其布局管理其设置为FlowLayot,添加两个面板,每个面板包含三个按钮
1个回答
展开全部
lz 你好
具体代码如下:
import java.awt.*;
import javax.swing.*;
public class Test extends JFrame{
private JPanel panel_1,panel_2;
private JButton[] button_1,button_2;
public Test(){
super("Test");
button_1 = new JButton[3];
button_2 = new JButton[3];
panel_1 = new JPanel(new GridLayout(3,2));
panel_2 = new JPanel(new GridLayout(3,2));
for (int i = 0; i < 3; i++) {
button_1[i] = new JButton("Panel_1:"+(i+1));
button_2[i] = new JButton("Panel_2:"+(i+4));
panel_1.add(button_1[i]);
panel_2.add(button_2[i]);
}
setLayout(new FlowLayout(FlowLayout.CENTER,5,30));
getContentPane().add(panel_1);
getContentPane().add(panel_2);
setLocation(400,150);
setSize(200,300);
setVisible(true);
setDefaultCloseOperation(3);
}
public static void main(String[] args) {
new Test();
}
}
希望能帮助你哈
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询