public class Course {
站在用戶的角度思考問題,與客戶深入溝通,找到城陽網(wǎng)站設(shè)計與城陽網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗,讓設(shè)計與互聯(lián)網(wǎng)技術(shù)結(jié)合,創(chuàng)造個性化、用戶體驗好的作品,建站類型包括:做網(wǎng)站、網(wǎng)站建設(shè)、企業(yè)官網(wǎng)、英文網(wǎng)站、手機端網(wǎng)站、網(wǎng)站推廣、國際域名空間、網(wǎng)站空間、企業(yè)郵箱。業(yè)務(wù)覆蓋城陽地區(qū)。
private String name;
private float score;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public float getScore() {
return score;
}
public void setScore(float score) {
this.score = score;
}
public Course(String name, float score) {
this.name = name;
this.score = score;
}
public String toString() {
return this.name + ":" + this.score;
}
}
public class Student {
private long id;
private String name;
private int age;
private boolean sex;
public String toString() {
String sex = "女";
if (this.sex == true) {
sex = "男";
}
return String.format("姓名:%s,性別:%s,聯(lián)系電話:%s,課程信息:%s,課程信息:%s", this.name, sex, this.phone, this.subject.toString());
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public boolean isSex() {
return sex;
}
public void setSex(boolean sex) {
this.sex = sex;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public Course[] getSubject() {
return subject;
}
public void setSubject(Course[] subject) {
this.subject = subject;
}
private String phone;
private Course[] subject;
public Student(long i, String n, int a, boolean s, String p) {
this.id = i;
this.name = n;
this.age = a;
this.sex = s;
this.phone = p;
}
}
import java.util.ArrayList;
public class Cmanage {
private ArrayListStudent students;
//插入
public void addStudent(Student student) {
students.add(student);
}
//刪除
public void delStudent(Student student) {
students.remove(student);
}
//查詢
public void queryStudent() {
System.out.printf("一共有%d個學(xué)生", students.size());
for (Student student : students) {
System.out.println(student.toString());
}
}
//修改
public void updateStudent(long i, String n, int a, boolean s, String p)
{
//以姓名做為唯一標(biāo)識
for(int j=0;jstudents.size();j++)
{
if (students.get(j).getName().equals(n))
{
students.get(j).setId(i);
students.get(j).setAge(a);
students.get(j).setSex(s);
students.get(j).setPhone(p);
}
}
}
}
幫你改了一下:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class logon extends JFrame {
public static void main(String args[]) {
logon a=new logon();
a.show();
}
CheckboxGroup ShenFen=new CheckboxGroup();
Checkbox ShenFen1;
Checkbox ShenFen2;
Checkbox ShenFen3;
JButton LogonButton,Exit;
JTextField id;
JPasswordField password;
public logon(){
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
this.setLayout(null);
setTitle("學(xué)生選課系統(tǒng)");
setSize(600,600);
ShenFen1=new Checkbox("學(xué)生",ShenFen,true);
ShenFen2=new Checkbox("教師",ShenFen,false);
ShenFen3=new Checkbox("管理員",ShenFen,false);
add(ShenFen1);
add(ShenFen2);
add(ShenFen3);
ShenFen1.setBounds(300, 350, 50, 50);
ShenFen2.setBounds(350, 350, 50, 50);
ShenFen3.setBounds(400, 350, 50, 50);
LogonButton=new JButton("登錄");
add(LogonButton);
Exit=new JButton("退出");
add(Exit);
Exit.setBounds(400, 400,60, 60);
id=new JTextField();
add(id);
id.setBounds(300, 200, 200, 30);
password=new JPasswordField();
add(password);
password.setBounds(300, 250, 200, 30);
}
}
你寫的是java學(xué)生選修課管理系統(tǒng)
到了要求哪里:1.系統(tǒng)利用C、C++程序設(shè)計語言實現(xiàn)。
沒救了.
import java.awt.*;
import java.awt.event.*;
import java.util.*;
class p1 extends Panel
{
Label l1;
Font f=new Font("宋體",Font.BOLD,20);
p1()
{
setLayout(new GridLayout(1,1));
l1=new Label("網(wǎng)上選課記錄系統(tǒng)",Label.CENTER);
l1.setFont(f);
add(l1);
}
}
class p2 extends Panel
{
Label l1,l2;
TextField t1,t2;
p2()
{
setLayout(new GridLayout(1,4));
l1=new Label("姓名",Label.CENTER);
l2=new Label("學(xué)號",Label.CENTER);
t1=new TextField(10);
t2=new TextField(10);
add(l1);
add(t1);
add(l2);
add(t2);
}
}
class p3 extends Panel
{
Label l1,l2;
TextField t1,t2;
p3()
{
setLayout(new GridLayout(1,4));
l1=new Label("專業(yè)",Label.CENTER);
l2=new Label("所屬院(系)",Label.CENTER);
t1=new TextField(10);
t2=new TextField(10);
add(l1);
add(t1);
add(l2);
add(t2);
}
}
class p4 extends Panel
{
Label l1;
Button btn1;
Button btn2;
Button btn3;
Font f=new Font("宋體",Font.BOLD,20);
p4()
{
setLayout(new GridLayout(1,4));
l1=new Label("請選擇您要選修的課程并確認(rèn)",Label.CENTER);
btn1=new Button("查詢");
btn2=new Button("確認(rèn)");
btn3=new Button("退出系統(tǒng)");
add(l1);
add(btn1);
add(btn2);
add(btn3);
}
}
class p5 extends Panel
{
List list ;
p5()
{
setLayout(new GridLayout(1,1));
list=new List(8,true);
list.add("大學(xué)英語");
list.add("計算機圖形學(xué)");
list.add("JAVA語言");
list.add("高等數(shù)學(xué)");
list.add("數(shù)據(jù)結(jié)構(gòu)");
list.add("單片機");
list.add("網(wǎng)絡(luò)應(yīng)用與開發(fā)");
list.add("概率論與數(shù)理統(tǒng)計");
list.add("管理學(xué)概論");
list.add("數(shù)據(jù)庫概論");
list.add("英語聽力");
list.add("VC++");
list.add("商務(wù)英語");
list.add("會計學(xué)");
list.add("經(jīng)濟學(xué)");
list.add("計算機網(wǎng)絡(luò)");
add(list);
}
}
class p6 extends Panel
{
TextArea ta;
p6()
{
setLayout(new GridLayout(1,1));
ta=new TextArea(8,30);
add(ta);
}
}
class p8 extends Panel
{
Label l1,l2,l3;
Label l4,l5,l6,l7,l9;
Panel p11,p22,p33,p44,p55;
TextField t1,t2;
Button btn;
p8()
{
p11=new Panel();
p22=new Panel();
p33=new Panel();
p44=new Panel();
p55=new Panel();
p11.setLayout(new GridLayout(1,1));
p22.setLayout(new GridLayout(1,1));
p33.setLayout(new GridLayout(1,4));
p44.setLayout(new GridLayout(1,4));
p55.setLayout(new GridLayout(1,1));
l4=new Label("");
l5=new Label("");
l6=new Label("");
l7=new Label("");
l9=new Label("");
l1=new Label("歡迎來到網(wǎng)上選課系統(tǒng)",Label.CENTER);
Font f=new Font("宋體",Font.BOLD,30);
l1.setFont(f);
l2=new Label("請輸入管理員帳號",Label.CENTER);
l3=new Label("請輸入管理員密碼",Label.CENTER);
setBackground(Color.lightGray);
btn=new Button("確定");
t1=new TextField(20);
t2=new TextField(15);
t2.setEchoChar(′*′);
l1.setForeground(Color.magenta);
t1.setBackground(Color.cyan);
t2.setBackground(Color.cyan);
t1.setForeground(Color.red);
t2.setForeground(Color.red);
l2.setForeground(Color.blue);
l3.setForeground(Color.blue);
p11.add(l1);
p22.add(l4);
p33.add(l5);
p33.add(l2);
p33.add(t1);
p33.add(l6);
p44.add(l7);
p44.add(l3);
p44.add(t2);
p44.add(btn);
p55.add(l9);
setLayout(new GridLayout(5,1));
add(p11);
add(p22);
add(p33);
add(p44);
add(p55);
}
}
class p9 extends Panel
{
p1 pn1=new p1();
p2 pn2=new p2();
p3 pn3=new p3();
p4 pn4=new p4();
p5 pn5=new p5();
p6 pn6=new p6();
p9()
{
setLayout(new GridLayout(6,1));
add(pn1);
add(pn2);
add(pn3);
add(pn4);
add(pn5);
add(pn6);
}
}
class user
{
String username;
String sd;
String major;
String institute;
String course;
user(String x1,String x2,String x3,String x4,String x5)
{
username=x1;
sd=x2;
major=x3;
institute=x4;
course=x5;
}
}
public class www
{
public static void main(String args[])
{
new m();
}
}
class m extends Frame implements ActionListener,ItemListener
{
StringBuffer ss=new StringBuffer("您好!您選修的課程有:");
Vector xiang=new Vector();
p9 pn9;
p8 pn8;
CardLayout cc=new CardLayout();
Button btn1;
Dialog d1;
m()
{
super("網(wǎng)上選課");
pn8=new p8();
pn9=new p9();
setLayout(cc);
add("one",pn8);
add("two",pn9);
btn1=new Button("確定");
pn9.pn1.l1.setBackground(Color.pink);
pn9.pn1.l1.setForeground(Color.blue);
pn9.pn2.l1.setBackground(Color.gray);
pn9.pn2.l1.setForeground(Color.orange);
pn9.pn2.l2.setBackground(Color.gray);
pn9.pn2.l2.setForeground(Color.orange);
pn9.pn3.l1.setBackground(Color.gray);
pn9.pn3.l1.setForeground(Color.orange);
pn9.pn3.l2.setBackground(Color.gray);
pn9.pn3.l2.setForeground(Color.orange);
pn9.pn2.t1.setForeground(Color.red);
pn9.pn2.t1.setBackground(Color.cyan);
pn9.pn2.t2.setForeground(Color.red);
pn9.pn2.t2.setBackground(Color.cyan);
pn9.pn3.t1.setForeground(Color.red);
pn9.pn3.t1.setBackground(Color.cyan);
pn9.pn3.t2.setForeground(Color.red);
pn9.pn3.t2.setBackground(Color.cyan);
pn9.pn5.list.setBackground(Color.pink);
pn9.pn5.list.setForeground(Color.blue);
pn9.pn6.ta.setBackground(Color.blue);
pn9.pn6.ta.setForeground(Color.white);
pn9.pn4.btn1.addActionListener(this);
pn9.pn4.btn2.addActionListener(this);
pn9.pn4.btn3.addActionListener(this);
pn9.pn5.list.addActionListener(this);
(pn9.pn5.list).addItemListener(this);
pn8.btn.addActionListener(this);
btn1.addActionListener(this);
setSize(650,400);
show();
}
public void actionPerformed(ActionEvent e)
{
xiang.addElement(new user("馬先生","23597483","計算機","計算機系","單片機,數(shù)學(xué)"));
xiang.addElement(new user("楊先生","7899452","計算機","計算機系","單片機,數(shù)學(xué)"));
xiang.addElement(new user("董先生","7899452","計算機","計算機系","單片機,數(shù)學(xué)"));
xiang.addElement(new user("何先生","7899453","計算機","計算機系","單片機,數(shù)學(xué)"));
if(e.getSource()==pn8.btn)
{
String ss="123";
if(ss.compareTo(pn8.t1.getText())==0ss.compareTo(pn8.t2.getText())==0)
cc.show(this,"two");
else
{
d1=new Dialog(this,"警告",true);
Panel p1=new Panel();
p1.add(new Label("您無權(quán)進(jìn)本系統(tǒng)!"));
d1.add("Center",p1);
Panel p2=new Panel();
p2.add(btn1);
d1.add("South",p2);
d1.setSize(200,100);
d1.show();
}
}
if(e.getSource()==btn1)
{
d1.dispose();
}
if(e.getSource()==pn9.pn4.btn3)
{
dispose();
System.exit(0);
}
if(e.getSource()==pn9.pn4.btn2)
{
pn9.pn6.ta.setText("");
ss.append(" 您的姓名是:"+pn9.pn2.t1.getText()+" "+"您的學(xué)號是:"+pn9.pn2.t2.getText()+" ");
ss.append("您的專業(yè)是:"+pn9.pn3.t1.getText()+" "+"您所在院(系)是:"+pn9.pn3.t2.getText()+" ");
ss.append("您的所有信息將被保存!");
pn9.pn6.ta.setText(ss.toString());
user s1=new user(pn9.pn2.t1.getText(),pn9.pn2.t2.getText(),pn9.pn3.t1.getText(),pn9.pn3.t2.getText(),ss.toString());
int i;
for(i=0;ixiang.size();i++)
{
user s=(user)xiang.elementAt(i);
if(s.sd.compareTo(s1.sd)==0)
{
s.username=s1.username;
s.sd=s1.sd;
s.major=s1.major;
s.institute=s1.institute;
s.course=s1.course;
xiang.setElementAt(new user(s.username,s.sd,s.major,s.institute,s.course),i);
break;
}
}
if(i==xiang.size())
xiang.addElement(new user(pn9.pn2.t1.getText(),pn9.pn2.t2.getText(),pn9.pn3.t1.getText(),pn9.pn3.t2.getText(),ss.toString()));
}
if(e.getSource()==pn9.pn4.btn1)
{
pn9.pn6.ta.setText("");
if(pn9.pn2.t2.getText()=="")
{
d1=new Dialog(this,"注意",true);
Panel p1=new Panel();
p1.add(new Label("按學(xué)號進(jìn)行查詢!請輸入學(xué)號!再按此鍵!"));
d1.add("Center",p1);
Panel p2=new Panel();
p2.add(btn1);
d1.add("South",p2);
d1.setSize(250,100);
d1.show();
}
int i;
for(i=0;ixiang.size();i++)
{
user s=(user)xiang.elementAt(i);
if(s.sd.compareTo(pn9.pn2.t2.getText())==0)
{
pn9.pn2.t1.setText(""+s.username);
pn9.pn3.t1.setText(""+s.major);
pn9.pn3.t2.setText(""+s.institute);
pn9.pn6.ta.setText("您選修的課程有:"+s.course);
break;
}
}
if(i==xiang.size())
{
d1=new Dialog(this,"警告",true);
Panel p1=new Panel();
p1.add(new Label("用戶不存在!請重新輸入!"));
d1.add("Center",p1);
Panel p2=new Panel();
p2.add(btn1);
d1.add("South",p2);
d1.setSize(200,100);
d1.show();
}
}
}
public void itemStateChanged(ItemEvent e)
{
List temp;
String sList[];
String mgr=new String("");
if(e.getItemSelectable()instanceof List)
{
temp=(List)(e.getItemSelectable());
sList=temp.getSelectedItems();
for(int i=0;isList.length;i++)
mgr=mgr+sList[i]+" ";
ss.append(mgr);
}
}
}
本程序已經(jīng)成功!?。⊥衮炞C?。。?!
學(xué)生選課系統(tǒng)的設(shè)計與實現(xiàn)摘要本文以一個具體的應(yīng)用系統(tǒng)—學(xué)生選課信息系統(tǒng)的設(shè)計與實現(xiàn)來說明如何利用UML和EJB組件來設(shè)計和構(gòu)建分布式軟件系統(tǒng)平臺。UML和組件技術(shù)結(jié)合使用能提高開發(fā)效率,增加系統(tǒng)的易維護(hù)性。關(guān)鍵詞UML;EJB;實例1引言現(xiàn)在信息管理系統(tǒng)軟件的開發(fā),采用組件技術(shù)可以提高效率,信息管理系統(tǒng)的分析設(shè)計也采用UML來進(jìn)行。兩者的結(jié)合可以極大的提高開發(fā)效率,保證系統(tǒng)開發(fā)的易維護(hù)性。本文用UML這種設(shè)計方法和EJB這種組件技術(shù)來設(shè)計和實現(xiàn)一個系統(tǒng)。2系統(tǒng)分析本系統(tǒng)設(shè)計為學(xué)生通過網(wǎng)頁登陸學(xué)校網(wǎng)站,進(jìn)行選課。下面用用例圖來說明該系統(tǒng)要實現(xiàn)的功能。2.1用例圖2.2系統(tǒng)總體結(jié)構(gòu)圖本系統(tǒng)采用三層體系結(jié)構(gòu),分為表示層,事務(wù)處理層,數(shù)據(jù)存儲層。三層結(jié)構(gòu)層次清晰,易維護(hù)。圖3類圖學(xué)生選課系統(tǒng)涉及到三個實體類學(xué)生,課程,以及學(xué)生和課程之間的一個一對多關(guān)系類。對每一個類,映射到一張表。學(xué)生類和課程類用Container-ManagedEntityBean實現(xiàn),學(xué)生和課程間的一對多關(guān)系類,用Bean-ManagedPersistence的EntityBean實現(xiàn)。再設(shè)計一個SessionBean對學(xué)生選課過程進(jìn)行控制。頁面顯示部分用JSP實現(xiàn)。3數(shù)據(jù)庫設(shè)計學(xué)生表對應(yīng)學(xué)生實體,詳細(xì)內(nèi)容如下表1學(xué)生表關(guān)聯(lián)表對應(yīng)學(xué)生和課程間的一對多關(guān)系,詳細(xì)內(nèi)容如下研究開發(fā)4實現(xiàn)4.1SessionBean的設(shè)計4.1.1定義HomeInterface4.1.2定義RemoteInterfacepublicinterfaceEnrollSessionextendsEJBObject{//-----//這是一個基于SessionBean的Remote接口,這個SessionBean是基于//Stateful的SessionBean,用來對特定學(xué)生選課的登記過程進(jìn)行操作//-----------------------------publicStringgetStudentName()throwsRemoteException;publicvoidenroll(ArrayListcourseItems)throwsRemoteExcep-tion;publicvoidunenroll()throwsRemoteException;publicvoiddeleteStudent()throwsFinderException,RemoteEx-ception;publicvoiddeleteCourse(Stringcourse_id)throwsRemoteExcep-tion;}4.1.3Client獲取HomeInterface和RemoteInterface的參考方式,我們使用JNDI機制來獲取Home接口和Remote接口的對象參考。4.1.4定義回調(diào)方法4.1.5實現(xiàn)遠(yuǎn)程數(shù)據(jù)庫的連接使用JNDI機制,通過數(shù)據(jù)庫的JNDI名稱javacomp/env/jdbc/StudentCourseDB來連接后臺數(shù)據(jù)庫。4.1.6SessionBean方法實現(xiàn)//定義變量publicStudentHomesHome;publicEnrollHomeeHome;publicStringstudent_id;publicStringname;//回調(diào)方法實現(xiàn)publicvoidejbCreate(Stringstudent_id)throwsCreateException{try{Studentstudent=sHome.findByPrimaryKey(student_id);name=student.getName();}catch(ObjectNotFoundExceptione){thrownewCreateException(Student+student_id+notfoundinStudentTBL!);}catch(Exceptione){thrownewEJBException(e.getMessage());}this.student_id=student_id;}//商業(yè)方法實現(xiàn)publicvoidenroll(ArrayListcourseItems){Enrollenroll=null;try{enroll=eHome.findByPrimaryKey(student_id);}catch(Exceptione){}try{if(enroll!=null){enroll.replaceCourseItems(courseItems);}else{eHome.create(student_id,courseItems);}}catch(Exceptione){thrownewEJBException(e.getMessage());}}publicvoidunenroll(){try{Enrollenroll=eHome.findByPrimaryKey(student_id);enroll.remove();}catch(Exceptione){thrownewEJBException(e.getMessage());}}//涉及到對兩張表的刪除。publicvoiddeleteStudent()throwsFinderException{try{Enrollenroll=eHome.findByPrimaryKey(student_id);Studentstudent=sHome.findByPrimaryKey(student_id);enroll.remove();student.remove();}catch(Exceptione){thrownewEJBException(e.getMessage());}}publicvoiddeleteCourse(Stringcourse_id){PreparedStatementps=null;try{getConnection();StringdeleteStatement=deletefromEnrollTBL+wherestudent_id=?andcourse_id=?;ps=con.prepareStatement(deleteStatement);ps.setString(1,student_id);ps.setString(2,course_id);ps.executeUpdate();}catch(Exceptione){thrownewEJBException(e.getMessage());}finally{try{ps.close();con.close();}catch(Exceptione){thrownewEJBException(e.getMessage());}}}4.2EntityBean的設(shè)計我們以關(guān)聯(lián)表(EnrollTBL)對應(yīng)的實體Bean為例進(jìn)行說明,它涉及到兩個表的一對多關(guān)系。4.2.1定義Home接口4.2.2定義RemoteInterfacepublicinterfaceEnrollextendsEJBObject{//---------------//這是一個基于EntityBean的Remote接口,這個EntityBean是基于//Bean-ManagedPersistence的EntityBean,用來對EnrollTBL表進(jìn)行操作//--------------------------publicArrayListgetCourseItems()throwsRemoteException;publicStringgetStudent_id()throwsRemoteException;publicvoidreplaceCourseItems(ArrayListcourseItems)throwsRemoteException;}4.2.3變量定義publicStringstudent_id;publicArrayListcourseItems;4.2.4增加數(shù)據(jù)記錄實現(xiàn)publicStringejbCreate(Stringstudent_id,ArrayListcourseItems)throwsCreateException{if(courseItems==null||courseItems.size()==0){thrownewCreateException(ejbCreateexception!);}this.student_id=student_id;try{enroll(courseItems);}catch(Exceptione){thrownewEJBException(ejbCreateexception+e.getMessage());}this.courseItems=courseItems;returnstudent_id;}//根據(jù)學(xué)生ID,插入課程項。privatevoidenroll(ArrayListcourseItems)throwsSQLException{StringinsertStatement=insertintoEnrollTBLvalues(?,?);PreparedStatementps=con.prepareStatement(insertStatement);try{//------------//依次將所有的課程項目插入EnrollTBL表//------------------ps.setString(1,this.student_id);for(inti=0;icourseItems.size();i++){Stringcourse_id=(String)courseItems.get(i);ps.setString(2,course_id);ps.executeUpdate();}}finally{ps.close();}}//根據(jù)學(xué)生ID,刪除課程項privatevoidunenroll()throwsSQLException{StringdeleteStatement=deletefromEnrollTBL+wherestudent_id=?;PreparedStatementps=con.prepareStatement(deleteStatement);try{ps.setString(1,student_id);ps.executeUpdate();}finally{ps.close();}}5部署和運行5.1部署程序5.1.1部署StudentEntityBean,設(shè)置事務(wù)屬性,生成部署文件。5.1.2同樣,再部署其他三個EJB組件EnrollSessionBean,CourseEntityBean,EnrollEntityBean。5.1.3部署web組件5.1.4部署整個應(yīng)用程序5.2運行啟動J2EE服務(wù)器,啟動數(shù)據(jù)庫服務(wù)器,打開瀏覽器。學(xué)生登錄,即可選課。6結(jié)論組件技術(shù)使得復(fù)雜的多層結(jié)構(gòu)應(yīng)用系統(tǒng)開發(fā)變得容易。采用組件技術(shù)能提高開發(fā)人員的效率,降低軟件的開發(fā)和維護(hù)成本,提高軟件的質(zhì)量,控制所構(gòu)建系統(tǒng)的復(fù)雜性。UML設(shè)計方法的使用能提高軟件設(shè)計的效率和保證設(shè)計的規(guī)范性。參考文獻(xiàn)[1]CraigLarman.UML和模式應(yīng)用-面向?qū)ο蠓治雠c設(shè)計導(dǎo)論[M].北京機械工業(yè)出版社,2003.10-100.[2]劉特.J2EEEJB應(yīng)用編程實例[M].北京清華大學(xué)出版社,2003.90-150.[3]GeriSchneider.用例分析技術(shù)[M].北京機械工業(yè)出版社,2003.1-98.
-----------------------------------------------
謝謝請采納:
不能發(fā)連接啊,請在百度
搜索‘珍惜知識網(wǎng)’點進(jìn)去就是了[ORDA]