学生成绩管理系统java结业项目

package model;


/**
 * 学生类
 * 
 * @author Administrator
 *
 */
public class Student {


private String id;
private String name;
private String sex;
private double yw;
private double sx;
private double wy;
private double zf;
private double pj;
private String pf;


public String getId() {
return id;
}


public void setId(String id) {
this.id = id;
}


public String getName() {
return name;
}


public void setName(String name) {
this.name = name;
}


public String getSex() {
return sex;
}


public void setSex(String sex) {
this.sex = sex;
}


public double getYw() {
return yw;
}


public void setYw(double yw) {
this.yw = yw;
}


public double getSx() {
return sx;
}


public void setSx(double sx) {
this.sx = sx;
}


public double getWy() {
return wy;
}


public void setWy(double wy) {
this.wy = wy;
}


public double getZf() {
return zf;
}


public void setZf(double zf) {
this.zf = zf;
}


public double getPj() {
return pj;
}


public void setPj(double pj) {
this.pj = pj;
}


public String getPf() {
return pf;
}


public void setPf(String pf) {
this.pf = pf;
}


}

-------------------------------------------------------------------------------------------------------------------------------------------------------------

package model;


/**
 * 教师类
 * 
 * @author Administrator
 *
 */
public class Teacher {


private int id;
private String name;
private String password;
private int power;


public Teacher() {

}


public Teacher(String name, String password, int power) {
super();
this.name = name;
this.password = password;
this.power = power;
}






public int getId() {
return id;
}


public void setId(int id) {
this.id = id;
}


public String getName() {
return name;
}


public void setName(String name) {
this.name = name;
}


public String getPassword() {
return password;
}


public void setPassword(String password) {
this.password = password;
}


public int getPower() {
return power;
}


public void setPower(int power) {
this.power = power;
}


}

====================================================================================================

package db;



import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;


/**
 * 连接数据库类
 * 
 * @author Administrator
 *
 */
public class DBUtil {
// 连接数据库信息
private static final String URL = "jdbc:mysql://127.0.0.1:3306/stumanager";
private static final String USER = "root";
private static final String PASSWORD = "root";
private static Connection conn = null;


static {
try {
// 加载数据库
Class.forName("com.mysql.jdbc.Driver");
// 获得数据库连接
conn = DriverManager.getConnection(URL, USER, PASSWORD);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
}


// 获得数据库连接的Connection方法
public static Connection getConn() {
return conn;
}


}

============================================================================================================

package dao;


import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;


import db.DBUtil;
import model.Student;


/**
 * 学生信息增删改查
 * @author Administrator
 *
 */
public class StuDao {

private Connection conn = DBUtil.getConn();
// private Student stu ; 
// private List<Student> list;
// private PreparedStatement ps;
// private ResultSet rs;


//添加
public void addStudent(){

}

//修改
public void updateStudent(){

}

//删除
public boolean deleteStudent(String name){
String sql = "delete from student where name=?";
boolean b = true;
try {
PreparedStatement ps = conn.prepareStatement(sql);
ps.setString(1, name);
b = ps.execute();
} catch (SQLException e) {
e.printStackTrace();
}
return b;
}

//查询单个学生
public Student queryStudent(){
return null;
}

//查询所有学生
public List<Student> getStudents(){
List<Student> list = null;
try {
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("select * from student");
list = new ArrayList<Student>();
Student stu = null;
while(rs.next()){
stu = new Student();
stu.setId(rs.getString("id"));
stu.setName(rs.getString("name"));
stu.setSex(rs.getString("sex"));
stu.setYw(rs.getDouble("yw"));
stu.setSx(rs.getDouble("sx"));
stu.setWy(rs.getDouble("wy"));
stu.setZf(rs.getDouble("zf"));
stu.setPj(rs.getDouble("pj"));
stu.setPf(rs.getString("pf"));
list.add(stu);
}
} catch (SQLException e) {
e.printStackTrace();
}
return list;
}

//根据学号查询学生
public Student getStudent(String id){
String sql = "select * from student where id=?";
Student stu = null;
try {
PreparedStatement ps = conn.prepareStatement(sql);
ps.setString(1, id);
ResultSet rs = ps.executeQuery();
while(rs.next()){
stu = new Student();
stu.setId(rs.getString("id"));
stu.setName(rs.getString("name"));
stu.setSex(rs.getString("sex"));
stu.setYw(rs.getDouble("yw"));
stu.setSx(rs.getDouble("sx"));
stu.setWy(rs.getDouble("wy"));
stu.setZf(rs.getDouble("zf"));
stu.setPj(rs.getDouble("pj"));
stu.setPf(rs.getString("pf"));
}
} catch (SQLException e) {
e.printStackTrace();
}
return stu;
}

//根据姓名查询
public Student findStudent(String name){
String sql = "select * from student where name=?";
Student stu = null;
try {
PreparedStatement ps = conn.prepareStatement(sql);
ps.setString(1, name);
ResultSet rs = ps.executeQuery();
while(rs.next()){
stu = new Student();
stu.setId(rs.getString("id"));
stu.setName(rs.getString("name"));
stu.setSex(rs.getString("sex"));
stu.setYw(rs.getDouble("yw"));
stu.setSx(rs.getDouble("sx"));
stu.setWy(rs.getDouble("wy"));
stu.setZf(rs.getDouble("zf"));
stu.setPj(rs.getDouble("pj"));
stu.setPf(rs.getString("pf"));
}
} catch (SQLException e) {
e.printStackTrace();
}
return stu;
}

}

--------------------------------------------------------------------------------------------------------------------------------

package dao;


import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;


import db.DBUtil;
import model.Teacher;


/**
 * 教师信息增删改查
 * @author Administrator
 *
 */
public class TeaDao {

private Connection conn = DBUtil.getConn();//获得数据库连接
private PreparedStatement ps;//准备声明
private ResultSet rs;//查询数据库返回的ResultSet集合


//添加
public boolean addTeacher(Teacher t){
String sql = "insert into teacher (name,password,power) values (?,?,?)";
boolean result = true;
try {
ps = conn.prepareStatement(sql);
ps.setString(1, t.getName());
ps.setString(2, t.getPassword());
ps.setInt(3, t.getPower());
result = ps.execute();
} catch (SQLException e) {
e.printStackTrace();
}
return result;
}

//修改
public void updateTeacher(){

}

//删除
public void deleteTeacher(){

}

//查询
public Teacher queryTeacher(String name){
String sql = "select * from teacher where name=?";
Teacher t = null;
try {
ps = conn.prepareStatement(sql);
ps.setString(1, name);
rs = ps.executeQuery();

while(rs.next()){
t = new Teacher();
t.setId(rs.getInt("id"));
t.setName(rs.getString("name"));
t.setPassword(rs.getString("password"));
t.setPower(rs.getInt("power"));
}
} catch (SQLException e) {
e.printStackTrace();
}

return t;
}
}

==========================================================================================================

package control;


import java.util.List;


import dao.StuDao;
import model.Student;


public class StuControl {


private static StuDao sd ;
private static StuControl sc = null;
private StuControl(){
this.sd = new StuDao();
}

public static StuControl getInstance(){
if(sc == null){
sc = new StuControl();
}
return sc;
}



//查询所有学生
public List<Student> getAllStu(){
return sd.getStudents();
}

//根据学号查询学生
public Student getStuForID(String id){
return sd.getStudent(id);
}

//根据姓名查询学生
public Student getStuForName(String name){
return sd.findStudent(name);
}

//删除学生
public boolean delStud(String name){
return sd.deleteStudent(name);
}

}

---------------------------------------------------------------------------------------------------------------------------------------------

package control;


import dao.TeaDao;
import model.Teacher;


public class TeaControl {

private TeaDao td;//声明教师的DAO对象
private Teacher t;//声明教师类对象


public TeaControl(){
this.td = new TeaDao();
this.t = new Teacher();
}

//教师登录
public String login(String name,String password){
t = td.queryTeacher(name);
if(t!=null){
if(t.getPassword().equals(password)){
return "登录成功";
}else{
return "密码错误";
}
}else{
return "用户不存在";
}
}

//教师注册
public String reg(Teacher t){
boolean result= td.addTeacher(t);
if(!result){
return "注册成功";
}else{
return "注册失败";
}
}

//查询老师信息
public Teacher findTes(String name){
return td.queryTeacher(name);
}

}

=====================================================================================================

package view;


import java.awt.BorderLayout;
import java.awt.EventQueue;


import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;


import util.GetNumber;


import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JRadioButton;
import java.awt.Font;
import javax.swing.JButton;


import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;


public class ADDStudent extends JFrame {


private JPanel contentPane;
private JTextField textField;
private JTextField textField_1;
private JTextField textField_2;
private JTextField textField_4;
private JTextField textField_5;
private JTextField textField_6;
private JTextField textField_7;
private JTextField textField_8;
private JRadioButton radioButton;
private JRadioButton radioButton_1;


/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
ADDStudent frame = new ADDStudent();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}


/**
* Create the frame.
*/
public ADDStudent() {
setTitle("\u6DFB\u52A0\u5B66\u751F");
setResizable(false);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 352, 580);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);

//学号标签
JLabel label = new JLabel("\u5B66  \u53F7\uFF1A");
label.setBounds(47, 35, 54, 15);
contentPane.add(label);

//姓名标签
JLabel label_1 = new JLabel("\u59D3  \u540D\uFF1A");
label_1.setBounds(47, 85, 54, 15);
contentPane.add(label_1);

//性别标签
JLabel label_2 = new JLabel("\u6027  \u522B\uFF1A");
label_2.setBounds(47, 135, 54, 15);
contentPane.add(label_2);

//语文标签
JLabel label_3 = new JLabel("\u8BED  \u6587\uFF1A");
label_3.setBounds(47, 185, 54, 15);
contentPane.add(label_3);

//数学标签
JLabel label_4 = new JLabel("\u6570  \u5B66\uFF1A");
label_4.setBounds(47, 235, 54, 15);
contentPane.add(label_4);

//外语标签
JLabel label_5 = new JLabel("\u5916  \u8BED\uFF1A");
label_5.setBounds(47, 285, 54, 15);
contentPane.add(label_5);

//总分标签
JLabel label_6 = new JLabel("\u603B  \u5206\uFF1A");
label_6.setBounds(47, 335, 54, 15);
contentPane.add(label_6);

//平均分标签
JLabel label_7 = new JLabel("\u5E73\u5747\u5206\uFF1A");
label_7.setBounds(47, 385, 54, 15);
contentPane.add(label_7);

//评级标签
JLabel label_8 = new JLabel("\u8BC4  \u7EA7\uFF1A");
label_8.setBounds(47, 435, 54, 15);
contentPane.add(label_8);

//学号文本框
textField = new JTextField();
textField.setText(GetNumber.getNum());
textField.setEnabled(false);
textField.setBounds(111, 32, 169, 21);
contentPane.add(textField);
textField.setColumns(10);

//姓名文本框
textField_1 = new JTextField();
textField_1.setBounds(111, 85, 169, 21);
contentPane.add(textField_1);
textField_1.setColumns(10);

//性别男
radioButton = new JRadioButton("\u7537");
radioButton.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent arg0) {
if(radioButton.isSelected()){
radioButton_1.setSelected(false);
}

}
});
radioButton.setBounds(111, 135, 69, 23);
contentPane.add(radioButton);

//性别女
radioButton_1 = new JRadioButton("\u5973");
radioButton_1.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent e) {
if(radioButton_1.isSelected()){
radioButton.setSelected(false);
}

}
});
radioButton_1.setBounds(182, 135, 121, 23);
contentPane.add(radioButton_1);

//语文输入框
textField_2 = new JTextField();
textField_2.addFocusListener(new FocusAdapter() {
@Override
public void focusLost(FocusEvent e) {
yanzheng(textField_2);
}
});
textField_2.addKeyListener(new KeyAdapter() {
@Override
public void keyTyped(KeyEvent e) {
int key = e.getKeyChar();
if(key >= KeyEvent.VK_0 && key <= KeyEvent.VK_9){

}else{
e.consume();
}
}
});
textField_2.setBounds(111, 185, 66, 21);
contentPane.add(textField_2);
textField_2.setColumns(10);

//“分”字标签
JLabel label_9 = new JLabel("\u5206");
label_9.setFont(new Font("宋体", Font.PLAIN, 13));
label_9.setBounds(182, 187, 54, 15);
contentPane.add(label_9);

//数学输入框
textField_4 = new JTextField();
textField_4.addFocusListener(new FocusAdapter() {
@Override
public void focusLost(FocusEvent e) {
yanzheng(textField_4);
}
});
textField_4.addKeyListener(new KeyAdapter() {
@Override
public void keyTyped(KeyEvent e) {
int key = e.getKeyChar();
if(key >= KeyEvent.VK_0 && key <= KeyEvent.VK_9){

}else{
e.consume();
}
}
});
textField_4.setColumns(10);
textField_4.setBounds(111, 235, 66, 21);
contentPane.add(textField_4);

//外语输入框
textField_5 = new JTextField();
textField_5.addFocusListener(new FocusAdapter() {
@Override
public void focusLost(FocusEvent e) {
yanzheng(textField_5);
}
});
textField_5.addKeyListener(new KeyAdapter() {
@Override
public void keyTyped(KeyEvent e) {
int key = e.getKeyChar();
if(key >= KeyEvent.VK_0 && key <= KeyEvent.VK_9){

}else{
e.consume();
}
}
});
textField_5.setColumns(10);
textField_5.setBounds(111, 285, 66, 21);
contentPane.add(textField_5);

//总分输入框
textField_6 = new JTextField();
textField_6.setEnabled(false);
textField_6.setColumns(10);
textField_6.setBounds(111, 335, 66, 21);
contentPane.add(textField_6);

//平均分输入框
textField_7 = new JTextField();
textField_7.setEnabled(false);
textField_7.setColumns(10);
textField_7.setBounds(111, 385, 66, 21);
contentPane.add(textField_7);

//评级输入框
textField_8 = new JTextField();
textField_8.setEnabled(false);
textField_8.setColumns(10);
textField_8.setBounds(111, 435, 66, 21);
contentPane.add(textField_8);

//“分”字标签
JLabel label_10 = new JLabel("\u5206");
label_10.setFont(new Font("宋体", Font.PLAIN, 13));
label_10.setBounds(182, 238, 54, 15);
contentPane.add(label_10);

//“分”字标签
JLabel label_11 = new JLabel("\u5206");
label_11.setFont(new Font("宋体", Font.PLAIN, 13));
label_11.setBounds(182, 288, 54, 15);
contentPane.add(label_11);

//“分”字标签
JLabel label_12 = new JLabel("\u5206");
label_12.setFont(new Font("宋体", Font.PLAIN, 13));
label_12.setBounds(182, 338, 54, 15);
contentPane.add(label_12);

//“分”字标签
JLabel label_13 = new JLabel("\u5206");
label_13.setFont(new Font("宋体", Font.PLAIN, 13));
label_13.setBounds(182, 388, 54, 15);
contentPane.add(label_13);

//“分”字标签
JLabel label_14 = new JLabel("\u5206");
label_14.setFont(new Font("宋体", Font.PLAIN, 13));
label_14.setBounds(182, 438, 54, 15);
contentPane.add(label_14);

//提交按钮
JButton button = new JButton("\u63D0\u4EA4");
button.setBounds(47, 497, 93, 23);
contentPane.add(button);

//重置按钮
JButton button_1 = new JButton("\u91CD\u7F6E");
button_1.setBounds(187, 497, 93, 23);
contentPane.add(button_1);
}

//成绩文本框验证
public void yanzheng(JTextField jt){
String fs = jt.getText();
//验证输入首数字是否为零
if(fs.length()>=2 && fs.length()<=3){
if(fs.charAt(0)=='0'){
fs = fs.substring(1, fs.length());
System.out.println(fs);
jt.setText(fs);
String yw = textField_2.getText().trim();
int i = 0;
if(yw!=null){
i = new Integer(yw);
}
String sx = textField_4.getText().trim();
System.out.println(sx);
int j = 0;
if(sx!=""||(!sx.equals(""))){
j = new Integer(sx);
}
String wy = textField_5.getText().trim();
int k = 0;
if(wy!=null){
k = new Integer(wy);
}
// int zf = Integer.valueOf(yw)+Integer.valueOf(sx)+Integer.valueOf(wy);
// textField_6.setText(String.valueOf(zf));
// int pj = zf/3;
// textField_7.setText(String.valueOf(pj));
// if(pj>=90 && pj<=100){
// textField_8.setText(String.valueOf("优"));
// }else if(pj>=75 && pj <= 89){
// textField_8.setText(String.valueOf("良"));
// }else if(pj >= 60 && pj <= 74){
// textField_8.setText(String.valueOf("中"));
// }else if(pj >= 0 && pj <= 59){
// textField_8.setText(String.valueOf("差"));
// }
}
if(fs.length()==3){
if(fs.charAt(0)>='1' && (fs.charAt(1)>'0' || fs.charAt(2)>'0')){
JOptionPane.showMessageDialog(ADDStudent.this,"分数范围在:0分~100分","验证提示",JOptionPane.WARNING_MESSAGE);
jt.setText("");
jt.requestFocus();
}
}
}else if(fs.length()>3){
JOptionPane.showMessageDialog(ADDStudent.this,"分数范围在:0分~100分","验证提示",JOptionPane.WARNING_MESSAGE);
jt.setText("");
jt.requestFocus();
}

}
}

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

package view;


import java.awt.BorderLayout;
import java.awt.Toolkit;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.Vector;


import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;


import control.StuControl;
import model.Student;


public class FindStuForID extends JFrame {


private JPanel contentPane;
private JTable table;
private int winWidth = (int) Toolkit.getDefaultToolkit().getScreenSize().getWidth();//获得屏幕的宽度
private int winHeight = (int) Toolkit.getDefaultToolkit().getScreenSize().getHeight();//获得屏幕的高度
private int x = winWidth/2-800/2;
private int y = winHeight/2-500/2;

public FindStuForID(String id) {
addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
FindStuForID.this.dispose();
}
});
Student stu = StuControl.getInstance().getStuForID(id);
if(stu==null){
JOptionPane.showMessageDialog(FindStuForID.this, "没有找到要查找的学生","查询结果",JOptionPane.WARNING_MESSAGE);
FindStuForID.this.dispose();
}else{
Vector<Object> row = new Vector<Object>();
row.add(stu.getId());
row.add(stu.getName());
row.add(stu.getSex());
row.add(stu.getYw());
row.add(stu.getSx());
row.add(stu.getWy());
row.add(stu.getZf());
row.add(stu.getPj());
row.add(stu.getPf());
Vector<Vector<Object>> stuDate = new Vector<Vector<Object>>();
stuDate.add(row);
Vector<String> colNum = new Vector<String>();
colNum.add("学号");
colNum.add("姓名");
colNum.add("性别");
colNum.add("语文");
colNum.add("数学");
colNum.add("外语");
colNum.add("总分");
colNum.add("平均分");
colNum.add("评级");
table = new JTable(stuDate,colNum);
JScrollPane jsp = new JScrollPane(table);

JFrame jf = new JFrame();
jf.getContentPane().add(jsp, BorderLayout.CENTER);
jf.setVisible(true);
jf.setTitle("查询学生信息");
jf.setBounds(x, y, 800, 500);
}

}

}

---------------------------------------------------------------------------------------------------------------------------------------------------------------

package view;


import java.awt.BorderLayout;
import java.awt.Toolkit;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.Vector;


import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;


import control.StuControl;
import model.Student;


public class FindStuForName extends JFrame {


private JPanel contentPane;
private JTable table;
private int winWidth = (int) Toolkit.getDefaultToolkit().getScreenSize().getWidth();//获得屏幕的宽度
private int winHeight = (int) Toolkit.getDefaultToolkit().getScreenSize().getHeight();//获得屏幕的高度
private int x = winWidth/2-800/2;
private int y = winHeight/2-500/2;

public FindStuForName(String name) {
addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
FindStuForName.this.dispose();
}
});
Student stu = StuControl.getInstance().getStuForName(name);
if(stu==null){
JOptionPane.showMessageDialog(FindStuForName.this, "没有找到要查找的学生","查询结果",JOptionPane.WARNING_MESSAGE);
FindStuForName.this.dispose();
}else{
Vector<Object> row = new Vector<Object>();
row.add(stu.getId());
row.add(stu.getName());
row.add(stu.getSex());
row.add(stu.getYw());
row.add(stu.getSx());
row.add(stu.getWy());
row.add(stu.getZf());
row.add(stu.getPj());
row.add(stu.getPf());
Vector<Vector<Object>> stuDate = new Vector<Vector<Object>>();
stuDate.add(row);
Vector<String> colNum = new Vector<String>();
colNum.add("学号");
colNum.add("姓名");
colNum.add("性别");
colNum.add("语文");
colNum.add("数学");
colNum.add("外语");
colNum.add("总分");
colNum.add("平均分");
colNum.add("评级");
table = new JTable(stuDate,colNum);
JScrollPane jsp = new JScrollPane(table);

JFrame jf = new JFrame();
jf.getContentPane().add(jsp, BorderLayout.CENTER);
jf.setVisible(true);
jf.setTitle("查询学生信息");
jf.setBounds(x, y, 800, 500);
}

}

}

-----------------------------------------------------------------------------------------------------------------------------------------------------------------

package view;


import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.Toolkit;


import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;


import control.TeaControl;


import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JPasswordField;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.ActionEvent;


public class Login extends JFrame {


private JPanel contentPane;
private JTextField nameText;
private JPasswordField passwordField;
private int winWidth = (int) Toolkit.getDefaultToolkit().getScreenSize().getWidth();//获得屏幕的宽度
private int winHeight = (int) Toolkit.getDefaultToolkit().getScreenSize().getHeight();//获得屏幕的高度
private int x = winWidth/2-320/2;
private int y = winHeight/2-166/2;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Login frame = new Login();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}


/**
* Create the frame.
*/
public Login() {
setResizable(false);
setTitle("\u6559\u5E08\u767B\u5F55");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(x, y, 320, 166);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);

//账号标签
JLabel nameLable = new JLabel("\u8D26\u53F7\uFF1A");
nameLable.setBounds(43, 20, 54, 15);
contentPane.add(nameLable);

//密码标签
JLabel passwordLable = new JLabel("\u5BC6\u7801\uFF1A");
passwordLable.setBounds(43, 55, 54, 15);
contentPane.add(passwordLable);

//用户名文本框
nameText = new JTextField();
nameText.addKeyListener(new KeyAdapter() {
@Override
public void keyTyped(KeyEvent e) {
int key = e.getKeyChar();
if(key == KeyEvent.VK_ENTER){
loginVerify();
}
}
});
nameText.setBounds(96, 17, 162, 21);
contentPane.add(nameText);
nameText.setColumns(10);

//密码文本框
passwordField = new JPasswordField();
passwordField.addKeyListener(new KeyAdapter() {
@Override
public void keyTyped(KeyEvent e) {
int key = e.getKeyChar();
if(key == KeyEvent.VK_ENTER){
loginVerify();
}
}
});
passwordField.setBounds(96, 52, 162, 21);
contentPane.add(passwordField);

//登录按钮
JButton loginButton = new JButton("登录");
loginButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
loginVerify();
}
});
loginButton.setBounds(43, 105, 93, 23);
contentPane.add(loginButton);

//注册按钮
JButton regButton = new JButton("注册");
regButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
new Reg().setVisible(true);
Login.this.dispose();
}
});
regButton.setBounds(165, 105, 93, 23);
contentPane.add(regButton);
}

//登录验证
public void loginVerify(){


String name = nameText.getText();//获得用户输入的账号
if(name.equals("")||name==""){
JOptionPane.showMessageDialog(Login.this,"账号不能为空", "登录信息", JOptionPane.CANCEL_OPTION);
nameText.requestFocus();
}else{
String password = String.valueOf(passwordField.getPassword());//获得用户输入的密码
if(password.equals("")||password==""){
JOptionPane.showMessageDialog(Login.this,"密码不能为空", "登录信息", JOptionPane.CANCEL_OPTION);
passwordField.requestFocus();
}else{
TeaControl tc = new TeaControl();
String message = tc.login(name, password);
if(message.equals("登录成功")){
JOptionPane.showMessageDialog(Login.this, message, "登录信息", JOptionPane.NO_OPTION);
new UserMain(name).setVisible(true);
Login.this.dispose();
}else if(message.equals("密码错误")){
JOptionPane.showMessageDialog(Login.this, message, "登录信息", JOptionPane.OK_OPTION);
passwordField.setText("");
passwordField.requestFocus();
}else if(message.equals("用户不存在")){
JOptionPane.showMessageDialog(Login.this, message, "登录信息", JOptionPane.CANCEL_OPTION);
nameText.setText("");
passwordField.setText("");
nameText.requestFocus();
}
}
}
}
}

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------

package view;


import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.Toolkit;


import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;


import control.TeaControl;
import model.Teacher;


import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JPasswordField;
import javax.swing.JComboBox;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;


import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;


public class Reg extends JFrame {


private JPanel contentPane;
private JTextField textField;
private JPasswordField passwordField;
private JPasswordField passwordField_1;
private JComboBox comboBox;
private int winWidth = (int) Toolkit.getDefaultToolkit().getScreenSize().getWidth();//获得屏幕的宽度
private int winHeight = (int) Toolkit.getDefaultToolkit().getScreenSize().getHeight();//获得屏幕的高度
private int x = winWidth/2-344/2;
private int y = winHeight/2-278/2;

/**
* Create the frame.
*/
public Reg() {
setTitle("\u6559\u5E08\u6CE8\u518C");
setResizable(false);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(x, y, 344, 278);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);

//用户名标签
JLabel label = new JLabel("\u7528\u6237\u540D\uFF1A");
label.setBounds(54, 26, 54, 15);
contentPane.add(label);

//密码标签
JLabel label_1 = new JLabel("\u5BC6  \u7801\uFF1A");
label_1.setBounds(54, 59, 54, 15);
contentPane.add(label_1);

//确认密码标签
JLabel label_2 = new JLabel("\u786E\u8BA4\u5BC6\u7801\uFF1A");
label_2.setBounds(54, 100, 68, 15);
contentPane.add(label_2);

//职务标签
JLabel label_3 = new JLabel("\u804C  \u52A1\uFF1A");
label_3.setBounds(54, 145, 54, 15);
contentPane.add(label_3);

//用户名输入框
textField = new JTextField();
textField.setBounds(118, 23, 146, 21);
contentPane.add(textField);
textField.setColumns(10);

//密码输入框
passwordField = new JPasswordField();
passwordField.setBounds(118, 56, 146, 21);
contentPane.add(passwordField);

//确认密码输入框
passwordField_1 = new JPasswordField();
passwordField_1.setBounds(118, 97, 146, 21);
contentPane.add(passwordField_1);

//职务下拉框
comboBox = new JComboBox();
comboBox.setModel(new DefaultComboBoxModel(new String[] {"\u8BF7\u9009\u62E9", "\u6559\u5E08", "\u6559\u5B66\u4E3B\u7BA1"}));
comboBox.setBounds(118, 142, 123, 21);
contentPane.add(comboBox);

//提交按钮
JButton tijiao = new JButton("\u63D0\u4EA4");
tijiao.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
regVerify();
}
});
tijiao.setBounds(53, 197, 93, 23);
contentPane.add(tijiao);

//返回登录
JButton back = new JButton("\u8FD4\u56DE\u767B\u5F55");
back.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
new Login().setVisible(true);
Reg.this.dispose();
}
});
back.setBounds(178, 197, 93, 23);
contentPane.add(back);
}

public void regVerify(){


String name = textField.getText();
if(name.equals("")||name==""){
JOptionPane.showMessageDialog(Reg.this,"用户名不能为空", "注册信息", JOptionPane.CANCEL_OPTION);
textField.requestFocus();

}else{
String password = String.valueOf(passwordField.getPassword());
if(password.equals("")||password==""){
JOptionPane.showMessageDialog(Reg.this,"密码不能为空", "注册信息", JOptionPane.CANCEL_OPTION);
passwordField.requestFocus();
}else{
String password2 = String.valueOf(passwordField_1.getPassword());
if(password2.equals("")||password2==""){
JOptionPane.showMessageDialog(Reg.this,"确认密码不能为空", "注册信息", JOptionPane.CANCEL_OPTION);
passwordField_1.requestFocus();
}else if(!password.equals(password2)){
JOptionPane.showMessageDialog(Reg.this,"密码输入不一致", "注册信息", JOptionPane.CANCEL_OPTION);
passwordField_1.setText("");
passwordField_1.requestFocus();
}else{
int select = comboBox.getSelectedIndex();
if(select == 0){
JOptionPane.showMessageDialog(Reg.this,"请选择职务", "注册信息", JOptionPane.CANCEL_OPTION);
}else{
TeaControl tc = new TeaControl();
String message = tc.reg(new Teacher(name,password,select));
if(message.equals("注册成功")){
JOptionPane.showMessageDialog(Reg.this,message, "注册信息", JOptionPane.NO_OPTION);
new Login().setVisible(true);
Reg.this.dispose();
}else if(message.equals("注册失败")){
JOptionPane.showMessageDialog(Reg.this, message, "注册信息", JOptionPane.OK_OPTION);
textField.setText("");
passwordField.setText("");
passwordField_1.setText("");
comboBox.setSelectedIndex(0);
textField.requestFocus();
}
}
}
}
}
}
}

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

package view;


import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.Toolkit;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.List;
import java.util.Vector;


import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.border.EmptyBorder;


import control.StuControl;
import model.Student;


import javax.swing.JTable;


public class ShowStu extends JFrame {


private JPanel contentPane;
private JTable table;
private int winWidth = (int) Toolkit.getDefaultToolkit().getScreenSize().getWidth();//获得屏幕的宽度
private int winHeight = (int) Toolkit.getDefaultToolkit().getScreenSize().getHeight();//获得屏幕的高度
private int x = winWidth/2-800/2;
private int y = winHeight/2-500/2;

public static void main(String[] args) {
new ShowStu();
}

public ShowStu() {
addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
ShowStu.this.dispose();
}
});
List<Student> list = StuControl.getInstance().getAllStu();
Vector<Object> row = null;
Vector<Vector<Object>> stuDate = new Vector<Vector<Object>>();
for (Student stu : list) {
row = new Vector<Object>();
row.add(stu.getId());
row.add(stu.getName());
row.add(stu.getSex());
row.add(stu.getYw());
row.add(stu.getSx());
row.add(stu.getWy());
row.add(stu.getZf());
row.add(stu.getPj());
row.add(stu.getPf());
stuDate.add(row);
}
Vector<String> colNum = new Vector<String>();
colNum.add("学号");
colNum.add("姓名");
colNum.add("性别");
colNum.add("语文");
colNum.add("数学");
colNum.add("外语");
colNum.add("总分");
colNum.add("平均分");
colNum.add("评级");
table = new JTable(stuDate,colNum);
JScrollPane jsp = new JScrollPane(table);

JFrame jf = new JFrame();
jf.getContentPane().add(jsp, BorderLayout.CENTER);
jf.setVisible(true);
jf.setTitle("查询学生信息");
jf.setBounds(x, y, 800, 500);


}

}

----------------------------------------------------------------------------------------------------------------------------------------------------

package view;


import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;


import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;


import control.StuControl;
import control.TeaControl;
import model.Student;
import model.Teacher;


import javax.swing.JLabel;
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.print.attribute.standard.JobName;
import javax.swing.ImageIcon;


public class UserMain extends JFrame {


private JPanel contentPane;
private int winWidth = (int) Toolkit.getDefaultToolkit().getScreenSize().getWidth();//获得屏幕的宽度
private int winHeight = (int) Toolkit.getDefaultToolkit().getScreenSize().getHeight();//获得屏幕的高度
private int x = winWidth/2-450/2;
private int y = winHeight/2-171/2;

public UserMain(String name) {
addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
int v = JOptionPane.showConfirmDialog(UserMain.this,"你确认要退出系统吗?","请确认",JOptionPane.OK_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE,null);
if(v==JOptionPane.OK_OPTION){
System.exit(0);
}
}
});
setTitle("学生成绩管理系统");
setResizable(false);
setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
setBounds(x, y, 450, 171);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);

JLabel lblNewLabel = new JLabel();
lblNewLabel.setText(name+"你好,欢迎登陆学生成绩管理系统!");
lblNewLabel.setFont(new Font("宋体",Font.BOLD,18));
lblNewLabel.setBounds(10, 44, 434, 42);
contentPane.add(lblNewLabel);

JMenuBar menuBar = new JMenuBar();
menuBar.setBounds(0, 0, 444, 21);
contentPane.add(menuBar);

JMenu menu = new JMenu("系统选项");
menuBar.add(menu);

//当前用户
JMenuItem menuItem = new JMenuItem("当前用户");
menuItem.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent e) {
TeaControl tc = new TeaControl();
Teacher tea = tc.findTes(name);
String zw = tea.getPower()==1?"教师":"教学主管";
String info = "当前在线:"+tea.getName()+",职务:"+zw;
JOptionPane.showMessageDialog(UserMain.this,info,"当前用户",JOptionPane.PLAIN_MESSAGE);
}
});
menu.add(menuItem);

//注销登录
JMenuItem menuItem_1 = new JMenuItem("注销登录");
menuItem_1.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent arg0) {
new Login().setVisible(true);
UserMain.this.dispose();
}
});
menu.add(menuItem_1);

//退出系统
JMenuItem menuItem_2 = new JMenuItem("退出系统");
menuItem_2.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent e) {
int v = JOptionPane.showConfirmDialog(UserMain.this,"你确认要退出系统吗?","请确认",JOptionPane.OK_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE,null);
if(v==JOptionPane.OK_OPTION){
System.exit(0);
}
}
});
menu.add(menuItem_2);

JMenu menu_1 = new JMenu("查询");
menuBar.add(menu_1);

//查询所有学生
JMenuItem menuItem_3 = new JMenuItem("查询所有学生");
menuItem_3.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent e) {
new ShowStu();

}
});
menu_1.add(menuItem_3);

//根据学号查询
JMenuItem menuItem_4 = new JMenuItem("根据学号查询");
menuItem_4.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent e) {
String stuID = JOptionPane.showInputDialog(UserMain.this, "请输入要查询的学号", "查询学生", JOptionPane.PLAIN_MESSAGE);
new FindStuForID(stuID);
}
});
menu_1.add(menuItem_4);

//根据姓名查询
JMenuItem menuItem_5 = new JMenuItem("根据姓名查询");
menuItem_5.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent e) {
String name = JOptionPane.showInputDialog(UserMain.this, "请输入要查询的姓名", "查询学生", JOptionPane.PLAIN_MESSAGE);
new FindStuForName(name);
}
});
menu_1.add(menuItem_5);

JMenu menu_2 = new JMenu("修改");
menuBar.add(menu_2);

JMenuItem menuItem_6 = new JMenuItem("修改学生信息");

menu_2.add(menuItem_6);

JMenuItem menuItem_7 = new JMenuItem("修改个人信息");
menu_2.add(menuItem_7);

JMenu menu_3 = new JMenu("添加");
menuBar.add(menu_3);

//添加学生
JMenuItem menuItem_8 = new JMenuItem("添加学生");
menuItem_8.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent e) {
new ADDStudent().setVisible(true);

}
});
menu_3.add(menuItem_8);

JMenu menu_4 = new JMenu("删除");
menuBar.add(menu_4);

//删除学生
JMenuItem menuItem_9 = new JMenuItem("删除学生");
menuItem_9.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent e) {
String name = JOptionPane.showInputDialog(UserMain.this, "请输入要删除的学生姓名", "删除学生", JOptionPane.PLAIN_MESSAGE);
Student stu = StuControl.getInstance().getStuForName(name);
if(stu != null){
boolean b = StuControl.getInstance().delStud(name);
if(!b){
JOptionPane.showMessageDialog(UserMain.this, "删除成功!","删除学生",JOptionPane.PLAIN_MESSAGE);
}else{
JOptionPane.showMessageDialog(UserMain.this,"删除失败!","删除学生",JOptionPane.ERROR_MESSAGE);
}
}else{
JOptionPane.showMessageDialog(UserMain.this, "学生不存在!","删除学生",JOptionPane.WARNING_MESSAGE);
}
}
});
menu_4.add(menuItem_9);

JLabel lblNewLabel_1 = new JLabel();
lblNewLabel_1.setFont(new Font("宋体",Font.BOLD,16));
lblNewLabel_1.setBounds(10, 96, 374, 37);
contentPane.add(lblNewLabel_1);

//当前时间
SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日  HH:mm:ss");
Timer time = new Timer();
time.schedule(new TimerTask() {

@Override
public void run() {
lblNewLabel_1.setText(sdf.format(new Date()));
}
}, 0,1000);

}


}

-==================================================================================================================

package util;


import java.awt.BorderLayout;  
import java.awt.Color;  
import java.awt.Font;  
import java.awt.Graphics;  
import java.util.Calendar;  
import java.util.GregorianCalendar;  
import java.util.TimerTask;  
  
import javax.swing.*;  
  
/** 
 * 时钟类 
 */  
public class Clock extends JFrame {  
    // 画时钟的面板  
    private paintPanel clock = new paintPanel();  
    // 定时器  
    private java.util.Timer timer = new java.util.Timer();  
    // 显示时间的label  
    JLabel messageLabel = new JLabel("", SwingConstants.CENTER);  
  
    public Clock() {  
        setTitle("时钟");  
        this.setVisible(true);  
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);  
        // this.setLocationRelativeTo(null);  
        this.setSize(400, 400);  
  
        add(clock);  
        messageLabel.setForeground(Color.RED);  
        messageLabel.setFont(new Font("Courier", Font.BOLD, 18));  
        add(messageLabel, BorderLayout.SOUTH);  
  
        // 定时器执行任务  
        timer.schedule(new TimerTask() {  
            @Override  
            public void run() {  
                clock.setCurrentTime();// 设置为当前时间  
                messageLabel.setText(clock.getHour() + ":" + clock.getMinute() + ":" + clock.getSecond() + '\n');  
                repaint();  
            }  
        }, 0, 1000);  
  
    }  
  
    public static void main(String[] args) {  
        new Clock();  
    }  
  
    private class paintPanel extends JPanel {  
        private int hour, minute, second;  
  
        public paintPanel() {  
            setCurrentTime();  
        }  
  
        // 设置时钟为当前时间  
        private void setCurrentTime() {  
            Calendar calendar = new GregorianCalendar();  
            hour = calendar.get(Calendar.HOUR_OF_DAY);  
            minute = calendar.get(Calendar.MINUTE);  
            second = calendar.get(Calendar.SECOND);  
        }  
  
        @Override  
        protected void paintComponent(Graphics g) {  
            super.paintComponent(g);  
            int xCenter = getWidth() / 2;  
            int yCenter = getHeight() / 2;  
  
            // 计算半径  
            int radius = (int) (Math.min(this.getWidth(), this.getHeight()) * 0.8 * 0.5);  
            // 画圆  
            g.drawOval(xCenter - radius, yCenter - radius, radius * 2, radius * 2);  
  
            // 画钟面上显示的数字  
            g.drawString("12", xCenter - 6, yCenter - radius + 12);  
            g.drawString("3", xCenter + radius - 12, yCenter + 4);  
            g.drawString("6", xCenter - 4, yCenter + radius - 8);  
            g.drawString("9", xCenter - radius + 4, yCenter + 6);  
  
            // 画时针、分针、秒针  
            g.drawLine(xCenter, yCenter, (int) (xCenter + radius * 0.8 * Math.sin(second * 2 * Math.PI / 60)), (int) (yCenter - radius * 0.8 * Math.cos(second * 2 * Math.PI / 60)));  
            g.drawLine(xCenter, yCenter, (int) (xCenter + radius * 0.6 * Math.sin(minute * 2 * Math.PI / 60)), (int) (yCenter - radius * 0.6 * Math.cos(minute * 2 * Math.PI / 60)));  
            g.drawLine(xCenter, yCenter, (int) (xCenter + radius * 0.4 * Math.sin((hour + minute / 60.0) * 2 * Math.PI / 12)), (int) (yCenter - radius * 0.4  
                    * Math.cos((hour + minute / 60.0) * 2 * Math.PI / 12)));  
        }  
  
        public int getHour() {  
            return hour;  
        }  
  
        public int getMinute() {  
            return minute;  
        }  
  
        public int getSecond() {  
            return second;  
        }  
    }  
}

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------

package util;


import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;


public class GetNumber {


public static String getNum(){
Random r = new Random();
int ran = r.nextInt(899)+100;
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
String date = sdf.format(new Date());
return date+String.valueOf(ran);
}
}

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

package util;


public class Test {


public static void main(String[] args) {
String fs = "023";
if(fs.length()>=2){
if(fs.charAt(0)=='0'){
fs = fs.substring(1, fs.length());
}
}
System.out.println(fs);


}


}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值