我主要负责的模块是:用户的登录检查,学生信息的修改和查找。
public class LoginCheck {
private final String name ;
private final String password ;
public LoginCheck(String name, String password){
this.name = name ;
this.password = password ;
}
public boolean validate(){
return("root".equals(name)&&"java".equals(password));
}
}
import javax.swing.*;
import java.awt.Menu;
import java.awt.event.ActionEvent;
public class Modify extends Menu{
private final JFrame jf=new JFrame("修改学生信息!");
private final JTextField jt5=new JTextField();
private final JButton bt1=new JButton("提交");
private final JButton bt2=new JButton("退出");
private int id;
private String na=null;
private String sq=null;
private float m,w,en,ever,su;
public Modify()throws Exception{
super();
JLabel jl0=new JLabel("请输入信息:");
JLabel jl1=new JLabel("对应学号:");
JTextField jt1=new JTextField();
JLabel jl2=new JLabel("姓 名:");
JTextField jt2=new JTextField();
JLabel jl3=new JLabel("数 学:");
JTextField jt3=new JTextField();
JLabel jl4=new JLabel("物 理:");
JTextField jt4=new JTextField();
JLabel jl5=new JLabel("英 语:");
JLabel xin=new JLabel("");
jl0.setBounds(10,10,120,30);
jl1.setBounds(10,50,60,30);
jt1.setBounds(80,50,180,30);
jl2.setBounds(10,90,60,30);
jt2.setBounds(80,90,180,30);
jl3.setBounds(10,130,60,30);
jt3.setBounds(80,130,180,30);
jl4.setBounds(10,170,60,30);
jt4.setBounds(80,170,180,30);
jl5.setBounds(10,210,60,30);
jt5.setBounds(80,210,180,30);
bt1.setBounds(20,250,60,30);
bt2.setBounds(90,250,60,30);
xin.setBounds(10,300,100,30);
jf.add(jl0);
jf.add(jl1);
jf.add(jt1);
jf.add(jl2);
jf.add(jt2);
jf.add(jl3);
jf.add(jt3);
jf.add(jl4);
jf.add(jt4);
jf.add(jl5);
jf.add(jt5);
jf.add(bt1);
jf.add(bt2);
jf.add(xin);
jf.setSize(400,400);
jf.setLocation(300,200);
jf.setVisible(true);
bt1.addActionListener((ActionEvent e)->{
if(e.getSource()==bt1){
if("".equals(jt1.getText().trim())|| "".equals(jt2.getText().trim())|| "".equals(jt3.getText().trim())
|| "".equals(jt4.getText().trim())|| "".equals(jt5.getText().trim())){
JOptionPane.showMessageDialog(null,"输入的信息不可以为空,请重新输入!","错误提示!",
JOptionPane.INFORMATION_MESSAGE);
f.dispose();
jf.dispose();
try{
new Modify();
}catch(Exception ex){
System.out.println("异常");
}
}
else if(Integer.parseInt(jt1.getText())<0||Float.parseFloat(jt3.getText())<0||Float.parseFloat(jt4.getText())<0||Float.parseFloat(jt5.getText())<0){
JOptionPane.showMessageDialog(null,"输入的信息不可以有负数,请重新输入!","错误提示!",
JOptionPane.INFORMATION_MESSAGE);
f.dispose();
jf.dispose();
try{
new Modify();
}catch(Exception ex){System.out.println("异常");}
}
else{
id=Integer.parseInt(jt1.getText().trim());
na=jt2.getText().trim();
m=Float.parseFloat(jt3.getText().trim());
w=Float.parseFloat(jt4.getText().trim());
en=Float.parseFloat(jt5.getText().trim());
su=m+w+en;
ever=toTwo((float)(su/3.0));
sq="update stu set name='"+na+"',math="+m+",wuli="+w+",english="+en+",everage="+ever+",sum="+su+" where id="+id;
try{
jf.dispose();
show(SQL,1,sq);
}catch(Exception ex){System.out.println("异常");}
}
}
}) ;
bt2.addActionListener((ActionEvent e)-> {
if (e.getSource() == bt2) {
jf.dispose();
}
});
}
}
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
public class Search extends Menu{
private final JFrame jf=new JFrame("查找学生信息!");
private final JButton jb=new JButton("查询");
private final JTextField jt=new JTextField();
private String s=null;
private String sq=null;
public Search() throws Exception{
super();
JLabel jl=new JLabel("请输入需要查询学生的学号或姓名!");
Font fo=new Font("Serief",Font.BOLD,12);
jl.setFont(fo);
jt.setBounds(15,15,150,30);
jb.setBounds(175,15,60,30);
jl.setBounds(10,80,180,30);
jf.add(jt);
jf.add(jb);
jf.add(jl);
jf.setSize(300,170);
jf.setLocation(300,250);
jf.setVisible(true);
jb.addActionListener((ActionEvent e)->{
if(e.getSource()==jb){
if("".equals(jt.getText().trim())){
JOptionPane.showMessageDialog(null,"输入的信息不可以为空,请重新输入!","错误提示!",
JOptionPane.INFORMATION_MESSAGE);
f.dispose();
jf.dispose();
try{
new Search();
}catch(Exception ex){
System.out.println("异常");
}
}
else{
s=jt.getText().trim();
try{
int t=Integer.parseInt(jt.getText().trim());
if(t<=0){
JOptionPane.showMessageDialog(null,"输入的学号不可以为0或负数,请重新输入!","错误提示!",
JOptionPane.INFORMATION_MESSAGE);
f.dispose();
jf.dispose();
try{
new Search();
}catch(Exception ex){System.out.println("异常");}
}else{
sq="select id,name,math,wuli,english,everage,sum from stu where id like '%"+t+"%'";
jf.dispose();
try{
show(sq,0," ");
}catch(Exception ex){System.out.println("异常");}
}
}catch(Exception ex){
sq="select id,name,math,wuli,english,everage,sum from stu where name like '%"+s+"%'";
jf.dispose();
try{
show(sq,0," ");
}catch(Exception ex1){System.out.println("异常");}
}
}
}
});
}
}



