怎样用java制作出如图所示的对话框界面
import javax.swing.*;
import java.awt.*;
public class BoxExample_1 {
public static void main(String[] args) {
WindowBox win = new WindowBox();
win.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
class WindowBox extends JFrame {
Box baseBox, boxV1, boxV2, confirmBox;
JMenuBar menu;
JMenu option;
JMenuItem newUser,exit;
WindowBox() {
menu = new JMenuBar();
option = new JMenu("菜单选项");
newUser = new JMenuItem("新建用户");
exit = new JMenuItem("退出");
option.add(newUser);
option.addSeparator();
option.add(exit);
menu.add(option);
setJMenuBar(menu);
boxV1 = Box.createVerticalBox();
boxV1.add(new Label("用户名"));
boxV1.add(Box.createVerticalStrut(8));
boxV1.add(new Label("密码"));
boxV2 = Box.createVerticalBox();
boxV2.add(new TextField(12));
boxV2.add(Box.createVerticalStrut(8));
boxV2.add(new TextField(12));
baseBox = Box.createHorizontalBox();
baseBox.add(boxV1);
baseBox.add(Box.createHorizontalStrut(10));
baseBox.add(boxV2);
setLayout(new FlowLayout());
add(baseBox);
confirmBox = Box.createHorizontalBox();
confirmBox.add(new JButton("确认"));
confirmBox.add(new JButton("取消"));
add(confirmBox, BorderLayout.PAGE_END);
setSize(250,170);
setVisible(true);
}
}
个人比较喜欢box布局,整齐点,窗口标题之类的细节自己弄