这个题目不会做
顾念念吖?_1546068946 发表于2018-12-31 16:32
编写一个Swing程序,实现学生注册功能,要求有数组、字符串、循环、包装类、数字处理类;
这两个都不会。如果会的话可以尽快回复我么,特别感谢。
//package com.zzsyp.z$others;
/**
* 实现注册功能
*
* @author zzsyp
*/
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.Container;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class Demo17$exp extends JFrame{
//成员参数
Container ctn=null;
JLabel titleJL=null;
JLabel nameJL=null;
JLabel numbJL=null;
JLabel pwd1JL=null;
JLabel pwd2JL=null;
JTextField nameJT=null;
JTextField numbJT=null;
JPasswordField pwd1JT=null;
JPasswordField pwd2JT=null;
JButton submitBtn=null;
JButton display_echo_char=null;
public Demo17$exp() {
setTitle("学生系统注册界面");//设置标题
setBounds(500,260,350,400);//设置大小及坐标
setDefaultCloseOperation(EXIT_ON_CLOSE);//设置默认关闭方式
//初始化成员参数
ctn=getContentPane();
ctn.setLayout(null);
titleJL=new JLabel("注册");
titleJL.setFont(new Font("宋体",Font.BOLD,22));
titleJL.setBounds(150,15 ,100, 20);
nameJL=new JLabel("姓 名:");
Font forJLs=new Font("宋体",Font.PLAIN,15);
nameJL.setFont(forJLs);
nameJL.setBounds(50,60 ,100, 20);
numbJL=new JLabel("学 号:");
numbJL.setFont(forJLs);
numbJL.setBounds(50,105 ,100, 20);
pwd1JL=new JLabel("密 码:");
pwd1JL.setFont(forJLs);
pwd1JL.setBounds(50,150 ,100, 20);
pwd2JL=new JLabel("确认密码:");
pwd2JL.setFont(forJLs);
pwd2JL.setBounds(50,195 ,100, 20);
nameJT=new JTextField();
nameJT.setBounds(120,60,150, 20);
numbJT=new JTextField();
numbJT.setBounds(120,105,150, 20);
pwd1JT=new JPasswordField();
pwd1JT.setBounds(120,150,150, 20);
pwd2JT=new JPasswordField();
pwd2JT.setBounds(120,195,150, 20);
submitBtn=new JButton("提交");
submitBtn.setBounds(210,240,70,30);
display_echo_char=new JButton("N");
display_echo_char.setBounds(270,195,20,20);
ctn.add(titleJL);
ctn.add(nameJL);
ctn.add(numbJL);
ctn.add(pwd1JL);
ctn.add(pwd2JL);
ctn.add(nameJT);
ctn.add(numbJT);
ctn.add(pwd1JT);
ctn.add(pwd2JT);
ctn.add(submitBtn);
ctn.add(display_echo_char);
ctn.validate();
addListeners();
}
public void addListeners() {
display_echo_char.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
switch(display_echo_char.getText()) {
case "Y":
display_echo_char.setText("N");
pwd1JT.setEchoChar('*');pwd2JT.setEchoChar('*');
break;
case "N":
display_echo_char.setText("Y");
pwd1JT.setEchoChar('\0');pwd2JT.setEchoChar('\0');
break;
}
}
});
submitBtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if(isNull()) {
JOptionPane.showMessageDialog(Demo17$exp.this,"有值未输入!");
}
else if(!(pwd1JT.getText().equals(pwd2JT.getText()))) {
JOptionPane.showMessageDialog(Demo17$exp.this,"密码不一致!");
}
else
{
JOptionPane.showMessageDialog(Demo17$exp.this,"注册成功!"+
"\n您的信息:\n姓名:"+nameJT.getText()+
"\n学号:"+numbJT.getText()+
"\n密码:"+pwd1JT.getText()
);
}
}
});
}
public boolean isNull() {
return nameJT.getText().equals("")||numbJT.getText().equals("")
||pwd1JT.getText().equals("")
||pwd2JT.getText().equals("");
}
public static void main(String[] args) {
new Demo17$exp().setVisible(true);
}
}
mrkj_0257 发表于2018-12-31 20:17
//package com.zzsyp.z$others;
/**
* 实现注册功能
*
* @author zzsyp
*/
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.Container;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class Demo17$exp extends JFrame{
//成员参数
Container ctn=null;
JLabel titleJL=null;
JLabel nameJL=null;
JLabel numbJL=null;
JLabel pwd1JL=null;
JLabel pwd2JL=null;
JTextField nameJT=null;
JTextField numbJT=null;
JPasswordField pwd1JT=null;
JPasswordField pwd2JT=null;
JButton submitBtn=null;
JButton display_echo_char=null;
public Demo17$exp() {
setTitle("学生系统注册界面");//设置标题
setBounds(500,260,350,400);//设置大小及坐标
setDefaultCloseOperation(EXIT_ON_CLOSE);//设置默认关闭方式
//初始化成员参数
ctn=getContentPane();
ctn.setLayout(null);
titleJL=new JLabel("注册");
titleJL.setFont(new Font("宋体",Font.BOLD,22));
titleJL.setBounds(150,15 ,100, 20);
nameJL=new JLabel("姓 名:");
Font forJLs=new Font("宋体",Font.PLAIN,15);
nameJL.setFont(forJLs);
nameJL.setBounds(50,60 ,100, 20);
numbJL=new JLabel("学 号:");
numbJL.setFont(forJLs);
numbJL.setBounds(50,105 ,100, 20);
pwd1JL=new JLabel("密 码:");
pwd1JL.setFont(forJLs);
pwd1JL.setBounds(50,150 ,100, 20);
pwd2JL=new JLabel("确认密码:");
pwd2JL.setFont(forJLs);
pwd2JL.setBounds(50,195 ,100, 20);
nameJT=new JTextField();
nameJT.setBounds(120,60,150, 20);
numbJT=new JTextField();
numbJT.setBounds(120,105,150, 20);
pwd1JT=new JPasswordField();
pwd1JT.setBounds(120,150,150, 20);
pwd2JT=new JPasswordField();
pwd2JT.setBounds(120,195,150, 20);
submitBtn=new JButton("提交");
submitBtn.setBounds(210,240,70,30);
display_echo_char=new JButton("N");
display_echo_char.setBounds(270,195,20,20);
ctn.add(titleJL);
ctn.add(nameJL);
ctn.add(numbJL);
ctn.add(pwd1JL);
ctn.add(pwd2JL);
ctn.add(nameJT);
ctn.add(numbJT);
ctn.add(pwd1JT);
ctn.add(pwd2JT);
ctn.add(submitBtn);
ctn.add(display_echo_char);
ctn.validate();
addListeners();
}
public void addListeners() {
display_echo_char.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
switch(display_echo_char.getText()) {
case "Y":
display_echo_char.setText("N");
pwd1JT.setEchoChar('*');pwd2JT.setEchoChar('*');
break;
case "N":
display_echo_char.setText("Y");
pwd1JT.setEchoChar('\0');pwd2JT.setEchoChar('\0');
break;
}
}
});
submitBtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if(isNull()) {
JOptionPane.showMessageDialog(Demo17$exp.this,"有值未输入!");
}
else if(!(pwd1JT.getText().equals(pwd2JT.getText()))) {
JOptionPane.showMessageDialog(Demo17$exp.this,"密码不一致!");
}
else
{
JOptionPane.showMessageDialog(Demo17$exp.this,"注册成功!"+
"\n您的信息:\n姓名:"+nameJT.getText()+
"\n学号:"+numbJT.getText()+
"\n密码:"+pwd1JT.getText()
);
}
}
});
}
public boolean isNull() {
return nameJT.getText().equals("")||numbJT.getText().equals("")
||pwd1JT.getText().equals("")
||pwd2JT.getText().equals("");
}
public static void main(String[] args) {
new Demo17$exp().setVisible(true);
}
}
谢谢你