import java.awt.Frame;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class BoxLayoutDemo extends JFrame {
private static final long serialVersionUID = 1L;
private JButton jButton1 = null;
private JButton jButton = null;
private JButton jButton3 = null;
public BoxLayoutDemo() {
super();
try{
initialize();
}
catch (Exception e){
e.printStackTrace();
}
}
private void initialize() throws Exception {
this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
this.setSize(300, 200);
this.setTitle("Frame");
this.add(getJButton1(), null);
this.add(getJButton(), null);
this.add(getJButton3(), null);
}
private JButton getJButton1() {
if (jButton1 == null) {
jButton1 = new JButton();
jButton1.setText("JButton1");
}
return jButton1;
}
private JButton getJButton() {
if (jButton == null) {
jButton = new JButton();
jButton.setText("JButton2");
}
return jButton;
}
private JButton getJButton3() {
if (jButton3 == null) {
jButton3 = new JButton();
jButton3.setText("JButton3");
}
return jButton3;}
public static void main (String[] args){
try{UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}catch (Exception e)
{
e.printStackTrace();
}
BoxLayoutDemo frame =new BoxLayoutDemo();
frame.setVisible(true);
}
protected void processWindowEvent(WindowEvent e)
{
if(e.getID()==WindowEvent.WINDOW_CLOSING)
System.exit(0);
}
}
程序有什么错误吗?为什么运行不出来呀?
[此贴子已经被作者于2007-8-29 0:31:34编辑过]