📄 ydq.java
字号:
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import javax.swing.JOptionPane;
import javax.swing.JColorChooser;
import java.io.*;
import java.net.*;
import javax.swing.*;
class denglu extends Frame implements ActionListener
{
TextField yonghuming,mima;
Choice choice;
Button button;
String xuehao;
Color color=Color.cyan;
Label label1,label2,label3;
Connection con=null;
Statement sql=null;
ResultSet rs=null;
Box basebox,boxh1,boxh2,boxh3;
denglu()
{ super("登陆界面");
setSize(200,250);
setBounds(300,300,250,130);
setVisible(true);
setBackground(Color.cyan);
yonghuming=new TextField(10);
mima=new TextField(10);
mima.setEchoChar('*');
label1=new Label("用户名");
label2=new Label("密码");
label3=new Label("身份选择");
button=new Button("登陆");
button.setBackground(Color.cyan);
choice=new Choice();
choice.add("用户");
choice.add("管理员");
basebox=Box.createHorizontalBox();
boxh1=Box.createVerticalBox();
boxh2=Box.createVerticalBox();
boxh3=Box.createVerticalBox();
boxh1.add(label1);
boxh1.add(Box.createVerticalStrut(4));
boxh2.add(yonghuming);
boxh1.add(label2);
boxh1.add(Box.createVerticalStrut(4));
boxh2.add(mima);
boxh1.add(label3);
boxh1.add(Box.createVerticalStrut(50));
boxh2.add(choice);
boxh2.add(Box.createVerticalStrut(50));
boxh3.add(Box.createVerticalStrut(70));
boxh3.add(button);
basebox.add(boxh1);
basebox.add(boxh3);
basebox.add(boxh2);
add(basebox);
validate();
addWindowListener (new WindowAdapter()
{public void windowClosing(WindowEvent e)
{System.exit(0);}
}
);
button.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{ if(e.getSource()==button)
{
try
{yanzheng();
}
catch(SQLException e1) {}
}
}
public void yanzheng() throws SQLException
{ try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}
catch(ClassNotFoundException e2) {}
con=DriverManager.getConnection("jdbc:odbc:qqq","","");
sql=con.createStatement();
String s1="'"+yonghuming.getText().trim()+"'";
xuehao=s1;
rs=sql.executeQuery("select * from denglu where 用户名="+s1);
while(rs.next())
{ String q1=rs.getString("用户名");
String q2=rs.getString("密码");
String q3=yonghuming.getText();
String q4=mima.getText();
String q5=rs.getString("身份");
String q6=choice.getSelectedItem();
if((q1.equals(q3))&&!(q2.equals(q4)))
{JOptionPane.showMessageDialog(this,"密码不正确","提示",JOptionPane.WARNING_MESSAGE);
con.close();
return;
}
else if(!(q5.equals(q6)))
{JOptionPane.showMessageDialog(this,"身份选择错误","提示",JOptionPane.WARNING_MESSAGE);
return;
}
else if((q1.equals(q3))&&(q2.equals(q4))&&q5.equals("用户"))
{ dispose();
yonghu gg=new yonghu();
gg.setVisible(true);
}
else if((q1.equals(q3))&&(q2.equals(q4))&&q5.equals("管理员"))
{dispose();
admin dd=new admin();
}
con.close();
return;
}
JOptionPane.showMessageDialog(this,"该用户不存在","警告",JOptionPane.WARNING_MESSAGE);
con.close();
}
//普通用户界面 (包含在denglu类里面)
class yonghu extends Frame implements ActionListener
{ MenuBar menubar;
Menu menu1,menu2,menu3,menu4;
MenuItem item1,item2,item3,item4,item5,item6,item7,item8,item9,item10,item11,item12;
Connection con=null;
Statement sql=null;
ResultSet rs=null;
yonghu()
{ super("用户界面");
setBackground(Color.cyan);
setSize(400,400);
setBounds(200,200,500,300);
setVisible(false);
menubar=new MenuBar();
menu1=new Menu("信息管理");
menu2=new Menu("选课管理");
menu3=new Menu("教师评教");
menu4=new Menu("常用小功能");
item1=new MenuItem("帐号信息管理");
item2=new MenuItem("基本信息管理");
item3=new MenuItem("退出");
item4=new MenuItem("设置背景颜色");
item5=new MenuItem("选课");
item6=new MenuItem("查询选课信息");
item7=new MenuItem("成绩查询");
item8=new MenuItem("评 教");
item9=new MenuItem("同月同日生");
item10=new MenuItem("程序源代码");
item11=new MenuItem("主机IP");
item12=new MenuItem("开始运行");
menu1.add(item1);
menu1.addSeparator();
menu1.add(item2);
menu1.addSeparator();
menu1.add(item4);
menu1.addSeparator();
menu1.add(item3);
menu2.add(item5);
menu2.addSeparator();
menu2.add(item6);
menu2.addSeparator();
menu2.add(item7);
menu3.add(item8);
menu4.add(item9);
menu4.addSeparator();
menu4.add(item10);
menu4.addSeparator();
menu4.add(item11);
menu4.addSeparator();
menu4.add(item12);
menubar.add(menu1);
menubar.add(menu2);
menubar.add(menu3);
menubar.add(menu4);
setMenuBar(menubar);
item1.addActionListener(this);
item2.addActionListener(this);
item3.addActionListener(this);
item4.addActionListener(this);
item5.addActionListener(this);
item6.addActionListener(this);
item7.addActionListener(this);
item8.addActionListener(this);
item9.addActionListener(this);
item10.addActionListener(this);
item11.addActionListener(this);
item12.addActionListener(this);
addWindowListener (new WindowAdapter()
{public void windowClosing(WindowEvent e)
{System.exit(0);}
}
);
}
public void actionPerformed(ActionEvent e)
{if(e.getSource()==item1)
{
yonghuzhanghaoxinxi jjj=new yonghuzhanghaoxinxi();
jjj.setVisible(true);
}
if(e.getSource()==item2)
{
yonghujibenxinxi kkkkk=new yonghujibenxinxi();
kkkkk.setVisible(true);
}
else if(e.getSource()==item3)
{ System.exit(0);
}
else if(e.getSource()==item4)
{color=JColorChooser.showDialog(this,"杨德青",getBackground());
setBackground(color);
}
else if(e.getSource()==item5)
{xuanke ll=new xuanke();
ll.setVisible(true);
}
else if(e.getSource()==item6)
{chaxunxuankexinxi qa=new chaxunxuankexinxi();
qa.setVisible(true);
}
else if(e.getSource()==item7)
{chengjichaxun jjjj=new chengjichaxun();
jjjj.setVisible(true);
}
else if(e.getSource()==item8)
{pingjiao mm=new pingjiao();
mm.setVisible(true);
}
else if(e.getSource()==item9)
{tongyuetongri jj=new tongyuetongri();
jj.setVisible(true);
}
else if(e.getSource()==item10)
{chaxunyuandaima gg=new chaxunyuandaima();
gg.setVisible(true);
}
else if(e.getSource()==item11)
{getip qg=new getip();
qg.setVisible(true);
}
else if(e.getSource()==item12)
{kaishiyunxing ad=new kaishiyunxing();
ad.setVisible(true);
}
}
class yonghuzhanghaoxinxi extends Frame implements ActionListener
{ Label label1,label2,label3;
TextField text1,text2,text3;
Button button1,button2;
Connection con=null;
Statement sql=null;
ResultSet rs=null;
yonghuzhanghaoxinxi()
{super("用户帐号信息管理页面");
setBackground(color);
setSize(200,300);
setBounds(200,200,400,300);
setVisible(false);
label1=new Label("用户名");
label2=new Label("密码");
label3=new Label("更改密码");
text1=new TextField(10);
text2=new TextField(20);
text3=new TextField(20);
text1.setText(xuehao.substring(1,8));
button1=new Button("查询密码");
button2=new Button("更改密码");
button1.addActionListener(this);
button2.addActionListener(this);
Panel p1=new Panel();
Panel p2=new Panel();
Panel p3=new Panel();
Panel p4=new Panel();
Panel p5=new Panel();
p1.add(label1,"West");
p1.add(text1,"Center");
p2.add(label2,"West");
p2.add(text2,"Center");
p3.add(label3,"West");
p3.add(text3,"Center");
p4.add(button1,"West");
p4.add(button2,"Center");
p5.add(p1,"North");
p5.add(p2,"Center");
p5.add(p3,"South");
p5.add(p4,"East");
add(p5);
addWindowListener (new WindowAdapter()
{public void windowClosing(WindowEvent e)
{dispose();}
}
);
}
public void actionPerformed(ActionEvent e)
{if(e.getSource()==button1)
{ try
{chaxunmima();
}
catch(Exception ee) {}
}
else if(e.getSource()==button2)
{ try
{genggaimima();
}
catch(Exception ee) {}
}
}
public void chaxunmima() throws SQLException
{
try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}
catch(ClassNotFoundException e4) {}
con=DriverManager.getConnection("jdbc:odbc:qqq","","");
sql=con.createStatement();
rs=sql.executeQuery("select * from denglu where 用户名="+xuehao);
while(rs.next())
{ String qq=rs.getString("密码");
text2.setText(qq);
con.close();
return;
}
JOptionPane.showMessageDialog(this,"该用户不存在","提示",JOptionPane.WARNING_MESSAGE);
}
public void genggaimima() throws SQLException
{ try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}
catch(ClassNotFoundException e7) {}
con=DriverManager.getConnection("jdbc:odbc:qqq","","");
sql=con.createStatement();
String q1=text2.getText();
String q2=text3.getText();
String q3="'"+text2.getText().trim()+"'";
if(!(q1.equals(q2)))
{JOptionPane.showMessageDialog(this,"两次输入的密码不一样,请重新输入","提示",JOptionPane.WARNING_MESSAGE);
return;
}
sql.executeUpdate("update denglu set 密码="+q3+" where 用户名="+xuehao);
JOptionPane.showMessageDialog(this,"修改密码成功","提示",JOptionPane.WARNING_MESSAGE);
con.close();
}
}
class yonghujibenxinxi extends Frame implements ActionListener
{ Label label1,label2,label3,label4,label5,label6,label7;
TextField text1,text2,text3,text4,text5,text6,text7;
Button button1,button2,button3;
Connection con=null;
Statement sql=null;
ResultSet rs=null;
yonghujibenxinxi()
{super("用户基本信息管理页面");
setBackground(color);
setSize(400,400);
setBounds(200,200,600,300);
setVisible(false);
label1=new Label("姓名");
label2=new Label("性别");
label3=new Label("出生日期");
label4=new Label("家庭住址");
label5=new Label("院系");
label6=new Label("班级");
label7=new Label("爱好");
text1=new TextField(6);
text2=new TextField(2);
text3=new TextField(10);
text4=new TextField(20);
text5=new TextField(10);
text6=new TextField(10);
text7=new TextField(10);
button1=new Button("查询");
button2=new Button("更改");
button3=new Button("第一次填写信息");
button1.addActionListener(this);
button2.addActionListener(this);
button3.addActionListener(this);
Panel p1=new Panel();
Panel p2=new Panel();
Panel p3=new Panel();
Panel p4=new Panel();
Panel p5=new Panel();
Panel p6=new Panel();
Panel p7=new Panel();
Panel p8=new Panel();
Panel p9=new Panel();
Panel p10=new Panel();
Panel p11=new Panel();
Panel p12=new Panel();
p1.add(label1,"West");
p1.add(text1,"Center");
p2.add(label2,"West");
p2.add(text2,"Center");
p3.add(label3,"West");
p3.add(text3,"Center");
p4.add(label4,"West");
p4.add(text4,"Center");
p5.add(label5,"West");
p5.add(text5,"Center");
p6.add(label6,"East");
p6.add(text6,"South");
p7.add(label7,"West");
p7.add(text7,"Center");
p8.add(button3,"West");
p8.add(button1,"Center");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -