javaGUI设计,求做出程序,最好有注释
2个回答
展开全部
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
public class LoginPage extends JFrame{
private static final long serialVersionUID = 1L;
public static final String INITIAL_VALUE = " ";
public static final String SUCCESS = " 登记学生张三成功 ";
public static final String FAILURE = "登记失败,请重新输出";
private JPanel panel;
private JLabel messageLabel;
public LoginPage(){
start();
}
public void start(){
JLabel title = new JLabel("学 生 登 记");
JLabel idLabel = new JLabel("学号: ");
JLabel nameLabel = new JLabel("名字: ");
JLabel genderLable = new JLabel("性别: ");
JTextField idField = new JTextField(10);
JTextField nameField = new JTextField(10);
JRadioButton maleButton = new JRadioButton("男");
JRadioButton femaleButton = new JRadioButton("女");
//把这两个按扭放到一个组中,实现单选
ButtonGroup group = new ButtonGroup();
group.add(maleButton);
group.add(femaleButton);
JButton confirmButton = new JButton("确定");
JButton resetButton = new JButton("重置");
confirmButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
//这里实现你登录的判断
JOptionPane.showMessageDialog(LoginPage.this, "你自已实现登录哦");
}
});
resetButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
messageLabel.setText(INITIAL_VALUE);
idField.setText("");
nameField.setText("");
group.clearSelection();
}
});
this.messageLabel = new JLabel(INITIAL_VALUE);
this.panel = new JPanel();
this.panel.setBorder(BorderFactory.createEtchedBorder());
//设置面板最大的大小
this.panel.setMaximumSize(new Dimension(180, 150));
this.panel.add(messageLabel);
this.panel.add(idLabel);
this.panel.add(idField);
this.panel.add(nameLabel);
this.panel.add(nameField);
this.panel.add(genderLable);
this.panel.add(maleButton);
this.panel.add(femaleButton);
this.panel.add(confirmButton);
this.panel.add(resetButton);
//设置布局为BoxLayout
this.getContentPane().setLayout(new BoxLayout(this.getContentPane(),BoxLayout.Y_AXIS));
this.getContentPane().add(title);
this.getContentPane().add(this.panel);
this.setTitle("学生登记系统");
this.setSize(300, 300);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
new LoginPage();
}
}
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
public class LoginPage extends JFrame{
private static final long serialVersionUID = 1L;
public static final String INITIAL_VALUE = " ";
public static final String SUCCESS = " 登记学生张三成功 ";
public static final String FAILURE = "登记失败,请重新输出";
private JPanel panel;
private JLabel messageLabel;
public LoginPage(){
start();
}
public void start(){
JLabel title = new JLabel("学 生 登 记");
JLabel idLabel = new JLabel("学号: ");
JLabel nameLabel = new JLabel("名字: ");
JLabel genderLable = new JLabel("性别: ");
JTextField idField = new JTextField(10);
JTextField nameField = new JTextField(10);
JRadioButton maleButton = new JRadioButton("男");
JRadioButton femaleButton = new JRadioButton("女");
//把这两个按扭放到一个组中,实现单选
ButtonGroup group = new ButtonGroup();
group.add(maleButton);
group.add(femaleButton);
JButton confirmButton = new JButton("确定");
JButton resetButton = new JButton("重置");
confirmButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
//这里实现你登录的判断
JOptionPane.showMessageDialog(LoginPage.this, "你自已实现登录哦");
}
});
resetButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
messageLabel.setText(INITIAL_VALUE);
idField.setText("");
nameField.setText("");
group.clearSelection();
}
});
this.messageLabel = new JLabel(INITIAL_VALUE);
this.panel = new JPanel();
this.panel.setBorder(BorderFactory.createEtchedBorder());
//设置面板最大的大小
this.panel.setMaximumSize(new Dimension(180, 150));
this.panel.add(messageLabel);
this.panel.add(idLabel);
this.panel.add(idField);
this.panel.add(nameLabel);
this.panel.add(nameField);
this.panel.add(genderLable);
this.panel.add(maleButton);
this.panel.add(femaleButton);
this.panel.add(confirmButton);
this.panel.add(resetButton);
//设置布局为BoxLayout
this.getContentPane().setLayout(new BoxLayout(this.getContentPane(),BoxLayout.Y_AXIS));
this.getContentPane().add(title);
this.getContentPane().add(this.panel);
this.setTitle("学生登记系统");
this.setSize(300, 300);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
new LoginPage();
}
}
2016-06-12
展开全部
给100万、还要帮点好、捆绑好。。。。。。。。装好车。。。。。
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询