java运行显示不出来窗口? 5
packagewuwei;importjava.awt.*;importjavax.swing.*;publicclassbuju{publicbuju(){JButto...
package wuwei;
import java.awt.*;
import javax.swing.*;
public class buju {
public buju() {
JButton btn1,btn2;
JFrame frame =new JFrame();
frame.setSize(800,800);
Container contentPane =frame.getContentPane();
contentPane.setLayout(new GridLayout(2,2));
JLabel[] label = new JLabel[5];
for (int i=0;i<label.length;i++) {
label[i] =new JLabel("label"+(i+1),JLabel.CENTER);
label[i].setBackground(Color.blue);
label[i].setBorder(BorderFactory.createEtchedBorder());
label[i].setOpaque(true);
}
JPanel panel1=new JPanel(new GridLayout(1,2));
panel1.add(label[0]);
JPanel panel2=new JPanel(new GridLayout(1,3));
panel2.add(label[1]);
JPanel panel3=new JPanel(new GridLayout(1,4));
panel3.add(label[2]);
panel3.add(label[4]);
JPanel panel4=new JPanel(new GridLayout(1,5));
panel4.add(label[3]);
btn1=new JButton("你好");
btn2=new JButton("再见");
panel1.add(btn1);
panel4.add(btn2);
contentPane.add(panel1);
contentPane.add(panel2);
frame.pack();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
public static void mian(String[]args){
new buju();
}
}
大神,这怎么回事呀 展开
import java.awt.*;
import javax.swing.*;
public class buju {
public buju() {
JButton btn1,btn2;
JFrame frame =new JFrame();
frame.setSize(800,800);
Container contentPane =frame.getContentPane();
contentPane.setLayout(new GridLayout(2,2));
JLabel[] label = new JLabel[5];
for (int i=0;i<label.length;i++) {
label[i] =new JLabel("label"+(i+1),JLabel.CENTER);
label[i].setBackground(Color.blue);
label[i].setBorder(BorderFactory.createEtchedBorder());
label[i].setOpaque(true);
}
JPanel panel1=new JPanel(new GridLayout(1,2));
panel1.add(label[0]);
JPanel panel2=new JPanel(new GridLayout(1,3));
panel2.add(label[1]);
JPanel panel3=new JPanel(new GridLayout(1,4));
panel3.add(label[2]);
panel3.add(label[4]);
JPanel panel4=new JPanel(new GridLayout(1,5));
panel4.add(label[3]);
btn1=new JButton("你好");
btn2=new JButton("再见");
panel1.add(btn1);
panel4.add(btn2);
contentPane.add(panel1);
contentPane.add(panel2);
frame.pack();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
public static void mian(String[]args){
new buju();
}
}
大神,这怎么回事呀 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询