當前位置:首頁 » 編程語言 » java學生管理系統代碼

java學生管理系統代碼

發布時間: 2024-09-23 23:57:43

A. 誰能幫忙用java語言編一個學生管理系統,訪問access資料庫,實現插入,刪除,查詢

您好,提問者:
給你一個查詢access資料庫,然後到處到xls的例子吧。。。

//下面是代碼
importjava.io.FileWriter;
importjava.io.IOException;
importjava.sql.Connection;
importjava.sql.DriverManager;
importjava.sql.ResultSet;
importjava.sql.SQLException;
importjava.sql.Statement;


publicclassUtil{

publicstaticvoidmain(String[]args)throwsClassNotFoundException,SQLException,IOException{
StringdbUr1="jdbc:odbc:driver={MicrosoftAccessDriver(*.mdb)};DBQ=C:\體檢.mdb";
Stringuser="";
Stringpassword="";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connectionc=DriverManager.getConnection(dbUr1,user,password);
Statements=c.createStatement();
ResultSetr=s.executeQuery("SELECT病歷號,體檢日期,姓名,性別,年齡,家庭住址,郵政編碼,聯系電話"+"FROM體檢記錄表");
FileWriterfw=newFileWriter("C:\體檢統計.xls");
fw.write("病歷號 ");
fw.write("體檢日期 ");
fw.write("姓名 ");
fw.write("性別 ");
fw.write("年齡 ");
fw.write("家庭住址 ");
fw.write("郵政編碼 ");
fw.write("聯系電話 ");
while(r.next()){
fw.write(r.getString("病歷號")+" ");
fw.write(r.getString("體檢日期")+" ");
fw.write(r.getString("姓名")+" ");
fw.write(r.getString("性別")+" ");
fw.write(r.getString("年齡")+" ");
fw.write(r.getString("家庭住址")+" ");
fw.write(r.getString("郵政編碼")+" ");
fw.write(r.getString("聯系電話")+" ");
}
s.close();
fw.close();
}
}

//把需求中的體檢.mdb放入到C:根目錄,下面這是體檢.mdb的截圖

B. 用Java 實現一個簡單的學生管理系統! 求代碼,求代碼!!!!

完成了,希望能幫到你
剛開始會叫你輸入編號選擇功能
import java.io.*;

public class student {

public static void main(String args[]) throws IOException{

int[] stud = {77,99,55,46,82,75,65,31,74,85};

System.out.println("請選擇功能:");//輸入編號選擇功能
System.out.println("1、輸入學號,查詢該學生成績:");
System.out.println("2、輸入成績,查詢學生學號:");
System.out.println("3、輸入學號,刪除該學生成績");
System.out.println("請選擇編號:");

BufferedReader td = new BufferedReader(new InputStreamReader(System.in));

String temp = td.readLine();

int choice = Integer.valueOf(temp);

if(choice == 1){//一為查詢學生成績

System.out.println("請輸入學號:");

BufferedReader sd = new BufferedReader(new InputStreamReader(System.in));

String temp_sd = sd.readLine();

int No = Integer.valueOf(temp_sd);

System.out.print("學號為 "+No+" 的學生成績為: " + stud[No-1] +"分");
}

if(choice == 2){//二為查詢學生編號

System.out.println("請輸入成績:");

BufferedReader sd = new BufferedReader(new InputStreamReader(System.in));

String chengji = sd.readLine();

int temp_cj = Integer.valueOf(chengji);

for(int i=0;i<stud.length;i++){

if(temp_cj == stud[i]){

System.out.print("成績為 "+ temp_cj+ "的學生的學號為: "+(i+1));

}
}
}
if(choice == 3){//三為刪除操作

System.out.println("請輸入學號:");

BufferedReader sd = new BufferedReader(new InputStreamReader(System.in));

String temp_sd = sd.readLine();

int No = Integer.valueOf(temp_sd);

stud[No-1]=0;//直接賦值為0,不刪除學生

System.out.print("學號為 "+No+" 的學生成績為: " + stud[No-1] +"分");
}

}
}

C. 怎麼用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循環來遍歷操作,方便快捷。

D. 急求java學生信息管理系統源代碼,帶有連接資料庫的,萬分感謝

import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.Container;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JToolBar;
import javax.swing.SwingConstants;
public class MainFrame extends JFrame implements ActionListener{
InsertPanel ip = null;
SelectPanel sp = null;
JPanel pframe;
JButton jb1,jb2,jb3;
JMenuItem jm11,jm21,jm22,jm23,jm31,jm32,jm41,jm42;
CardLayout clayout;
public MainFrame(String s){
super(s);
JMenuBar mb = new JMenuBar();
this.setJMenuBar(mb);
JMenu m1 = new JMenu("系統");
JMenu m2 = new JMenu("基本信息");
JMenu m3 = new JMenu("成績");
JMenu m4 = new JMenu("獎懲");
mb.add(m1);
mb.add(m2);
mb.add(m3);
mb.add(m4);
jm11 = new JMenuItem("退出系統");
jm21 = new JMenuItem("輸入");
jm22 = new JMenuItem("查詢");
jm23 = new JMenuItem("更改");
jm31 = new JMenuItem("輸入成績");
jm32 = new JMenuItem("查詢成績");
jm41 = new JMenuItem("獎勵");
jm42 = new JMenuItem("處分");
m1.add(jm11);
m2.add(jm21);
m2.add(jm22);
m2.add(jm23);
m3.add(jm31);
m3.add(jm32);
m4.add(jm41);
m4.add(jm42);
Icon i1 = new ImageIcon();
Icon i2 = new ImageIcon();
Icon i3 = new ImageIcon();
jb1 = new JButton(i1);
jb1.setToolTipText("輸入");
jb2 = new JButton(i2);
jb2.setToolTipText("查詢");
jb3 = new JButton(i3);
jb3.setToolTipText("退出");
JToolBar tb = new JToolBar("系統工具");
tb.add(jb1);
tb.add(jb2);
tb.add(jb3);
add(tb,BorderLayout.NORTH);
jm11.addActionListener(this);
jm21.addActionListener(this);
jm22.addActionListener(this);
jb1.addActionListener(this);
jb2.addActionListener(this);
jb3.addActionListener(this);
clayout = new CardLayout();
pframe = new JPanel(clayout);
add(pframe);
JPanel mainp = new JPanel(new BorderLayout());
JLabel mainl = new JLabel("學生信息管理平台",SwingConstants.CENTER);
mainl.setFont(new Font("serif",Font.BOLD,30));
mainp.add(mainl);
pframe.add(mainp,"main");
clayout.show(pframe, "main");
}
public void actionPerformed(ActionEvent e){
if(e.getSource() == jm21 || e.getSource() == jb1){
if(ip == null){
ip= new InsertPanel();
pframe.add(ip,"insert");
}
clayout.show(pframe, "insert");
this.setTitle("輸入學生信息");
}
else if(e.getSource() == jm22 || e.getSource() == jb2){
if(sp == null){
sp= new SelectPanel();
pframe.add(sp,"select");
}
clayout.show(pframe, "select");
this.setTitle("查詢學生信息");
}
else if(e.getSource() == jm11 || e.getSource() == jb3){
System.exit(0);
}
}
}
第二個:
import javax.swing.JFrame;
public class MainTest {
public static void main(String [] args){
MainFrame f = new MainFrame("學生信息管理平台");
f.setSize(400,300);
f.setLocation(350,250);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
}
}
第二個:
import java.sql.Connection;
import java.sql.DriverManager;
public class MySQLConnection {
static Connection getCon(){
Connection con = null;
try{
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost/test","root","123");
}
catch(Exception e){
System.out.println("建立資料庫連接遇到異常!");
}
return con;
}
}
第四個:
import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
public class SelectPanel extends JPanel implements ActionListener{
JButton jb;
JTextField jt;
JTextField jt1,jt2,jt3,jt4;
public SelectPanel(){
JLabel jl = new JLabel("請輸入學號:",SwingConstants.CENTER);
jt = new JTextField();
jb = new JButton("確定");
JPanel jp1 = new JPanel(new GridLayout(1,3));
jp1.add(jl);
jp1.add(jt);
jp1.add(jb);
JLabel j1,j2,j3,j4;
j1 = new JLabel("學號:",SwingConstants.CENTER);
j2 = new JLabel("姓名:",SwingConstants.CENTER);
j3 = new JLabel("性別:",SwingConstants.CENTER);
j4 = new JLabel("年齡:",SwingConstants.CENTER);
jt1 = new JTextField(6);
jt1.setEditable(false);
jt2 = new JTextField(6);
jt2.setEditable(false);
jt3 = new JTextField(6);
jt3.setEditable(false);
jt4 = new JTextField(6);
jt4.setEditable(false);
JPanel jp2 = new JPanel(new BorderLayout());
JPanel jp3 = new JPanel(new GridLayout(4,2));
jp2.add(new JLabel(""),BorderLayout.NORTH);
jp3.add(j1);
jp3.add(jt1);
jp3.add(j2);
jp3.add(jt2);
jp3.add(j3);
jp3.add(jt3);
jp3.add(j4);
jp3.add(jt4);
jp2.add(jp3);
this.setLayout(new BorderLayout());
add(jp1,BorderLayout.NORTH);
add(jp2);
jb.addActionListener(this);
}
public void actionPerformed(ActionEvent e){
if(e.getSource() == jb){
String stuNo = jt.getText().trim();
Student s = new Student();
boolean b = true;
try{
b = s.selectByStuNo(stuNo);
}
catch(Exception ex){
System.out.println("查詢學生信息遇到異常!");
}
if(b){
jt1.setText(s.getStuNo());
jt2.setText(s.getName());
jt3.setText(s.getGender());
int a = s.getAge();
Integer i = new Integer(a);
jt4.setText(i.toString());
}
else{
JOptionPane.showMessageDialog(null, "無此學生!");
}
}
}

}
第五個:
import javax.swing.JFrame;
public class SelectTest {
public static void main(String [] args){
JFrame f = new JFrame("查詢學生信息");
SelectPanel p = new SelectPanel();
f.add(p);
f.setSize(400,300);
f.setLocation(300,250);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
}
}
第六個:
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
public class Student {
String stuNo;
String name;
String gender;
int age;
public Student(){}
public Student(String stuNo,String name,String gender, int age){
this.stuNo = stuNo;
this.name = name;
this.gender = gender;
this.age = age;
}
public String getStuNo(){
return stuNo;
}
public void setStuNo(String stuNo){
this.stuNo = stuNo;
}
public String getName(){
return name;
}
public void setName(String name){
this.name = name;
}
public String getGender(){
return gender;
}
public void setGender(String gender){
this.gender = gender;
}
public int getAge(){
return age;
}
public void setAge(int age){
this.age = age;
}
public boolean insertStudent(){
boolean b = true;
try{
Connection con = MySQLConnection.getCon();
Statement statement = con.createStatement();
String sql = "insert into student values('" + stuNo + "','" + name +"','" + gender + "'," + age + ")";
sql = new String(sql.getBytes("gb2312"),"ISO8859_1");
statement.executeUpdate(sql);
con.close();
}
catch(Exception e){
b = false;
System.out.println("插入資料庫遇到異常!");
}
return b;
}
public boolean selectByStuNo(String stuNo)throws Exception{
boolean b = true;
Connection con = MySQLConnection.getCon();
Statement statement = con.createStatement();
String sql = "select * from student where stuNo =" + stuNo;
ResultSet rs = statement.executeQuery(sql);
if(rs != null && rs.next()){
String no = rs.getString(1);
this.setStuNo(no);
String n = rs.getString(2);
n = new String(n.getBytes("ISO8859_1"),"gb2312");
this.setName(n);
String g = rs.getString(3);
g = new String (g.getBytes("ISO8859_1"),"gb2312");
this.setGender(g);
this.setAge(rs.getInt(4));
b = true;
}
rs.close();
statement.close();
con.close();
return b;
}
}
資料庫你自己弄吧,我沒時間弄了!初學得多動手哦

E. 學生考試管理系統,JAva源代碼

//主類EnglishTest——

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class EnglishTest extends JFrame
{
TestArea testPanel=null;
Container con=null;
public EnglishTest()
{
super("模擬考試");
testPanel=new TestArea();
con=getContentPane();
con.add(testPanel,BorderLayout.CENTER);
addWindowListener(new WindowAdapter()
{ public void windowClosing(WindowEvent e)
{ System.exit(0);
}
});
setVisible(true);
setBounds(60,40,660,460);
con.validate();
validate();
}
public static void main(String args[])
{
new EnglishTest();
}
}

//讀取試題 ReadTestquestion

import java.io.*;
import java.util.*;
public class ReadTestquestion
{ String filename="",
correctAnswer="",
testContent="" ,
selection="" ;
int score=0;
long time=0;
boolean 完成考試=false;
File f=null;
FileReader in=null;
BufferedReader 讀取=null;
public void setFilename(String name)
{ filename=name;

score=0;
selection="";
try {
if(in!=null&&讀取!=null)
{
in.close();
讀取.close();
}
f=new File(filename);
in=new FileReader(f);
讀取=new BufferedReader(in);
correctAnswer=(讀取.readLine()).trim();
String temp=(讀取.readLine()).trim() ;
StringTokenizer token=new StringTokenizer(temp,":");
int hour=Integer.parseInt(token.nextToken()) ;
int minute=Integer.parseInt(token.nextToken());
int second=Integer.parseInt(token.nextToken());
time=1000*(second+minute*60+hour*60*60);

}
catch(Exception e)
{
testContent="沒有選擇試題";
}
}
public String getFilename()
{
return filename;
}
public long getTime()
{
return time;
}
public void set完成考試(boolean b)
{
完成考試=b;
}
public boolean get完成考試()
{
return 完成考試;
}
public String getTestContent()
{ try {
String s=null;
StringBuffer temp=new StringBuffer();
if(讀取!=null)
{
while((s=讀取.readLine())!=null)
{
if(s.startsWith("**"))
break;
temp.append("\n"+s);
if(s.startsWith("endend"))
{
in.close();
讀取.close();
完成考試=true;
}
}
testContent=new String(temp);
}
else
{
testContent=new String("沒有選擇試題");
}
}
catch(Exception e)
{
testContent="試題內容為空,考試結束!!";
}
return testContent;
}
public void setSelection(String s)
{
selection=selection+s;
}
public int getScore()
{ score=0;
int length1=selection.length();
int length2=correctAnswer.length();
int min=Math.min(length1,length2);
for(int i=0;i<min;i++)
{ try{
if(selection.charAt(i)==correctAnswer.charAt(i))
score++;
}
catch( e)
{
i=0;
}
}
return score;
}20:10 03-8-31
public String getMessages()
{
int length1=selection.length();
int length2=correctAnswer.length();
int length=Math.min(length1,length2);
String message="正確答案:"+correctAnswer.substring(0,length)+"\n"+
"你的回答:"+selection+"\n";
return message;
}

}

//考試區域TestArea

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.io.*;
class FileName implements FilenameFilter
{
String str=null;
FileName (String s)
{
str="."+s;
}
public boolean accept(File dir,String name)
{
return name.endsWith(str);
}
}
public class TestArea extends JPanel implements ActionListener,ItemListener,Runnable
{
Choice list=null;
JTextArea 試題顯示區=null,消息區=null;
JCheckBox box[];
JButton 提交該題答案,讀取下一題,查看分數;
ReadTestquestion 讀取試題=null;
JLabel welcomeLabel=null;
Thread countTime=null;
long time=0;
JTextField timeShow=null;
boolean 是否關閉計時器=false,
是否暫停計時=false;
JButton 暫停或繼續計時=null;
public TestArea()
{
list= new Choice();
String 當前目錄=System.getProperty("user.dir");
File dir=new File(當前目錄);
FileName fileTxt=new FileName("txt");
String fileName[]=dir.list(fileTxt);
for(int i=0;i<fileName.length;i++)
{
list.add(fileName[i]);
}

試題顯示區=new JTextArea(15,12);
試題顯示區.setLineWrap(true);
試題顯示區.setWrapStyleWord(true);
試題顯示區.setFont(new Font("TimesRoman",Font.PLAIN,14));
試題顯示區.setForeground(Color.blue);
消息區=new JTextArea(8,8);
消息區.setForeground(Color.blue);
消息區.setLineWrap(true);
消息區.setWrapStyleWord(true);

countTime=new Thread(this);
String s[]={"A","B","C","D"};
box=new JCheckBox[4];
for(int i=0;i<4;i++)
{
box[i]=new JCheckBox(s[i]);
}
暫停或繼續計時=new JButton("暫停計時");
暫停或繼續計時.addActionListener(this);
提交該題答案=new JButton("提交該題答案");
讀取下一題=new JButton("讀取第一題");
讀取下一題.setForeground(Color.blue);
提交該題答案.setForeground(Color.blue);
查看分數=new JButton("查看分數");
查看分數.setForeground(Color.blue);
提交該題答案.setEnabled(false);
提交該題答案.addActionListener(this);
讀取下一題.addActionListener(this);
查看分數.addActionListener(this);
list.addItemListener(this);
讀取試題=new ReadTestquestion();
JPanel pAddbox=new JPanel();
for(int i=0;i<4;i++)
{
pAddbox.add(box[i]);
}
Box boxH1=Box.createVerticalBox(),
boxH2=Box.createVerticalBox(),
baseBox=Box.createHorizontalBox();
boxH1.add(new JLabel("選擇試題文件"));
boxH1.add(list);
boxH1.add(new JScrollPane(消息區));
boxH1.add(查看分數);
timeShow=new JTextField(20);
timeShow.setHorizontalAlignment(SwingConstants.RIGHT);
timeShow.setEditable(false);
JPanel p1=new JPanel();
p1.add(new JLabel("剩餘時間:"));
p1.add(timeShow);
p1.add(暫停或繼續計時);
boxH1.add(p1);
boxH2.add(new JLabel("試題內容:"));
boxH2.add(new JScrollPane(試題顯示區));
JPanel p2=new JPanel();
p2.add(pAddbox);
p2.add(提交該題答案);
p2.add(讀取下一題);
boxH2.add(p2);
baseBox.add(boxH1);
baseBox.add(boxH2);
setLayout(new BorderLayout());
add(baseBox,BorderLayout.CENTER);
welcomeLabel=new JLabel("歡迎考試,提高英語水平",JLabel.CENTER);
welcomeLabel.setFont(new Font("隸書",Font.PLAIN,24));
welcomeLabel.setForeground(Color.blue);
add(welcomeLabel,BorderLayout.NORTH);

}
public void itemStateChanged(ItemEvent e)
{
timeShow.setText(null);
是否關閉計時器=false;
是否暫停計時=false;
暫停或繼續計時.setText("暫停計時");
String name=(String)list.getSelectedItem();
讀取試題.setFilename(name);
讀取試題.set完成考試(false);
time=讀取試題.getTime();
if(countTime.isAlive())
{
是否關閉計時器=true;
countTime.interrupt();
}
countTime=new Thread(this);

消息區.setText(null);
試題顯示區.setText(null);
讀取下一題.setText("讀取第一題");
提交該題答案.setEnabled(false);
讀取下一題.setEnabled(true);
welcomeLabel.setText("歡迎考試,你選擇的試題:"+讀取試題.getFilename());
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==讀取下一題)
{
讀取下一題.setText("讀取下一題");
提交該題答案.setEnabled(true);
String contentTest=讀取試題.getTestContent();
試題顯示區.setText(contentTest);
消息區.setText(null);
讀取下一題.setEnabled(false);
try {
countTime.start();
}
catch(Exception event)
{

}
}
if(e.getSource()==提交該題答案)
{
讀取下一題.setEnabled(true);
提交該題答案.setEnabled(false);
String answer="?";
for(int i=0;i<4;i++)
{
if(box[i].isSelected())
{
answer=box[i].getText();
box[i].setSelected(false);
break;
}
}
讀取試題.setSelection(answer);
}
if(e.getSource()==查看分數)
{
int score=讀取試題.getScore();
String messages=讀取試題.getMessages();
消息區.setText("分數:"+score+"\n"+messages);
}
if(e.getSource()==暫停或繼續計時)
{
if(是否暫停計時==false)
{
暫停或繼續計時.setText("繼續計時");
是否暫停計時=true;
}
else if(是否暫停計時==true)
{
暫停或繼續計時.setText("暫停計時");
是否暫停計時=false;
countTime.interrupt();
}
}
}
public synchronized void run()
{
while(true)
{
if(time<=0)
{
是否關閉計時器=true;
countTime.interrupt();
提交該題答案.setEnabled(false);
讀取下一題.setEnabled(false);
timeShow.setText("用時盡,考試結束");
}
else if(讀取試題.get完成考試())
{
是否關閉計時器=true;
timeShow.setText("考試效果:分數*剩餘時間(秒)="+1.0*讀取試題.getScore()*(time/1000));
countTime.interrupt();
提交該題答案.setEnabled(false);
讀取下一題.setEnabled(false);

}
else if(time>=1)
{
time=time-1000;
long leftTime=time/1000;
long leftHour=leftTime/3600;
long leftMinute=(leftTime-leftHour*3600)/60;
long leftSecond=leftTime%60;
timeShow.setText(""+leftHour+"小時"+leftMinute+"分"+leftSecond+"秒");
}
try
{
Thread.sleep(1000);
}
catch(InterruptedException ee)
{
if(是否關閉計時器==true)
return ;
}
while(是否暫停計時==true)
{
try
{
wait();
}
catch(InterruptedException ee)
{
if(是否暫停計時==false)
{
notifyAll();
}
}
}
}
}

}

F. 用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();
}
}

熱點內容
導出手機中緩存的視頻 發布:2024-09-24 03:10:07 瀏覽:679
劍俠情緣腳本軟體 發布:2024-09-24 02:58:45 瀏覽:451
sql2000win764位 發布:2024-09-24 02:53:34 瀏覽:581
雲南昆明企業伺服器雲主機 發布:2024-09-24 02:49:21 瀏覽:337
塊存儲格式 發布:2024-09-24 02:31:37 瀏覽:687
linux中查看文件 發布:2024-09-24 02:31:31 瀏覽:858
兒童編程下載 發布:2024-09-24 02:03:56 瀏覽:689
iis訪問量 發布:2024-09-24 02:03:16 瀏覽:719
微信在手機文件夾叫什麼名字叫什麼 發布:2024-09-24 01:58:25 瀏覽:691
絕地求生亞服的安卓手機怎麼玩 發布:2024-09-24 01:53:57 瀏覽:124