import java.awt.GridBagLayout;
import java.awt.Panel;
import javax.swing.BoxLayout;
import java.awt.ComponentOrientation;
import java.awt.SystemColor;
import java.awt.Font;
import java.awt.Toolkit;
import javax.swing.JButton;
import java.awt.Dimension;
import javax.swing.*;
public class BoxLayoutDemo extends Panel {
private static final long serialVersionUID = 1L;
private JButton jButton = null;
private JButton jButton1 = null;
private JButton jButton2 = null;
private JButton jButton3 = null;
private JButton jButton4 = null;
/**
* This is the default constructor
*/
public BoxLayoutDemo() {
super();
initialize();
}
/**
* This method initializes this
*
* @return void
*/
private void initialize() {
this.setSize(426, 200);
this.setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
this.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
this.setFont(new Font("Dialog", Font.PLAIN, 12));
this.setBackground(SystemColor.activeCaptionBorder);
this.add(getJButton(), null);
this.add(getJButton1(), null);
this.add(getJButton2(), null);
this.add(getJButton3(), null);
this.add(getJButton4(), null);
}
/**
* This method initializes jButton
*
* @return javax.swing.JButton
*/
private JButton getJButton() {
if (jButton == null) {
jButton = new JButton();
jButton.setText("JButton1");
}
return jButton;
}
/**
* This method initializes jButton1
*
* @return javax.swing.JButton
*/
private JButton getJButton1() {
if (jButton1 == null) {
jButton1 = new JButton();
jButton1.setText("JButton2");
}
return jButton1;
}
/**
* This method initializes jButton2
*
* @return javax.swing.JButton
*/
private JButton getJButton2() {
if (jButton2 == null) {
jButton2 = new JButton();
jButton2.setText("JButton3");
}
return jButton2;
}
/**
* This method initializes jButton3
*
* @return javax.swing.JButton
*/
private JButton getJButton3() {
if (jButton3 == null) {
jButton3 = new JButton();
jButton3.setText("JButton4");
}
return jButton3;
}
/**
* This method initializes jButton4
*
* @return javax.swing.JButton
*/
private JButton getJButton4() {
if (jButton4 == null) {
jButton4 = new JButton();
jButton4.setText("JButton5");
}
return jButton4;
}
public static void main(String[] args){
try{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}catch (Exception e ){e.printStackTrace();
}
BoxLayoutDemo frame=new BoxLayoutDemo();
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize=frame.getSize();
frame.setLocation((screenSize.height-frameSize.height)/2,(screenSize.width-frameSize.width)/2);
frame.setVisible(true);
// @jve:decl-index=0:visual-constraint="68,55"
}
}
程序有什么问题吗?为什么显示不出画面呀?