当前位置:首页 » 编程语言 » 学生信息管理系统java

学生信息管理系统java

发布时间: 2025-02-05 06:58:45

java程序设计课程设计 学生信息管理系统 要求:使用图形用户界面用数据库建立1或

import java.awt.*;
import java.awt.event.*;
public class DengLuJieMian extends Frame implements ActionListener
{
Label username=new Label("用户名:");//使用文本创建一个用户名标签
TextField t1=new TextField();//创建一个文本框对象
Label password=new Label("密码:");//创建一个密码标签
TextField t2=new TextField();
Button b1=new Button("登陆");//创建登陆按钮
Button b2=new Button("取消");//创建取消按钮
public DengLuJieMian()
{
this.setTitle("学生信息管理系统");//设置窗口标题
this.setLayout(null);//设置窗口布局管理器
username.setBounds(50,40,60,20);//设置姓名标签的初始位置
this.add(username);// 将姓名标签组件添加到容器
t1.setBounds(120,40,80,20);// 设置文本框的初始位置
this.add(t1);// 将文本框组件添加到容器
password.setBounds(50,100,60,20);//密码标签的初始位置
this.add(password);//将密码标签组件添加到容器
t2.setBounds(120,100,80,20);//设置密码标签的初始位置
this.add(t2);//将密码标签组件添加到容器
b1.setBounds(50,150,60,20);//设置登陆按钮的初始位置
this.add(b1);//将登陆按钮组件添加到容器
b2.setBounds(120,150,60,20);//设置取消按钮的初始位置
this.add(b2);// 将取消按钮组件添加到容器
b1.addActionListener(this);//给登陆按钮添加监听器
b2.addActionListener(this);// 给取消按钮添加监听器

this.setVisible(true);//设置窗口的可见性
this.setSize(300,200);//设置窗口的大小
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});//通过内部类重写关闭窗体的方法
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==b1)//处理登陆事件
{
String name=t1.getText();
String pass=t2.getText();
if(name!=null&&pass.equals("000123"))//判断语句
{
new StudentJieMian();
}
}
}
public static void main(String args[])//主函数
{
new DengLuJieMian();
}
}
以下方法实现了学生界面设计
import java.awt.*;
import java.awt.event.*;
class StudentJieMian extends Frame implements ActionListener
{
MenuBar m=new MenuBar();//创建菜单栏
Menu m1=new Menu("信息");//创建菜单“信息”
MenuItem m11=new MenuItem("插入");//创建“插入”的菜单项
MenuItem m12=new MenuItem("查询");
Menu m2=new Menu("成绩");//创建菜单“成绩”
MenuItem m21=new MenuItem("查询");
public StudentJieMian()
{
this.setTitle("学生界面");//设置窗口标题
this.setLayout(new CardLayout());//设置窗口布局管理器
this.setMenuBar(m);//将菜单栏组件添加到容器
m.add(m1);//将信息菜单放入菜单栏
m.add(m2);
m1.add(m11);//将“插入”菜单项添加到“信息”菜单
m1.add(m12); //将“查询”菜单项添加到“信息”菜单
m2.add(m21); //将“查询”菜单项添加到“成绩”菜单
m11.addActionListener(this); //给“插入”菜单项添加监听器
m12.addActionListener(this); //给“查询”菜单项添加监听器
m21.addActionListener(this); //给“查询”菜单项添加监听器
this.setVisible(true); //设置窗口的可见性
this.setSize(300,200); //设置窗口的大小
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);//关闭窗口
}
});
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==m11) //处理“添加信息”事件
{
new AddStudent();
}
if(e.getSource()==m12) //处理“查询信息”事件
{
new SelectStudent();
}
if(e.getSource()==m21) //处理“查询成绩”事件
{
new ChengJiStudent();
}
}
public static void main(String args[])
{ new StudentJieMian(); //创建一个对象 }

② 怎么用java做一个简单的学生管理系统

用java写的话,可以用List来实现学生管理系统:x0dx0a首先,管理系统尺孙是针对学生对象的,所以我们先把学生对象就写出来:x0dx0apackage bean;x0dx0apublic class Student {x0dx0a String name;x0dx0a String studentId;x0dx0a String sex;x0dx0a int grade;x0dx0a public Student(String name,String studentId,String sex,int grade){x0dx0a this.name= name;x0dx0a this.studentId= studentId;x0dx0a this.sex = sex;x0dx0a this.grade = grade; x0dx0a }x0dx0a public int getGrade(){x0dx0a return grade;x0dx0a }x0dx0a public String getName(){x0dx0a return name;x0dx0a }x0dx0a public String getSex(){x0dx0a return sex;x0dx0a }x0dx0a public void setGrade(int g){x0dx0a this.grade = g;x0dx0a }x0dx0a public String getStudentId(){x0dx0a return studentId;x0dx0a }x0dx0a}x0dx0a这里面定义了一些得到当前学生对象数据的一些get方法,和成绩修改的set方法,代码很简单,就不做详细的解答。x0dx0a就下来就是我们的正文了。x0dx0a虽然我们暂时不用swing来做界面,但是总得要看的过去吧,所以,先做了一个比较简单的界面:x0dx0a System.out.println("***************");x0dx0a System.out.println("*欢迎来到学生管理系统 *");x0dx0a System.out.println("*1:增加学生脊搜 *");x0dx0a System.out.println("*2:删除学生 *");x0dx0a System.out.println("*3:修改成绩 *");x0dx0a System.out.println("*4:查询成绩 *");x0dx0a System.out.println("***************");x0dx0a System.out.println("您想选择的操作是:");x0dx0a这里可以看到,我们的是用一个1234来选择项目,说以不得不讲一下Java如何获取到键盘所输入的数据---------Scanner ,要使用这个,首先需要import进来一个包:x0dx0a例如这里:x0dx0aimport java.util.*;x0dx0a之后的两行代码搞定输入:x0dx0aScanner sc = new Scanner(System.in);x0dx0a int choice = sc.nextInt();x0dx0a接下来就是各个功能的陵野链实现:x0dx0ax0dx0apackage test;x0dx0aimport java.util.*;x0dx0aimport bean.Student;x0dx0apublic class Manager {x0dx0a static List StudentList = new LinkedList();x0dx0a public static void main(String[] agrs){x0dx0a select(StudentList); x0dx0a }x0dx0a private static void select(List StudentList ){x0dx0a System.out.println("***************");x0dx0a System.out.println("*欢迎来到学生管理系统 *");x0dx0a System.out.println("*1:增加学生 *");x0dx0a System.out.println("*2:删除学生 *");x0dx0a System.out.println("*3:修改成绩 *");x0dx0a System.out.println("*4:查询成绩 *");x0dx0a System.out.println("***************");x0dx0a System.out.println("您想选择的操作是:");x0dx0a Scanner sc = new Scanner(System.in);x0dx0a int choice = sc.nextInt(); x0dx0a switch(choice){x0dx0a //增加学生x0dx0a case 1:x0dx0a System.out.print("请输入学生的姓名:");x0dx0a Scanner Sname = new Scanner(System.in);x0dx0a String name = Sname.nextLine();x0dx0a System.out.print("请输入学生的性别:");x0dx0a Scanner Ssex = new Scanner(System.in);x0dx0a String sex = Ssex.nextLine();x0dx0a System.out.print("请输入学生的学号:");x0dx0a Scanner SId = new Scanner(System.in);x0dx0a String studentId = SId.nextLine();x0dx0a System.out.print("请输入学生的成绩:");x0dx0a Scanner Sgrade = new Scanner(System.in);x0dx0a int grade = Sgrade.nextInt();x0dx0a StudentList.add(new Student(name,studentId,sex,grade));x0dx0a System.out.println("添加成功!!!!!");x0dx0a select(StudentList);x0dx0a break;x0dx0a //删除学生成绩x0dx0a case 2:x0dx0a System.out.print("请告诉我需要删除学生的学号:");x0dx0a Scanner Sid = new Scanner(System.in);x0dx0a String SstudentId = Sid.nextLine();x0dx0a boolean isfindDelete = false;x0dx0a for (int i = 0; i < StudentList.size(); i++) {x0dx0a if(SstudentId.equals(StudentList.get(i).getStudentId())){x0dx0a System.out.println("发现了该学生,正在删除...");x0dx0a StudentList.remove(i);x0dx0a System.out.println("删除成功!!!");x0dx0a isfindDelete =true;x0dx0a }x0dx0a }x0dx0a if(!isfindDelete){x0dx0a System.out.println("抱歉,没有找到");x0dx0a }x0dx0a select(StudentList);x0dx0a break;x0dx0a //修改学生成绩x0dx0a case 3:x0dx0a System.out.print("请告诉我需要修改成绩学生的学号:");x0dx0a Scanner GId = new Scanner(System.in);x0dx0a String GstudentId = GId.nextLine();x0dx0a boolean isfindChange = false;x0dx0a for (int j = 0; j < StudentList.size(); j++) {x0dx0a if(GstudentId.equals(StudentList.get(j).getStudentId())){x0dx0a System.out.println("发现了该学生,正在修改...");x0dx0a System.out.println("学生原成绩为"+StudentList.get(j).getGrade());x0dx0a System.out.print("请输入修改后学生的成绩:");x0dx0a Scanner Ggrade = new Scanner(System.in);x0dx0a int grade2 = Ggrade.nextInt();x0dx0a StudentList.get(j).setGrade(grade2);x0dx0a System.out.println("修改成功!!!");x0dx0a isfindChange =true;x0dx0a }else{x0dx0a }x0dx0a }x0dx0a if(!isfindChange){x0dx0a System.out.println("抱歉,没有找到");x0dx0a }x0dx0a select(StudentList);x0dx0a break;x0dx0a //查看学生成绩x0dx0a case 4:x0dx0a System.out.print("请告诉我需要查询学生的学号:");x0dx0a Scanner CId = new Scanner(System.in);x0dx0a String CstudentId = CId.nextLine();x0dx0a boolean isfindData = false;x0dx0a for (int i = 0; i < StudentList.size(); i++) {x0dx0a if(CstudentId.equals(StudentList.get(i).getStudentId())){x0dx0a System.out.println("名字:"+StudentList.get(i).getName());x0dx0a System.out.println("性别:"+StudentList.get(i).getSex());x0dx0a System.out.println("学号:"+StudentList.get(i).getStudentId());x0dx0a System.out.println("成绩:"+StudentList.get(i).getGrade());x0dx0a isfindData = true;x0dx0a }x0dx0a }x0dx0a if(!isfindData){x0dx0a System.out.println("抱歉,没有找到");x0dx0a }x0dx0a select(StudentList);x0dx0a break;x0dx0a default:x0dx0a System.out.println("您输入的数字有误,请重新输入:");x0dx0a break;x0dx0a }x0dx0a }x0dx0a}x0dx0a可以看见,我把所有的实现过程全部放在select();方法中了,这样可以避免我选择完了一个操作后不能继续其他操作。大部分的操作都是依靠for循环来遍历操作,方便快捷。

③ 用java编写一个学生管理系统平台登录模块怎么写啊

import java.util.Scanner;
public class StudentManagementSystemLogin {
public static void main(String[] args) {
// 创建Scanner对象,用于接收用运绝户输入
Scanner scanner = new Scanner(System.in);
// 定义用户名和密码
String username = "admin";
String password = "123456";
// 循环提示用户输入用户名和密码,腔悄郑直到伍颂输入正确为止
while (true) {
System.out.println("请输入用户名:");
String inputUsername = scanner.nextLine();
System.out.println("请输入密码:");
String inputPassword = scanner.nextLine();
if (inputUsername.equals(username) && inputPassword.equals(password)) {
System.out.println("登录成功!");
break;
} else {
System.out.println("用户名或密码错误,请重新输入!");
}
}
// 关闭Scanner对象
scanner.close();
}
}

④ java编写学生成绩管理系统

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Admin {

public static void main(String[] args) throws IOException, ClassNotFoundException {
Scanner in = new Scanner(System.in);
int studentNum = 5;

List<Student> result = new ArrayList<Student>();
for (int i = 0; i < studentNum; i++) {
Student bean = new Student();
System.out.print("输入第" + (i + 1) + "个学生学号:");
bean.setNo(in.next());
System.out.print("输入第" + (i + 1) + "个学生姓名:");
bean.setName(in.next());
System.out.print("输入第" + (i + 1) + "个学生数学成绩:");
bean.setShuxue(in.nextDouble());
System.out.print("输入第" + (i + 1) + "个学生语文成绩:");
bean.setYuwen(in.nextDouble());
result.add(bean);
}

while (true) {
System.out.println("1.保存到文件;2.总成绩;3.平均成绩;4.不及格比例;5.及格比例;6,优良比例;0.退出.");
int i = in.nextInt();

if (i == 0) {
System.exit(0);
}

if (i == 1) {
save(result);
}

if (i == 2) {
for (int j = 0; j < result.size(); j++) {
Student s = result.get(j);
System.out.println("学生" + s.getName() + "的总成绩是:" + s.all());
}
}

if (i == 3) {
int jigeSum = 0;
for (int j = 0; j < result.size(); j++) {
Student s = result.get(j);
if (!s.isJige()) {
jigeSum++;
}
}
System.out.println("不及格比例:" + jigeSum + "/" + result.size());
}
if (i == 4) {
// 篇幅受限,自行开发
}
if (i == 5) {
// 篇幅受限,自行开发
}
}
}

private static void save(List result) throws IOException {
FileOutputStream fs = new FileOutputStream("d:/a.txt");
ObjectOutputStream os = new ObjectOutputStream(fs);
os.writeObject(result);
os.flush();
os.close();
fs.close();
}
}

class Student implements Serializable {

private String no;

private String name;

private double shuxue;

private double yuwen;

public String getName() {
return name;
}

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

public String getNo() {
return no;
}

public void setNo(String no) {
this.no = no;
}

public double getShuxue() {
return shuxue;
}

public void setShuxue(double shuxue) {
this.shuxue = shuxue;
}

public double getYuwen() {
return yuwen;
}

public void setYuwen(double yuwen) {
this.yuwen = yuwen;
}

public double all() {
return shuxue + yuwen;
}

public double avg() {
return all() / 2;
}

public boolean isJige() {
return avg() > 60;
}
}

⑤ 学生信息综合查询管理系统 JAVA程序编写

package test;

import java.sql.*;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.border.*;
import javax.swing.JOptionPane;
class Add extends Panel implements ActionListener{
Connection con;
Statement sql;
Button b1,b2;
TextField tf1,tf2,tf3,tf4,tf5,tf6;
Box baseBox,bv1,bv2;
Add(){
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e){}
try{
con=DriverManager.getConnection("jdbc:odbc:data","","");
sql=con.createStatement();
}
catch(SQLException ee){}
setLayout(new BorderLayout());
Panel p1=new Panel();
Panel p2=new Panel();
tf1=new TextField(16);
tf2=new TextField(16);
tf3=new TextField(16);
tf4=new TextField(16);
tf5=new TextField(16);
tf6=new TextField(16);
b1=new Button("录入");
b1.setBackground(Color.green);
b2=new Button("重置");
b2.setBackground(Color.green);
b1.addActionListener(this);
b2.addActionListener(this);
p1.add(b1);
p1.add(b2);
bv1=Box.createVerticalBox();
bv1.add(new Label("学号"));
bv1.add(Box.createVerticalStrut(8));
bv1.add(new Label("姓名"));
bv1.add(Box.createVerticalStrut(8));
bv1.add(new Label("性别"));
bv1.add(Box.createVerticalStrut(8));
bv1.add(new Label("专业"));
bv1.add(Box.createVerticalStrut(8));
bv1.add(new Label("年级"));
bv1.add(Box.createVerticalStrut(8));
bv1.add(new Label("出生"));
bv1.add(Box.createVerticalStrut(8));
bv2=Box.createVerticalBox();
bv2.add(tf1);
bv2.add(Box.createVerticalStrut(8));
bv2.add(tf2);
bv2.add(Box.createVerticalStrut(8));
bv2.add(tf3);
bv2.add(Box.createVerticalStrut(8));
bv2.add(tf4);
bv2.add(Box.createVerticalStrut(8));
bv2.add(tf5);
bv2.add(Box.createVerticalStrut(8));
bv2.add(tf6);
bv2.add(Box.createVerticalStrut(8));
baseBox=Box.createHorizontalBox();
baseBox.add(bv1);
baseBox.add(Box.createHorizontalStrut(10));
baseBox.add(bv2);
p2.add(baseBox);
add(p1,"South");
add(p2,"Center");
setSize(350,300);
setBackground(Color.pink);
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==b1){
try{ insert();}
catch(SQLException ee){}
JOptionPane.showMessageDialog(this,"数据已入库!","提示对话框",JOptionPane.INFORMATION_MESSAGE);
}
else if(e.getSource()==b2){
tf1.setText(" ");
tf2.setText(" ");
tf3.setText(" ");
tf4.setText(" ");
tf5.setText(" ");
tf6.setText(" ");
}
}
public void insert() throws SQLException{
String s1="'"+tf1.getText().trim()+"'";
String s2="'"+tf2.getText().trim()+"'";
String s3="'"+tf3.getText().trim()+"'";
String s4="'"+tf4.getText().trim()+"'";
String s5="'"+tf5.getText().trim()+"'";
String s6="'"+tf6.getText().trim()+"'";
String temp="INSERT INTO jesse VALUES ("+s1+","+s2+","+s3+","+s4+","+s5+","+s6+")";
con=DriverManager.getConnection("jdbc:odbc:data","","");
sql.executeQuery(temp);
con.close();
}
}
class Query extends Panel implements ActionListener{
Connection con;
Statement sql;
TextField t1,t2,t3,t4,t5,t6;
Button b;
Box baseBox,bv1,bv2;
int flag=0;
Query(){
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e){}
try{
con=DriverManager.getConnection("jdbc:odbc:data","","");
sql=con.createStatement();
}
catch(SQLException ee){}
setLayout(new BorderLayout());
b=new Button("查询");
b.setBackground(Color.orange);
b.addActionListener(this);
t1=new TextField(8);
t2=new TextField(16);
t3=new TextField(16);
t4=new TextField(16);
t5=new TextField(16);
t6=new TextField(16);
t2.setEditable(false);
t3.setEditable(false);
t4.setEditable(false);
t5.setEditable(false);
t6.setEditable(false);
Panel p1=new Panel(),p2=new Panel();
p1.add(new Label("输入要查询的学号"));
p1.add(t1);
p1.add(b);
bv1=Box.createVerticalBox();
bv1.add(new Label("姓名"));
bv1.add(Box.createVerticalStrut(8));
bv1.add(new Label("性别"));
bv1.add(Box.createVerticalStrut(8));
bv1.add(new Label("专业"));
bv1.add(Box.createVerticalStrut(8));
bv1.add(new Label("年级"));
bv1.add(Box.createVerticalStrut(8));
bv1.add(new Label("出生"));
bv1.add(Box.createVerticalStrut(8));
bv2=Box.createVerticalBox();
bv2.add(t2);
bv2.add(Box.createVerticalStrut(8));
bv2.add(t3);
bv2.add(Box.createVerticalStrut(8));
bv2.add(t4);
bv2.add(Box.createVerticalStrut(8));
bv2.add(t5);
bv2.add(Box.createVerticalStrut(8));
bv2.add(t6);
bv2.add(Box.createVerticalStrut(8));
baseBox=Box.createHorizontalBox();
baseBox.add(bv1);
baseBox.add(Box.createHorizontalStrut(10));
baseBox.add(bv2);
p2.add(baseBox);
add(p1,"North");
add(p2,"Center");
setSize(300,250);
setBackground(Color.red);
}
public void actionPerformed(ActionEvent e){
flag=0;
try{query();}
catch(SQLException ee){}
}
public void query() throws SQLException{
String num,name,sex,subject,grade,born;
con=DriverManager.getConnection("jdbc:odbc:data","","");
ResultSet rs=sql.executeQuery("SELECT * FROM jesse ");
while(rs.next()){
num=rs.getString("学号");
name=rs.getString("姓名");
sex=rs.getString("性别");
subject=rs.getString("专业");
grade=rs.getString("年级");
born=rs.getString("出生");
if(num.equals(t1.getText().trim())){
t2.setText(name);
t3.setText(sex);
t4.setText(subject);
t5.setText(grade);
t6.setText(born);
flag=1;
break;
}
}
con.close();
if(flag==0){t1.setText("没有该学生");}
}
}
class Update extends Panel implements ActionListener{
Connection con;
Statement sql;
Button b1,b2,b3;
Box baseBox,bv1,bv2;
TextField t1,t2,t3,t4,t5,t6;
Update(){
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e){}
try{
con=DriverManager.getConnection("jdbc:odbc:data","","");
sql=con.createStatement();
}
catch(SQLException ee){}
setLayout(new BorderLayout());
b1=new Button("开始修改");
b1.setBackground(Color.green);
b2=new Button("录入修改");
b2.setBackground(Color.yellow);
b3=new Button("重置");
b3.setBackground(Color.yellow);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
t1=new TextField(8);
t2=new TextField(16);
t3=new TextField(16);
t4=new TextField(16);
t5=new TextField(16);
t6=new TextField(16);
Panel p1=new Panel(),p2=new Panel(),p3=new Panel();
p1.add(new Label("输入要修改信息的学号"));
p1.add(t1);
p1.add(b1);
bv1=Box.createVerticalBox();
bv1.add(new Label("(新)姓名"));
bv1.add(Box.createVerticalStrut(8));
bv1.add(new Label("(新)性别"));
bv1.add(Box.createVerticalStrut(8));
bv1.add(new Label("(新)专业"));
bv1.add(Box.createVerticalStrut(8));
bv1.add(new Label("(新)年级"));
bv1.add(Box.createVerticalStrut(8));
bv1.add(new Label("(新)出生"));
bv1.add(Box.createVerticalStrut(8));
bv2=Box.createVerticalBox();
bv2.add(t2);
bv2.add(Box.createVerticalStrut(8));
bv2.add(t3);
bv2.add(Box.createVerticalStrut(8));
bv2.add(t4);
bv2.add(Box.createVerticalStrut(8));
bv2.add(t5);
bv2.add(Box.createVerticalStrut(8));
bv2.add(t6);
bv2.add(Box.createVerticalStrut(8));
baseBox=Box.createHorizontalBox();
baseBox.add(bv1);
baseBox.add(Box.createHorizontalStrut(10));
baseBox.add(bv2);
p2.add(baseBox);
p3.add(b2);
p3.add(b3);
add(p1,"North");
add(p2,"Center");
add(p3,"South");
setSize(300,250);
setBackground(Color.cyan);
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==b1){
try{
String num,name,sex,subject,grade,born;
con=DriverManager.getConnection("jdbc:odbc:data","","");
ResultSet rs=sql.executeQuery("SELECT * FROM jesse ");
while(rs.next()){
num=rs.getString("学号");
name=rs.getString("姓名");
sex=rs.getString("性别");
subject=rs.getString("专业");
grade=rs.getString("年级");
born=rs.getString("出生");
if(num.equals(t1.getText().trim())){
t2.setText(name);
t3.setText(sex);
t4.setText(subject);
t5.setText(grade);
t6.setText(born);
break;
}
}
con.close();
}
catch(SQLException ee){}
}
if(e.getSource()==b2){
try{update();}
catch(SQLException ee){}
}
if(e.getSource()==b3){
t2.setText(" ");
t3.setText(" ");
t4.setText(" ");
t5.setText(" ");
t6.setText(" ");
}
}
public void update() throws SQLException{
String s1="'"+t1.getText().trim()+"'";
String s2="'"+t2.getText().trim()+"'";
String s3="'"+t3.getText().trim()+"'";
String s4="'"+t4.getText().trim()+"'";
String s5="'"+t5.getText().trim()+"'";
String s6="'"+t6.getText().trim()+"'";
String temp="UPDATE jesse SET 姓名 ="+s2+", 性别="+s3+", 专业="+s4+", 年级="+s5+", 出生="+s6+" WHERE 学号="+s1;
con=DriverManager.getConnection("jdbc:odbc:data","","");
sql.executeQuery(temp);
con.close();
}
}
class Delete extends Panel implements ActionListener{
Connection con;
Statement sql;
TextField t1,t2,t3,t4,t5,t6;
Button b;
Box baseBox,bv1,bv2;
Delete(){
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e){}
try{
con=DriverManager.getConnection("jdbc:odbc:data","","");
sql=con.createStatement();
}
catch(SQLException ee){}
setLayout(new BorderLayout());
b=new Button("删除");
b.setBackground(Color.cyan);
b.addActionListener(this);
t1=new TextField(8);
t1.addActionListener(this);
t2=new TextField(16);
t3=new TextField(16);
t4=new TextField(16);
t5=new TextField(16);
t6=new TextField(16);
t2.setEditable(false);
t3.setEditable(false);
t4.setEditable(false);
t5.setEditable(false);
t6.setEditable(false);
Panel p1=new Panel(),p2=new Panel();
p1.add(new Label("输入要删除的学号"));
p1.add(t1);
p1.add(b);
bv1=Box.createVerticalBox();
bv1.add(new Label("姓名"));
bv1.add(Box.createVerticalStrut(8));
bv1.add(new Label("性别"));
bv1.add(Box.createVerticalStrut(8));
bv1.add(new Label("专业"));
bv1.add(Box.createVerticalStrut(8));
bv1.add(new Label("年级"));
bv1.add(Box.createVerticalStrut(8));
bv1.add(new Label("出生"));
bv1.add(Box.createVerticalStrut(8));
bv2=Box.createVerticalBox();
bv2.add(t2);
bv2.add(Box.createVerticalStrut(8));
bv2.add(t3);
bv2.add(Box.createVerticalStrut(8));
bv2.add(t4);
bv2.add(Box.createVerticalStrut(8));
bv2.add(t5);
bv2.add(Box.createVerticalStrut(8));
bv2.add(t6);
bv2.add(Box.createVerticalStrut(8));
baseBox=Box.createHorizontalBox();
baseBox.add(bv1);
baseBox.add(Box.createHorizontalStrut(10));
baseBox.add(bv2);
p2.add(baseBox);
add(p1,"North");
add(p2,"Center");
setSize(300,250);
setBackground(Color.green);
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==t1){
try{delete();}
catch(SQLException ee){}
}
else if(e.getSource()==b){
int n=JOptionPane.showConfirmDialog(this,"确定要删除该学号及全部信息吗?","确定",JOptionPane.YES_NO_OPTION);
if(n==JOptionPane.YES_OPTION){
try{
String s1="'"+t1.getText().trim()+"'";
String temp="DELETE FROM jesse WHERE 学号="+s1;
con=DriverManager.getConnection("jdbc:odbc:data","","");
sql.executeUpdate(temp);
con.close();
}
catch(SQLException ee){}
}
else if(n==JOptionPane.NO_OPTION){}
}
}
public void delete() throws SQLException{
String num,name,sex,subject,grade,born;
con=DriverManager.getConnection("jdbc:odbc:data","","");
ResultSet rs=sql.executeQuery("SELECT * FROM jesse ");
while(rs.next()){
num=rs.getString("学号");
name=rs.getString("姓名");
sex=rs.getString("性别");
subject=rs.getString("专业");
grade=rs.getString("年级");
born=rs.getString("出生");
if(num.equals(t1.getText().trim())){
t2.setText(name);
t3.setText(sex);
t4.setText(subject);
t5.setText(grade);
t6.setText(born);
break;
}
}
con.close();
}
}
public class tyj extends Frame implements ActionListener{
MenuBar bar=null;
Menu menu1,menu2,menu3,menu4,menu5;
MenuItem item1,item2,item3,item4,item5;
Add zengjia;
Query chaxun;
Update gengxin;
Delete shanchu;
tyj(){
super("欢迎进入学生信息管理系统");
zengjia=new Add();
chaxun=new Query();
gengxin=new Update();
shanchu=new Delete();
bar=new MenuBar();
menu1=new Menu("信息录入");
menu2=new Menu("信息查询");
menu3=new Menu("信息更新");
menu4=new Menu("信息删除");
menu5=new Menu("退出系统");
item1=new MenuItem("录入");
item2=new MenuItem("查询");
item3=new MenuItem("更新");
item4=new MenuItem("删除");
item5=new MenuItem("退出");
menu1.add(item1);
menu2.add(item2);
menu3.add(item3);
menu4.add(item4);
menu5.add(item5);
bar.add(menu1);
bar.add(menu2);
bar.add(menu3);
bar.add(menu4);
bar.add(menu5);
setMenuBar(bar);
item1.addActionListener(this);
item2.addActionListener(this);
item3.addActionListener(this);
item4.addActionListener(this);
item5.addActionListener(this);
Label label=new Label("欢迎进入学生信息管理系统",Label.CENTER);
String s=" ";
Font f=new Font(s,Font.BOLD,22);
label.setFont(f);
label.setBackground(Color.GREEN);
label.setForeground(Color.BLUE);
add(label,"Center");
setVisible(true);
setSize(320,300);
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==item1){
removeAll();
add(zengjia,"Center");
validate();
}
if(e.getSource()==item2){
removeAll();
add(chaxun,"Center");
validate();
}
if(e.getSource()==item3){
removeAll();
add(gengxin,"Center");
validate();
}
if(e.getSource()==item4){
removeAll();
add(shanchu,"Center");
validate();
}
if(e.getSource()==item5){
removeAll();
setBackground(Color.GREEN);
Label label=new Label("欢迎进入学生信息管理系统",Label.CENTER);
String s=" ";
Font f=new Font(s,Font.BOLD,22);
label.setFont(f);
label.setForeground(Color.BLUE);
add(label,"Center");
validate();
}
}
public static void main(String[] args)
{
tyj jesse=new tyj();
jesse.setVisible(true);
jesse.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
}
}

⑥ 如何用java做一个学生管理系统平台的登录界面模块和添加界面模块!

下面是一个使用 Java 创建的学生管理系统的登录和添加界面模块的示例代码。这个代码演示了如何使用 Swing 库来构建图形用户界面(GUI)。
登录界面模块:
```java
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class Login extends JFrame {
JLabel lb1, lb2;
JTextField tf1;
JPasswordField pf1;
JButton btn1, btn2;
public Login() {
setTitle("学生管理系统-登录");
setSize(300, 200);
setLocationRelativeTo(null);
lb1 = new JLabel("用户名:");
lb2 = new JLabel("密码:");
tf1 = new JTextField();
pf1 = new JPasswordField();
btn1 = new JButton("登录");
btn2 = new JButton("取消");
JPanel p1 = new JPanel();
p1.setLayout(new GridLayout(2, 2));
p1.add(lb1);
p1.add(tf1);
p1.add(lb2);
p1.add(pf1);
JPanel p2 = new JPanel();
p2.setLayout(new FlowLayout());
p2.add(btn1);
p2.add(btn2);
setLayout(new BorderLayout());
add(p1, BorderLayout.CENTER);
add(p2, BorderLayout.SOUTH);
btn1.addActionListener(this);
btn2.addActionListener(this);
}
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == btn1) {
// 登录按钮被点击
String username = tf1.getText();
String password = new String(pf1.getPassword());
if (username.equals("admin") && password.equals("123456")) {
// 登录成功,打开主界面
new MainFrame();
dispose();
} else {
// 登录失败,弹出提示框
JOptionPane.showMessageDialog(this, "用户名或密码错误!");
}
} else if (e.getSource() == btn2) {
// 取消按钮被点击,关闭窗口
dispose();
}
}
public static void main(String[] args) {
Login frame = new Login();
frame.setVisible(true);
}
}
```
添加界面模块:
```java
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class AddFrame extends JFrame {
JLabel lb1, lb2, lb3, lb4, lb5, lb6;
JTextField tf1, tf2, tf3, tf4, tf5;
JButton btn1, btn2;
public AddFrame() {
setTitle("学生管理系统-添加");
setSize(400, 300);
setLocationRelativeTo(null);
lb1 = new JLabel("学号:");
lb2 = new JLabel("姓名:");
lb3 = new JLabel("性别:");
lb4 = new JLabel("出生日期:");
lb5 = new JLabel("籍贯:");
lb6 = new JLabel("所在院系:");
tf1 = new JTextField();
tf2 = new JTextField();
tf3 = new JTextField();
tf4 = new JTextField();
tf5 = new JTextField();
btn1 = new JButton("添加");
btn2 = new JButton("取消");
JPanel p1 = new JPanel();
p1.setLayout(new GridLayout(6, 2));
p1.add(lb1);
p1.add(tf1);
p1.add(lb2);
p1.add(tf2);
p1.add(lb3);
p1.add(tf3);
p1.add(lb4);
p1.add(tf4);
p1.add(lb5);
p1.add(tf5);
p1.add(lb6);
String[] deptList = {"计算机科学与技术", "信息工程", "物联网工程"};
JComboBox comboBox = new JComboBox>(deptList);
p1.add(comboBox);
JPanel p2 = new JPanel();
p2.setLayout(new FlowLayout());
p2.add(btn1);
p2.add(btn2);
setLayout(new BorderLayout());
add(p1, BorderLayout.CENTER);
add(p2, BorderLayout.SOUTH);
btn1.addActionListener(this);
btn2.addActionListener(this);
}
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == btn1) {
// 添加按钮被点击
String id = tf1.getText();
String name = tf2.getText();
String sex = tf3.getText();
String birth = tf4.getText();
String hometown = tf5.getText();
String dept = (String) comboBox.getSelectedItem();
// TODO: 将学生信息添加到数据库中
JOptionPane.showMessageDialog(this, "添加成功!");
} else if (e.getSource() == btn2) {
// 取消按钮被点击,关闭窗口
dispose();
}
}
public static void main(String[] args) {
AddFrame frame = new AddFrame();
frame.setVisible(true);
}
}
```
这两个类分别创建了一个登录界面和一个添加学生信息的界面。在实际应用中,您需要将用户名和密码的验证逻辑以及添加学生信息的逻辑与数据库进行交互。这里的代码仅用于演示目的,并未包含与数据库的实际交互代码。

热点内容
行车记录仪存储卡多大合适 发布:2025-02-05 09:35:21 浏览:109
oppo手机锁屏密码忘了怎么办 发布:2025-02-05 09:33:50 浏览:121
phprsa算法 发布:2025-02-05 09:33:48 浏览:228
快写编译器 发布:2025-02-05 09:29:15 浏览:587
java随机验证码 发布:2025-02-05 09:27:45 浏览:634
word打开密码怎么设置 发布:2025-02-05 09:26:58 浏览:975
核桃编程课导 发布:2025-02-05 09:25:36 浏览:496
编译内核源码 发布:2025-02-05 09:17:43 浏览:333
云计算与编程语言 发布:2025-02-05 09:13:17 浏览:654
Android三国杀 发布:2025-02-05 09:05:55 浏览:243