學生信息管理系統java
① 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
③ 用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);
}
}
```
這兩個類分別創建了一個登錄界面和一個添加學生信息的界面。在實際應用中,您需要將用戶名和密碼的驗證邏輯以及添加學生信息的邏輯與資料庫進行交互。這里的代碼僅用於演示目的,並未包含與資料庫的實際交互代碼。