public class Course {
站在用户的角度思考问题,与客户深入沟通,找到城阳网站设计与城阳网站推广的解决方案,凭借多年的经验,让设计与互联网技术结合,创造个性化、用户体验好的作品,建站类型包括:做网站、网站建设、企业官网、英文网站、手机端网站、网站推广、国际域名空间、网站空间、企业邮箱。业务覆盖城阳地区。
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,联系电话:%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个学生", students.size());
for (Student student : students) {
System.out.println(student.toString());
}
}
//修改
public void updateStudent(long i, String n, int a, boolean s, String p)
{
//以姓名做为唯一标识
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("学生选课系统");
setSize(600,600);
ShenFen1=new Checkbox("学生",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学生选修课管理系统
到了要求哪里:1.系统利用C、C++程序设计语言实现。
没救了.
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("网上选课记录系统",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("学号",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("专业",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("请选择您要选修的课程并确认",Label.CENTER);
btn1=new Button("查询");
btn2=new Button("确认");
btn3=new Button("退出系统");
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("大学英语");
list.add("计算机图形学");
list.add("JAVA语言");
list.add("高等数学");
list.add("数据结构");
list.add("单片机");
list.add("网络应用与开发");
list.add("概率论与数理统计");
list.add("管理学概论");
list.add("数据库概论");
list.add("英语听力");
list.add("VC++");
list.add("商务英语");
list.add("会计学");
list.add("经济学");
list.add("计算机网络");
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("欢迎来到网上选课系统",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("网上选课");
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","计算机","计算机系","单片机,数学"));
xiang.addElement(new user("杨先生","7899452","计算机","计算机系","单片机,数学"));
xiang.addElement(new user("董先生","7899452","计算机","计算机系","单片机,数学"));
xiang.addElement(new user("何先生","7899453","计算机","计算机系","单片机,数学"));
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("您无权进本系统!"));
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()+" "+"您的学号是:"+pn9.pn2.t2.getText()+" ");
ss.append("您的专业是:"+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("按学号进行查询!请输入学号!再按此键!"));
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);
}
}
}
本程序已经成功!!!望再验证!!!!
学生选课系统的设计与实现摘要本文以一个具体的应用系统—学生选课信息系统的设计与实现来说明如何利用UML和EJB组件来设计和构建分布式软件系统平台。UML和组件技术结合使用能提高开发效率,增加系统的易维护性。关键词UML;EJB;实例1引言现在信息管理系统软件的开发,采用组件技术可以提高效率,信息管理系统的分析设计也采用UML来进行。两者的结合可以极大的提高开发效率,保证系统开发的易维护性。本文用UML这种设计方法和EJB这种组件技术来设计和实现一个系统。2系统分析本系统设计为学生通过网页登陆学校网站,进行选课。下面用用例图来说明该系统要实现的功能。2.1用例图2.2系统总体结构图本系统采用三层体系结构,分为表示层,事务处理层,数据存储层。三层结构层次清晰,易维护。图3类图学生选课系统涉及到三个实体类学生,课程,以及学生和课程之间的一个一对多关系类。对每一个类,映射到一张表。学生类和课程类用Container-ManagedEntityBean实现,学生和课程间的一对多关系类,用Bean-ManagedPersistence的EntityBean实现。再设计一个SessionBean对学生选课过程进行控制。页面显示部分用JSP实现。3数据库设计学生表对应学生实体,详细内容如下表1学生表关联表对应学生和课程间的一对多关系,详细内容如下研究开发4实现4.1SessionBean的设计4.1.1定义HomeInterface4.1.2定义RemoteInterfacepublicinterfaceEnrollSessionextendsEJBObject{//-----//这是一个基于SessionBean的Remote接口,这个SessionBean是基于//Stateful的SessionBean,用来对特定学生选课的登记过程进行操作//-----------------------------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定义回调方法4.1.5实现远程数据库的连接使用JNDI机制,通过数据库的JNDI名称javacomp/env/jdbc/StudentCourseDB来连接后台数据库。4.1.6SessionBean方法实现//定义变量publicStudentHomesHome;publicEnrollHomeeHome;publicStringstudent_id;publicStringname;//回调方法实现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;}//商业方法实现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的设计我们以关联表(EnrollTBL)对应的实体Bean为例进行说明,它涉及到两个表的一对多关系。4.2.1定义Home接口4.2.2定义RemoteInterfacepublicinterfaceEnrollextendsEJBObject{//---------------//这是一个基于EntityBean的Remote接口,这个EntityBean是基于//Bean-ManagedPersistence的EntityBean,用来对EnrollTBL表进行操作//--------------------------publicArrayListgetCourseItems()throwsRemoteException;publicStringgetStudent_id()throwsRemoteException;publicvoidreplaceCourseItems(ArrayListcourseItems)throwsRemoteException;}4.2.3变量定义publicStringstudent_id;publicArrayListcourseItems;4.2.4增加数据记录实现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;}//根据学生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();}}//根据学生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,设置事务属性,生成部署文件。5.1.2同样,再部署其他三个EJB组件EnrollSessionBean,CourseEntityBean,EnrollEntityBean。5.1.3部署web组件5.1.4部署整个应用程序5.2运行启动J2EE服务器,启动数据库服务器,打开浏览器。学生登录,即可选课。6结论组件技术使得复杂的多层结构应用系统开发变得容易。采用组件技术能提高开发人员的效率,降低软件的开发和维护成本,提高软件的质量,控制所构建系统的复杂性。UML设计方法的使用能提高软件设计的效率和保证设计的规范性。参考文献[1]CraigLarman.UML和模式应用-面向对象分析与设计导论[M].北京机械工业出版社,2003.10-100.[2]刘特.J2EEEJB应用编程实例[M].北京清华大学出版社,2003.90-150.[3]GeriSchneider.用例分析技术[M].北京机械工业出版社,2003.1-98.
-----------------------------------------------
谢谢请采纳:
不能发连接啊,请在百度
搜索‘珍惜知识网’点进去就是了[ORDA]