A. 求畢業設計及論文「基於java的學生信息管理系統的設計與實現」
僅僅給你個參考
//Java Group Project_StudentManagement源碼
//NetBeans IDE 6.5 環境
package studentmanager;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
import java.util.*;
class Student implements java.io.Serializable{
String number,name,specialty,grade,borth,sex;
public Student(){};
public void setNumber(String number){ this.number=number;}
public String getNumber(){ return number;}
public void setName(String name){ this.name=name;}
public String getName(){ return name;}
public void setSex(String sex){ this.sex=sex;}
public String getSex(){ return sex;}
public void setSpecialty(String specialty){ this.specialty=specialty;}
public String getSpecialty(){ return specialty;}
public void setGrade(String grade){ this.grade=grade;}
public String getGrade(){ return grade;}
public void setBorth(String borth){ this.borth=borth;}
public String getBorth(){ return borth;}
}
public class StudentManager extends JFrame{
JLabel lb=new JLabel("錄清襪入請先輸入記錄,查詢、刪除請先輸入學號,修改是對查詢" +
"內容改後的保存!");
JTextField 學號,姓名,專業,年級,出生;
JRadioButton 男,女;
ButtonGroup group=null;
JButton 錄入,查詢,刪除,修改,顯示;
JPanel p1,p2,p3,p4,p5,p6,pv,ph;
Student 學生=null;
Hashtable 學生散列表=null;
File file=null;
FileInputStream inOne=null;
ObjectInputStream inTwo=null;
FileOutputStream outOne=null;
肆正此ObjectOutputStream outTwo=null;
public StudentManager(){
super("學生基本信息管理系統");
學號=new JTextField(10);
姓名=new JTextField(10);
專業=new JTextField(10);
年級=new JTextField(10);
出生=new JTextField(10);
group=new ButtonGroup();
男=new JRadioButton("男",true);
女=new JRadioButton("女",false);
group.add(男);
group.add(女);
錄入=new JButton("錄入");
查詢=new JButton("查詢");
刪除=new JButton("刪除");
修改=new JButton("修改");
顯示=new JButton("顯示");
錄裂迅入.addActionListener(new InputAct());
查詢.addActionListener(new InquestAct());
修改.addActionListener(new ModifyAct());
刪除.addActionListener(new DeleteAct());
顯示.addActionListener(new ShowAct());
修改.setEnabled(false);
p1=new JPanel();
p1.add(new JLabel("學號:",JLabel.CENTER));
p1.add(學號);
p2=new JPanel();
p2.add(new JLabel("姓名:",JLabel.CENTER));
p2.add(姓名);
p3=new JPanel();
p3.add(new JLabel("性別:",JLabel.CENTER));
p3.add(男);
p3.add(女);
p4=new JPanel();
p4.add(new JLabel("專業:",JLabel.CENTER));
p4.add(專業);
p5=new JPanel();
p5.add(new JLabel("年級:",JLabel.CENTER));
p5.add(年級);
p6=new JPanel();
p6.add(new JLabel("出生:",JLabel.CENTER));
p6.add(出生);
pv=new JPanel();
pv.setLayout(new GridLayout(6,1));
pv.add(p1);
pv.add(p2);
pv.add(p3);
pv.add(p4);
pv.add(p5);
pv.add(p6);
ph=new JPanel();
ph.add(錄入);
ph.add(查詢);
ph.add(修改);
ph.add(刪除);
ph.add(顯示);
file=new File("學生信息.txt");
學生散列表=new Hashtable();
if(!file.exists()){
try{
FileOutputStream out=new FileOutputStream(file);
ObjectOutputStream objectOut=new ObjectOutputStream(out);
objectOut.writeObject(學生散列表);
objectOut.close();
out.close();
}
catch(IOException e){}
}
Container con=getContentPane();
con.setLayout(new BorderLayout());
con.add(lb, BorderLayout.NORTH);
con.add(pv, BorderLayout.CENTER);
con.add(ph, BorderLayout.SOUTH);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setBounds(100,100,600,300);
setVisible(true);
}
public static void main(String[] args) {new StudentManager();}
class InputAct implements ActionListener{
public void actionPerformed(ActionEvent e){
修改.setEnabled(false);
String number="";
number=學號.getText();
if(number.length()>0){
try{
inOne=new FileInputStream(file);
inTwo=new ObjectInputStream(inOne);
學生散列表=(Hashtable)inTwo.readObject();
inOne.close();
inTwo.close();
}
catch(Exception ee){System.out.println("創建散列表出現問題!");}
if(學生散列表.containsKey(number)){
String warning="該生信息已存在,請到修改頁面修改!";
JOptionPane.showMessageDialog(null,warning,"警告",
JOptionPane.WARNING_MESSAGE);
}//end if1
else{
String m="該生信息將被錄入!";
int ok=JOptionPane.showConfirmDialog(null,m,"確認",
JOptionPane.YES_NO_OPTION,JOptionPane.INFORMATION_MESSAGE);
if(ok==JOptionPane.YES_OPTION){
String name=姓名.getText();
String specialty=專業.getText();
String grade=年級.getText();
String borth=出生.getText();
String sex=null;
if(男.isSelected()){sex=男.getText();}
else{sex=女.getText();}
學生=new Student();
學生.setNumber(number);
學生.setName(name);
學生.setSpecialty(specialty);
學生.setGrade(grade);
學生.setBorth(borth);
學生.setSex(sex);
try{
outOne=new FileOutputStream(file);
outTwo=new ObjectOutputStream(outOne);
學生散列表.put(number,學生);
outTwo.writeObject(學生散列表);
outTwo.close();
outOne.close();
}
catch(Exception ee){System.out.println("輸出散列表出現問題!");}
學號.setText(null);
姓名.setText(null);
專業.setText(null);
年級.setText(null);
出生.setText(null);
}
}//end else1
}//end if0
else{
String warning="必須輸入學號!";
JOptionPane.showMessageDialog(null,warning,
"警告",JOptionPane.WARNING_MESSAGE);
}//end else0
}//end actionPerformed
}//end class
class InquestAct implements ActionListener{
public void actionPerformed(ActionEvent e){
String number="";
number=學號.getText();
if(number.length()>0){
try{
inOne=new FileInputStream(file);
inTwo=new ObjectInputStream(inOne);
學生散列表=(Hashtable)inTwo.readObject();
inOne.close();
inTwo.close();
}
catch(Exception ee){System.out.println("散列表有問題!");}
if(學生散列表.containsKey(number)){
修改.setEnabled(true);
Student stu=(Student)學生散列表.get(number);
姓名.setText(stu.getName());
專業.setText(stu.getSpecialty());
年級.setText(stu.getGrade());
出生.setText(stu.getBorth());
if(stu.getSex().equals("男")){男.setSelected(true);}
else{女.setSelected(true);}
}
else{
修改.setEnabled(false);
String warning="該學號不存在!";
JOptionPane.showMessageDialog(null,warning,
"警告",JOptionPane.WARNING_MESSAGE);
}
}
else{
修改.setEnabled(false);
String warning="必須輸入學號!";
JOptionPane.showMessageDialog(null,warning,
"警告",JOptionPane.WARNING_MESSAGE);
}
}
}
class ModifyAct implements ActionListener{
public void actionPerformed(ActionEvent e){
String number=學號.getText();
String name=姓名.getText();
String specialty=專業.getText();
String grade=年級.getText();
String borth=出生.getText();
String sex=null;
if(男.isSelected()){sex=男.getText();}
else{sex=女.getText();}
Student 學生=new Student();
學生.setNumber(number);
學生.setName(name);
學生.setSpecialty(specialty);
學生.setGrade(grade);
學生.setBorth(borth);
學生.setSex(sex);
try{
outOne=new FileOutputStream(file);
outTwo=new ObjectOutputStream(outOne);
學生散列表.put(number, 學生);
outTwo.writeObject(學生散列表);
outTwo.close();
outOne.close();
學號.setText(null);
姓名.setText(null);
專業.setText(null);
年級.setText(null);
出生.setText(null);
}
catch(Exception ee){
System.out.println("錄入修改出現異常!");
修改.setEnabled(false);
}
}
}
class DeleteAct implements ActionListener{
public void actionPerformed(ActionEvent e){
修改.setEnabled(false);
String number=學號.getText();
if(number.length()>0){
try{
inOne=new FileInputStream(file);
inTwo=new ObjectInputStream(inOne);
學生散列表=(Hashtable)inTwo.readObject();
inOne.close();
inTwo.close();
}
catch(Exception ee){}
if(學生散列表.containsKey(number)){
Student stu=(Student)學生散列表.get(number);
姓名.setText(stu.getName());
專業.setText(stu.getSpecialty());
年級.setText(stu.getGrade());
出生.setText(stu.getBorth());
if(stu.getSex().equals("男")){男.setSelected(true);}
else{女.setSelected(true);}
}
String m="確定要刪除該學生的記錄嗎?";
int ok=JOptionPane.showConfirmDialog(null,m,"確認",
JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE);
if(ok==JOptionPane.YES_OPTION){
學生散列表.remove(number);
try{
outOne=new FileOutputStream(file);
outTwo=new ObjectOutputStream(outOne);
outTwo.writeObject(學生散列表);
outTwo.close();
outOne.close();
學號.setText(null);
姓名.setText(null);
專業.setText(null);
年級.setText(null);
出生.setText(null);
}
catch(Exception ee){System.out.println(ee);}
}
else if(ok==JOptionPane.NO_OPTION){
學號.setText(null);
姓名.setText(null);
專業.setText(null);
年級.setText(null);
出生.setText(null);
}
else{
String warning="該學號不存在!";
JOptionPane.showMessageDialog(null,warning,
"警告",JOptionPane.WARNING_MESSAGE);
}
}
else{
String warning="必須輸入學號!";
JOptionPane.showMessageDialog(null,warning,
"警告",JOptionPane.WARNING_MESSAGE);
}
}
}
class ShowAct implements ActionListener{
public void actionPerformed(ActionEvent e){
new StudentShow(file);
}
}
class StudentShow extends JDialog{
Hashtable 學生散列表= null;
JTextArea 顯示=null;
FileInputStream inOne=null;
ObjectInputStream inTwo=null;
File file=null;
public StudentShow(File file){
super(new JFrame(),"顯示對話框");
this.file=file;
顯示=new JTextArea(16,30);
try{
inOne=new FileInputStream(file);
inTwo=new ObjectInputStream(inOne);
學生散列表=(Hashtable)inTwo.readObject();
inOne.close();
inTwo.close();
}
catch(Exception ee){}
if(學生散列表.isEmpty())顯示.append("目前還沒有學生的信息記錄!\n");
else{
顯示.setText("學號 姓名 性別 專業 年級 出生\n");
for(Enumeration enm=學生散列表.elements();enm.hasMoreElements();){
Student stu=(Student)enm.nextElement();
String sex="";
if(stu.getSex().equals("男"))sex="男";
else sex="女";
String str=stu.getNumber()+","+stu.getName()+","+sex+","
+stu.getSpecialty()+","+stu.getGrade()+","+stu.getBorth()+"\n";
顯示.append(str);
}
}
JScrollPane scroll=new JScrollPane(顯示);
Container con=getContentPane();
con.add("Center",scroll);
con.validate();
setVisible(true);
setBounds(200,200,400,300);
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){setVisible(false);}
}
);
}
}
}
B. 高分求兩個簡單的JAVA設計源代碼
上面 wukun12同學寫的不錯,但我想還不能運行,並且還不太完善。我給個能運行的:(注意:文件名為:Test.java)
//要實現對象間的比較,就必須實現Comparable介面,它裡面有個compareTo方法
//Comparable最好使用泛型,這樣,無論是速度還是代碼量都會減少
@SuppressWarnings("unchecked")
class Student implements Comparable<Student>{
private String studentNo; //學號
private String studentName; //姓名
private double englishScore; //英語成績
private double computerScore; //計算機成績
private double mathScore; //數學成績
private double totalScore; //總成績
//空構造函數
public Student() {}
//構造函數
public Student(String studentNo,String studentName,double englishSocre,double computerScore,double mathScore) {
this.studentNo = studentNo;
this.studentName = studentName;
this.englishScore = englishSocre;
this.computerScore = computerScore;
this.mathScore = mathScore;
}
//計算總成績
public double sum() {
this.totalScore = englishScore+computerScore+mathScore;
return totalScore;
}
//計算評測成績
public double testScore() {
return sum()/3;
}
//實現compareTO方法
@Override
public int compareTo(Student student) {
double studentTotal = student.getTotalScore();
return totalScore==studentTotal?0:(totalScore>studentTotal?1:-1);
}
//重寫toString方法
public String toString(){
return "學號:"+this.getStudentNo()+" 姓名:"+this.getStudentName()+" 英語成績:"+this.getEnglishScore()+" 數學成績:"+this.getMathScore()+" 計算機成績:"+this.getComputerScore()+" 總成績:"+this.getTotalScore();
}
//重寫equals方法
public boolean equals(Object obj) {
if(obj == null){
return false;
}
if(!(obj instanceof Student)){
return false;
}
Student student = (Student)obj;
if(this.studentNo.equals(student.getStudentName())) { //照現實來說,比較是不是同一個學生,應該只是看他的學號是不是相同
return true;
} else {
return false;
}
}
/*以下為get和set方法,我個人認為,totalScore的set的方法沒必要要,因為它是由其它成績計算出來的
在set方法中,沒設置一次值,調用一次sum方法,即重新計算總成績
*/
public String getStudentNo() {
return studentNo;
}
public void setStudentNo(String studentNo) {
this.studentNo = studentNo;
sum();
}
public String getStudentName() {
return studentName;
}
public void setStudentName(String studentName) {
this.studentName = studentName;
sum();
}
public double getEnglishScore() {
return englishScore;
}
public void setEnglishScore(double englishScore) {
this.englishScore = englishScore;
sum();
}
public double getComputerScore() {
return computerScore;
}
public void setComputerScore(double computerScore) {
this.computerScore = computerScore;
sum();
}
public double getMathScore() {
return mathScore;
}
public void setMathScore(double mathScore) {
this.mathScore = mathScore;
sum();
}
public double getTotalScore() {
return totalScore;
}
}
//Student子類學習委員類的實現
class StudentXW extends Student {
//重寫父類Student的testScore()方法
@Override
public double testScore() {
return sum()/3+3;
}
public StudentXW() {}
//StudentXW的構造函數
public StudentXW(String studentNo,String studentName,double englishSocre,double computerScore,double mathScore) {
super(studentNo,studentName,englishSocre,computerScore,mathScore);
}
}
//Student子類班長類的實現
class StudentBZ extends Student {
//重寫父類Student的testScore()方法
@Override
public double testScore() {
return sum()/3+5;
}
public StudentBZ() {}
//StudentXW的構造函數
public StudentBZ(String studentNo,String studentName,double englishSocre,double computerScore,double mathScore) {
super(studentNo,studentName,englishSocre,computerScore,mathScore);
}
}
//測試類
public class Test {
public static void main(String[] args) {
//生成若干個student類、StudentXW類、StudentBZ類
Student student1 = new Student("s001","張三",70.5,50,88.5);
Student student2 = new Student("s002","李四",88,65,88.5);
Student student3 = new Student("s003","王五",67,77,90);
StudentXW student4 = new StudentXW("s004","李六",99,88,99.5);
StudentBZ student5 = new StudentBZ("s005","朱漆",56,65.6,43.5);
Student[] students = {student1,student2,student3,student4,student5};
for(int i = 0 ; i<students.length; i++){
double avgScore = students[i].testScore();
System.out.println(students[i].getStudentName()+"學生的評測成績為:"+ avgScore+"分");
}
}
}
運行結果為:
張三學生的評測成績為:69.66666666666667分
李四學生的評測成績為:80.5分
王五學生的評測成績為:78.0分
李六學生的評測成績為:98.5分
朱漆學生的評測成績為:60.03333333333333分
C. 用java web小游戲源代碼。期末結課老師讓做,急用,謝了
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Toolkit;
import javax.swing.JFrame;
@SuppressWarnings("serial")
public class MainClass extends JFrame {
ControlSnake control;
Toolkit kit;
Dimension dimen;
public static void main(String[] args) {
new MainClass("my snake");
}
public MainClass(String s) {
super(s);
control = new ControlSnake();
control.setFocusable(true);
kit = Toolkit.getDefaultToolkit();
dimen = kit.getScreenSize();
add(control);
setLayout(new BorderLayout());
setLocation(dimen.width / 3, dimen.height / 3);// dimen.width/3,dimen.height/3
setSize(FWIDTH, FHEIGHT);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setResizable(false);
setVisible(true);
}
public static final int FWIDTH = 315;
public static final int FHEIGHT = 380;
}
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.util.ArrayList;
import java.util.Random;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.Timer;
@SuppressWarnings("serial")
public class ControlSnake extends JPanel implements ActionListener {
Random rand;
ArrayList<Point> list, listBody;
String str, str1;
static boolean key;
int x, y, dx, dy, fx, fy, flag;
int snakeBody;
int speed;
public ControlSnake() {
snakeBody = 1;
str = "上下左右方向鍵控制 P鍵暫停...";
str1 = "現在的長度為:" + snakeBody;
key = true;
flag = 1;
speed = 700;
rand = new Random();
list = new ArrayList<Point>();
listBody = new ArrayList<Point>();
x = 5;
y = 5;
list.add(new Point(x, y));
listBody.add(list.get(0));
dx = 10;
dy = 0;
fx = rand.nextInt(30) * 10 + 5;// 2
fy = rand.nextInt(30) * 10 + 5;// 2
setBackground(Color.BLACK);
setSize(new Dimension(318, 380));
final Timer time = new Timer(speed, this);
time.start();
addKeyListener(new KeyAdapter(){
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == 37) {
dx = -10;
dy = 0;
} else if (e.getKeyCode() == 38) {
dx = 0;
dy = -10;
} else if (e.getKeyCode() == 39) {
dx = 10;
dy = 0;
} else if (e.getKeyCode() == 40) {
dx = 0;
dy = 10;
} else if (e.getKeyCode() == 80) {
if (flag % 2 == 1) {
time.stop();
}
if (flag % 2 == 0) {
time.start();
}
flag++;
}
}
});
}
public void paint(Graphics g) {
g.setColor(Color.WHITE);
g.fillRect(0, 0, 400, 400);
g.setColor(Color.DARK_GRAY);
g.drawLine(3, 3, 305, 3);
g.drawLine(3, 3, 3, 305);
g.drawLine(305, 3, 305, 305);
g.drawLine(3, 305, 305, 305);
g.setColor(Color.PINK);
for (int i = 0; i < listBody.size(); i++) {
g.fillRect(listBody.get(i).x, listBody.get(i).y, 9, 9);
}
g.fillRect(x, y, 9, 9);
g.setColor(Color.ORANGE);
g.fillRect(fx, fy, 9, 9);
g.setColor(Color.DARK_GRAY);
str1 = "現在的長度為:" + snakeBody;
g.drawString(str, 10, 320);
g.drawString(str1, 10, 335);
}
public void actionPerformed(ActionEvent e) {
x += dx;
y += dy;
if (makeOut() == false) {
JOptionPane.showMessageDialog(null, "重新開始......");
speed = 700;
snakeBody = 1;
x = 5;
y = 5;
list.clear();
list.add(new Point(x, y));
listBody.clear();
listBody.add(list.get(0));
dx = 10;
dy = 0;
}
addPoint(x, y);
if (x == fx && y == fy) {
speed = (int) (speed * 0.8);//速度增加參數
if (speed < 200) {
speed = 100;
}
fx = rand.nextInt(30) * 10 + 5;// 2
fy = rand.nextInt(30) * 10 + 5;// 2
snakeBody++;// 2
} // 2
repaint();
}
public void addPoint(int xx, int yy) {
// 動態的記錄最新發生的50步以內的移動過的坐標
// 並畫出最新的snakeBody
if (list.size() < 100) {//蛇身長度最長為100
list.add(new Point(xx, yy));
} else {
list.remove(0);
list.add(new Point(xx, yy));
}
if (snakeBody == 1) {
listBody.remove(0);
listBody.add(0, list.get(list.size() - 1));
} else {
listBody.clear();
if (list.size() < snakeBody) {
for (int i = list.size() - 1; i > 0; i--) {
listBody.add(list.get(i));
}
} else {
for (int i = list.size() - 1; listBody.size() < snakeBody; i--) {
listBody.add(list.get(i));
}
}
}
}
public boolean makeOut() {
if ((x < 3 || y < 3) || (x > 305 || y > 305)) {
return false;
}
for (int i = 0; i < listBody.size() - 1; i++) {
for (int j = i + 1; j < listBody.size(); j++) {
if (listBody.get(i).equals(listBody.get(j))) {
return false;
}
}
}
return true;
}
}
/*貪吃蛇代碼*/