package bottntest;
import java.awt.*;
import javax.swing.*;
public class BoxLayout1 extends JFrame{
private JPanel jp = new JPanel();
private JPanel jpy = new JPanel();
private JPanel jpx = new JPanel();
BoxLayout1(){
jpy.setLayout(new BoxLayout(jpy,BoxLayout.Y_AXIS));
for(int i = 1;i<=5;i++){
jpy.add(new JButton("jpy "+i));
}
jpx.setLayout(new BoxLayout(jpy,BoxLayout.X_AXIS));
for(int j = 1;j <= 5;j++){
jpx.add(new JButton("jpx "+j));
}
jp = (JPanel)getContentPane();
jp.setLayout(new BorderLayout());
jp.add(jpy,BorderLayout.EAST);
jp.add(jpx,BorderLayout.SOUTH);
setBounds(150,150,450,200);
setVisible(true);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
new BoxLayout1();
}
}
为什么会有执行错误说setVisible(true);
有错误.请指点.
----------------解决方案--------------------------------------------------------
发现你很粗心啊
我看了5分钟才发现你这里写错了
jpy.setLayout(new BoxLayout(jpy,BoxLayout.Y_AXIS));
for(int i = 1;i<=5;i++){
jpy.add(new JButton("jpy "+i));
}
jpx.setLayout(new BoxLayout(jpy,BoxLayout.X_AXIS));
for(int j = 1;j <= 5;j++){
jpx.add(new JButton("jpx "+j));
}
明白了吗?
----------------解决方案--------------------------------------------------------
晕死.我一般喜欢晚上敲代码.
可能当时脑袋必浑.谢谢了.
----------------解决方案--------------------------------------------------------