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();
}
}
希望能帮助你哈