幫你改了一下:
站在用戶(hù)的角度思考問(wèn)題,與客戶(hù)深入溝通,找到富平網(wǎng)站設(shè)計(jì)與富平網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗(yàn),讓設(shè)計(jì)與互聯(lián)網(wǎng)技術(shù)結(jié)合,創(chuàng)造個(gè)性化、用戶(hù)體驗(yàn)好的作品,建站類(lèi)型包括:成都網(wǎng)站設(shè)計(jì)、成都做網(wǎng)站、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣、域名與空間、雅安服務(wù)器托管、企業(yè)郵箱。業(yè)務(wù)覆蓋富平地區(qū)。
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);
}
}
學(xué)生選課系統(tǒng)的設(shè)計(jì)與實(shí)現(xiàn)摘要本文以一個(gè)具體的應(yīng)用系統(tǒng)—學(xué)生選課信息系統(tǒng)的設(shè)計(jì)與實(shí)現(xiàn)來(lái)說(shuō)明如何利用UML和EJB組件來(lái)設(shè)計(jì)和構(gòu)建分布式軟件系統(tǒng)平臺(tái)。UML和組件技術(shù)結(jié)合使用能提高開(kāi)發(fā)效率,增加系統(tǒng)的易維護(hù)性。關(guān)鍵詞UML;EJB;實(shí)例1引言現(xiàn)在信息管理系統(tǒng)軟件的開(kāi)發(fā),采用組件技術(shù)可以提高效率,信息管理系統(tǒng)的分析設(shè)計(jì)也采用UML來(lái)進(jìn)行。兩者的結(jié)合可以極大的提高開(kāi)發(fā)效率,保證系統(tǒng)開(kāi)發(fā)的易維護(hù)性。本文用UML這種設(shè)計(jì)方法和EJB這種組件技術(shù)來(lái)設(shè)計(jì)和實(shí)現(xiàn)一個(gè)系統(tǒng)。2系統(tǒng)分析本系統(tǒng)設(shè)計(jì)為學(xué)生通過(guò)網(wǎng)頁(yè)登陸學(xué)校網(wǎng)站,進(jìn)行選課。下面用用例圖來(lái)說(shuō)明該系統(tǒng)要實(shí)現(xiàn)的功能。2.1用例圖2.2系統(tǒng)總體結(jié)構(gòu)圖本系統(tǒng)采用三層體系結(jié)構(gòu),分為表示層,事務(wù)處理層,數(shù)據(jù)存儲(chǔ)層。三層結(jié)構(gòu)層次清晰,易維護(hù)。圖3類(lèi)圖學(xué)生選課系統(tǒng)涉及到三個(gè)實(shí)體類(lèi)學(xué)生,課程,以及學(xué)生和課程之間的一個(gè)一對(duì)多關(guān)系類(lèi)。對(duì)每一個(gè)類(lèi),映射到一張表。學(xué)生類(lèi)和課程類(lèi)用Container-ManagedEntityBean實(shí)現(xiàn),學(xué)生和課程間的一對(duì)多關(guān)系類(lèi),用Bean-ManagedPersistence的EntityBean實(shí)現(xiàn)。再設(shè)計(jì)一個(gè)SessionBean對(duì)學(xué)生選課過(guò)程進(jìn)行控制。頁(yè)面顯示部分用JSP實(shí)現(xiàn)。3數(shù)據(jù)庫(kù)設(shè)計(jì)學(xué)生表對(duì)應(yīng)學(xué)生實(shí)體,詳細(xì)內(nèi)容如下表1學(xué)生表關(guān)聯(lián)表對(duì)應(yīng)學(xué)生和課程間的一對(duì)多關(guān)系,詳細(xì)內(nèi)容如下研究開(kāi)發(fā)4實(shí)現(xiàn)4.1SessionBean的設(shè)計(jì)4.1.1定義HomeInterface4.1.2定義RemoteInterfacepublicinterfaceEnrollSessionextendsEJBObject{//-----//這是一個(gè)基于SessionBean的Remote接口,這個(gè)SessionBean是基于//Stateful的SessionBean,用來(lái)對(duì)特定學(xué)生選課的登記過(guò)程進(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機(jī)制來(lái)獲取Home接口和Remote接口的對(duì)象參考。4.1.4定義回調(diào)方法4.1.5實(shí)現(xiàn)遠(yuǎn)程數(shù)據(jù)庫(kù)的連接使用JNDI機(jī)制,通過(guò)數(shù)據(jù)庫(kù)的JNDI名稱(chēng)javacomp/env/jdbc/StudentCourseDB來(lái)連接后臺(tái)數(shù)據(jù)庫(kù)。4.1.6SessionBean方法實(shí)現(xiàn)//定義變量publicStudentHomesHome;publicEnrollHomeeHome;publicStringstudent_id;publicStringname;//回調(diào)方法實(shí)現(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è)方法實(shí)現(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());}}//涉及到對(duì)兩張表的刪除。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è)計(jì)我們以關(guān)聯(lián)表(EnrollTBL)對(duì)應(yīng)的實(shí)體Bean為例進(jìn)行說(shuō)明,它涉及到兩個(gè)表的一對(duì)多關(guān)系。4.2.1定義Home接口4.2.2定義RemoteInterfacepublicinterfaceEnrollextendsEJBObject{//---------------//這是一個(gè)基于EntityBean的Remote接口,這個(gè)EntityBean是基于//Bean-ManagedPersistence的EntityBean,用來(lái)對(duì)EnrollTBL表進(jìn)行操作//--------------------------publicArrayListgetCourseItems()throwsRemoteException;publicStringgetStudent_id()throwsRemoteException;publicvoidreplaceCourseItems(ArrayListcourseItems)throwsRemoteException;}4.2.3變量定義publicStringstudent_id;publicArrayListcourseItems;4.2.4增加數(shù)據(jù)記錄實(shí)現(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,插入課程項(xiàng)。privatevoidenroll(ArrayListcourseItems)throwsSQLException{StringinsertStatement=insertintoEnrollTBLvalues(?,?);PreparedStatementps=con.prepareStatement(insertStatement);try{//------------//依次將所有的課程項(xiàng)目插入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,刪除課程項(xiàng)privatevoidunenroll()throwsSQLException{StringdeleteStatement=deletefromEnrollTBL+wherestudent_id=?;PreparedStatementps=con.prepareStatement(deleteStatement);try{ps.setString(1,student_id);ps.executeUpdate();}finally{ps.close();}}5部署和運(yùn)行5.1部署程序5.1.1部署StudentEntityBean,設(shè)置事務(wù)屬性,生成部署文件。5.1.2同樣,再部署其他三個(gè)EJB組件EnrollSessionBean,CourseEntityBean,EnrollEntityBean。5.1.3部署web組件5.1.4部署整個(gè)應(yīng)用程序5.2運(yùn)行啟動(dòng)J2EE服務(wù)器,啟動(dòng)數(shù)據(jù)庫(kù)服務(wù)器,打開(kāi)瀏覽器。學(xué)生登錄,即可選課。6結(jié)論組件技術(shù)使得復(fù)雜的多層結(jié)構(gòu)應(yīng)用系統(tǒng)開(kāi)發(fā)變得容易。采用組件技術(shù)能提高開(kāi)發(fā)人員的效率,降低軟件的開(kāi)發(fā)和維護(hù)成本,提高軟件的質(zhì)量,控制所構(gòu)建系統(tǒng)的復(fù)雜性。UML設(shè)計(jì)方法的使用能提高軟件設(shè)計(jì)的效率和保證設(shè)計(jì)的規(guī)范性。參考文獻(xiàn)[1]CraigLarman.UML和模式應(yīng)用-面向?qū)ο蠓治雠c設(shè)計(jì)導(dǎo)論[M].北京機(jī)械工業(yè)出版社,2003.10-100.[2]劉特.J2EEEJB應(yīng)用編程實(shí)例[M].北京清華大學(xué)出版社,2003.90-150.[3]GeriSchneider.用例分析技術(shù)[M].北京機(jī)械工業(yè)出版社,2003.1-98.
-----------------------------------------------
謝謝請(qǐng)采納:
不能發(fā)連接啊,請(qǐng)?jiān)诎俣?/p>
搜索‘珍惜知識(shí)網(wǎng)’點(diǎn)進(jìn)去就是了[ORDA]
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é)號(hào)",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("專(zhuān)業(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("請(qǐng)選擇您要選修的課程并確認(rèn)",Label.CENTER);
btn1=new Button("查詢(xún)");
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é)英語(yǔ)");
list.add("計(jì)算機(jī)圖形學(xué)");
list.add("JAVA語(yǔ)言");
list.add("高等數(shù)學(xué)");
list.add("數(shù)據(jù)結(jié)構(gòu)");
list.add("單片機(jī)");
list.add("網(wǎng)絡(luò)應(yīng)用與開(kāi)發(fā)");
list.add("概率論與數(shù)理統(tǒng)計(jì)");
list.add("管理學(xué)概論");
list.add("數(shù)據(jù)庫(kù)概論");
list.add("英語(yǔ)聽(tīng)力");
list.add("VC++");
list.add("商務(wù)英語(yǔ)");
list.add("會(huì)計(jì)學(xué)");
list.add("經(jīng)濟(jì)學(xué)");
list.add("計(jì)算機(jī)網(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("歡迎來(lái)到網(wǎng)上選課系統(tǒng)",Label.CENTER);
Font f=new Font("宋體",Font.BOLD,30);
l1.setFont(f);
l2=new Label("請(qǐng)輸入管理員帳號(hào)",Label.CENTER);
l3=new Label("請(qǐng)輸入管理員密碼",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","計(jì)算機(jī)","計(jì)算機(jī)系","單片機(jī),數(shù)學(xué)"));
xiang.addElement(new user("楊先生","7899452","計(jì)算機(jī)","計(jì)算機(jī)系","單片機(jī),數(shù)學(xué)"));
xiang.addElement(new user("董先生","7899452","計(jì)算機(jī)","計(jì)算機(jī)系","單片機(jī),數(shù)學(xué)"));
xiang.addElement(new user("何先生","7899453","計(jì)算機(jī)","計(jì)算機(jī)系","單片機(jī),數(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("您無(wú)權(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é)號(hào)是:"+pn9.pn2.t2.getText()+" ");
ss.append("您的專(zhuān)業(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é)號(hào)進(jìn)行查詢(xún)!請(qǐng)輸入學(xué)號(hào)!再按此鍵!"));
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("用戶(hù)不存在!請(qǐng)重新輸入!"));
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)成功!?。⊥衮?yàn)證?。。?!