展开全部
把WindowBoxLayout 类放到EduSystem类的外62616964757a686964616fe78988e69d8331333337393465面,另外给窗口设置大小,否则打开是最小化界面win.setSize(400, 300);。界面上的位置还需要你自己调整了。代码如下:
import java.awt.*;
import javax.swing.*;
public class EduSystem {
public static void main(String args[]){
WindowBoxLayout win=new WindowBoxLayout();
win.setTitle("教务系统");
win.setSize(400, 300);
}
}
class WindowBoxLayout extends JFrame{
Box baseBox,boxV1,boxV2;
JRadioButton radio1,radio2;
JButton button;
ButtonGroup group;
WindowBoxLayout(){
setLayout(new java.awt.FlowLayout());
init();
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
void init(){
group=new ButtonGroup();
radio1=new JRadioButton("教师");
radio2=new JRadioButton("学生");
group.add(radio1);
group.add(radio2);
boxV1=Box.createVerticalBox();
boxV1.add(new JLabel("登陆账号:"));
boxV1.add(Box.createVerticalStrut(8));
boxV1.add(new JLabel("登陆密码:"));
boxV1.add(Box.createVerticalStrut(8));
boxV2=Box.createVerticalBox();
boxV2.add(new JTextField(10));
boxV2.add(Box.createVerticalStrut(8));
boxV2.add(new JTextField(10));
boxV2.add(Box.createVerticalStrut(8));
boxV2.add(radio1);
boxV2.add(radio2);
boxV2.add(new JButton("登陆"));
baseBox=Box.createHorizontalBox();
baseBox.add(boxV1);
baseBox.add(Box.createHorizontalStrut(10));
baseBox.add(boxV2);
add(baseBox);
}
}