主题:GUI 编程出错,有经验的麻烦近来指点下
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class BoxLayoutExaple extends JApplet{
public void init(){
Container cp =getContentPane();
Box bBox=Box.createHorizontalBox();
cp.add(bBox);
Box vBox1=Box.createVerticalBox();
JLabel 1b=new JLabel("这是标签");
vBox1.add(1b);
JButton bt1=new JButton("This is button1");
bt1.setMaximumSize(new Dimension(100,200));
vBox.add(bt1);
bBox.add(vBox1);
Box vBox2=new createVerticalBox();
bBox.add(vBox2);
JTextField tf1=new JTextField("This is TextField");
tf1.setAlignmentX(Component.CENTER_ALIGNMENT);
tf1.setMaximumSize(new Dimension(150,50));
vBox2.add(tf1);
Box vBox2=Box.createHorizontalBox();
vBox2.add(vBox2h);
Box vBox2h1=Box.createVerticalBox();
vBox2h1.add(Box.createVerticalSrut(20));
vBox2h1.add(new JTextAre("This is TextField"));
vBox2h1.add(Box.createVerticalStrut(20));
vBox2h.add(vBox2h1);
Box vBox2h2=Box.createVerticalBox();
vBox2h2.add(new JButton("button2"));
vBox2h2.add(Box.createVerticalGlue());
vBox2h2.add(new JButton("button4"));
vBox2h.add(vBox2h2);
}
}
import javax.swing.*;
import java.awt.event.*;
public class BoxLayoutExaple extends JApplet{
public void init(){
Container cp =getContentPane();
Box bBox=Box.createHorizontalBox();
cp.add(bBox);
Box vBox1=Box.createVerticalBox();
JLabel 1b=new JLabel("这是标签");
vBox1.add(1b);
JButton bt1=new JButton("This is button1");
bt1.setMaximumSize(new Dimension(100,200));
vBox.add(bt1);
bBox.add(vBox1);
Box vBox2=new createVerticalBox();
bBox.add(vBox2);
JTextField tf1=new JTextField("This is TextField");
tf1.setAlignmentX(Component.CENTER_ALIGNMENT);
tf1.setMaximumSize(new Dimension(150,50));
vBox2.add(tf1);
Box vBox2=Box.createHorizontalBox();
vBox2.add(vBox2h);
Box vBox2h1=Box.createVerticalBox();
vBox2h1.add(Box.createVerticalSrut(20));
vBox2h1.add(new JTextAre("This is TextField"));
vBox2h1.add(Box.createVerticalStrut(20));
vBox2h.add(vBox2h1);
Box vBox2h2=Box.createVerticalBox();
vBox2h2.add(new JButton("button2"));
vBox2h2.add(Box.createVerticalGlue());
vBox2h2.add(new JButton("button4"));
vBox2h.add(vBox2h2);
}
}