2020-11-27

Java 制作一个注册窗口,点击注册按钮然后跳转到登入窗口。
注册窗口,当账号和密码一个为空时弹出请注册窗口
当注册成功后就会进入登入页面,输入的密码和账号正确会弹出登入成功
代码如下:
注册窗口:
package shiyan3;import java.awt.event.;import javax.swing.;import java.awt.*;class Data{ static String uname; static String upass;}public class Zhuceck extends JFrame{ Box boxH1,boxH2,boxH3,boxV; JCheckBox checkBox1,checkBox2,checkBox3; JRadioButton radioM,radioF; JTextField jt1,jt2; JComboBox comBox; JButton button; JTextArea text; public Zhuceck() { setLayout(new java.awt.FlowLayout()); init(); setVisible(true); setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); } void init() { setLayout(new FlowLayout()); boxH1=Box.createHorizontalBox(); boxH1.add(new JLabel(“用户名:”)); jt1=new JTextField(14); boxH1.add(jt1); boxH1.add(new JLabel(“密码:”)); jt2=new JTextField(14); boxH1.add(jt2); add(boxH1); boxH2=Box.createHorizontalBox(); boxH2.add(new JLabel(“性别:”)); radioM=new JRadioButton(“男”); radioF=new JRadioButton(“女”); boxH2.add(radioM);boxH2.add(radioF); boxH2.add(new JLabel(" 爱好:")); checkBox1=new JCheckBox(“音乐”); checkBox2=new JCheckBox(“国内旅游”);
checkBox3=new JCheckBox(“阅读”); boxH2.add(checkBox1);boxH2.add(checkBox2);boxH2.add(checkBox3);add(boxH2); comBox=new JComboBox(); boxH3=Box.createHorizontalBox(); boxV=Box.createVerticalBox(); boxH3.add(new JLabel(“职业:”)); comBox.addItem(“学生”); comBox.addItem(“老师”); boxV.add(Box.createVerticalStrut(75)); boxV.add(comBox); boxV.add(Box.createVerticalStrut(75)); boxH3.add(boxV); boxH3.add(new JLabel(“Note:”)); boxH3.add(new JTextArea(10,12)); button=new JButton(“register”); boxH3.add(button); add(boxH3); button.addActionListener(new ActionListener() { private Window oldFrame; @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub Data.uname=jt1.getText(); Data.upass=jt2.getText(); if(Data.uname.equals("") || Data.upass.equals("")) JOptionPane.showMessageDialog(jt2, “请注册”, “注册”,JOptionPane.INFORMATION_MESSAGE ); else { setVisible(false); Dengruck dr=new Dengruck();} } }); } public static void main(String args[]) { Zhuceck zh = new Zhuceck(); zh.setBounds(100, 100, 400, 360); zh.setTitle(“注册窗口”); }}

登入窗口:
package shiyan3;import java.awt.event.;import javax.swing.;import java.awt.*;public class Dengruck extends JFrame{ Box boxH1,boxH2; Box boxVOne,boxVTwo; JButton button; JTextField jt3,jt4; String password; String name; public Dengruck() { setLayout(new java.awt.FlowLayout()); init(); setBounds(100,100,260,200); setTitle(“登入窗口”); setVisible(true); setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); } void init() { boxH1=Box.createHorizontalBox(); boxH2=Box.createHorizontalBox(); boxVOne=Box.createVerticalBox(); boxVTwo=Box.createVerticalBox(); boxVOne.add(new JLabel(“用户名:”)); boxVOne.add(new JLabel(“密码:”)); jt3=new JTextField(15); boxVTwo.add(jt3); jt4=new JTextField(15); boxVTwo.add(jt4); boxH1.add(boxVOne); boxH1.add(Box.createHorizontalStrut(10)); boxH1.add(boxVTwo); add(boxH1); boxH2.add(Box.createHorizontalStrut(10)); button=new JButton(“login”); boxH2.add(button); add(boxH2); button.addActionListener(new ActionListener() { @Override public void actactionPerformed(ActionEvent e) { // TODO Auto-generated method stub String name=jt3.getText(); String pass=jt4.getText(); if(name.equals(Data.uname)&&pass.equals(Data.upass)) JOptionPane.showMessageDialog(jt3, “登入成功”, “登入”,JOptionPane.INFORMATION_MESSAGE ); else JOptionPane.showMessageDialog(jt3, “登入失败”,“重新登入”,JOptionPane.INFORMATION_MESSAGE ); } }); } }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值