java选课页面代码 java学生选课系统课程设计
用Java语言设计一个界面,
首先:采用什么技术实现
为鹿邑等地区用户提供了全套网页设计制作服务,及鹿邑网站建设行业解决方案。主营业务为网站设计、成都网站制作、鹿邑网站设计,以传统方式定制建设网站,并提供域名空间备案等一条龙服务,秉承以专业、用心的态度为用户提供真诚的服务。我们深信只要达到每一位用户的要求,就会得到认可,从而选择与我们长期合作。这样,我们也可以走得更远!
java语言可以使用awt 和swing等技术实现图形界面
推荐使用Swing,因为Swing比AWT更专业,更漂亮,组件更丰富,功能更强大。
2. 其次:分析采用什么布局
边界布局BorderLayout,配合表格布局GridLayout,既简单又美观
3. 最后:分析需求中需要用的组件
学生姓名 学号 显示信息 需要用到文本框JTextField
单选按钮 需要用到组件 JRadioButton
复选框 需要用到组件 JCheckBox
组合框 需要用到组件 JComboBox
图片效果
参考代码如下
//导入所需要的包
import java.awt.event.*;
import javax.swing.border.*;
import javax.swing.*;
import java.awt.*;
public class ClassFrame extends JFrame {// 写一个类继承自JFrame 窗体
// 定义组件
private static final long serialVersionUID = 1L;
private JPanel contentPane;
private JTextField tfName, tfNum, allInfo;
private JRadioButton rb1, rb2;
private JCheckBox cb1, cb2, cb3;
private JComboBoxString t1, t2, t3;
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
ClassFrame frame = new ClassFrame();// 创建一个窗口实例
frame.setVisible(true);// 让该窗口实例可见
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* 窗口属性的设置,内部组件的初始化
*/
public ClassFrame() {
setTitle("选课ing...");//标题
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);// 设置关闭是退出JVM
setSize(450, 339);// 设置窗体大小
setLocationRelativeTo(null);// 窗体居中
contentPane = new JPanel();// 内容面板
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
contentPane.setLayout(new BorderLayout(0, 0));// 设置布局
setContentPane(contentPane);
JPanel panel = new JPanel(new GridLayout(5, 1, 5, 10));//5行1列的表格布局
panel.setBorder(new TitledBorder(null, "", TitledBorder.LEADING, TitledBorder.TOP, null, null));
contentPane.add(panel, BorderLayout.CENTER);//给panel添加边框
JPanel panel_1 = new JPanel();
panel.add(panel_1);
JLabel label = new JLabel("姓名");
panel_1.add(label);
tfName = new JTextField();
panel_1.add(tfName);
tfName.setColumns(10);
JLabel label_2 = new JLabel("学号");
panel_1.add(label_2);
tfNum = new JTextField();
tfNum.setColumns(10);
panel_1.add(tfNum);
rb1 = new JRadioButton("男");
panel_1.add(rb1);
rb1.setSelected(true);//设置单选按钮中,默认选择的按钮
rb2 = new JRadioButton("女");
panel_1.add(rb2);
ButtonGroup bts = new ButtonGroup();//单选按钮需要加入同一个ButonGroup中才能生效
bts.add(rb1);
bts.add(rb2);
JPanel panel_2 = new JPanel();
panel.add(panel_2);
cb1 = new JCheckBox("高等数学");
panel_2.add(cb1);
t1 = new JComboBoxString();
t1.setModel(new DefaultComboBoxModelString(new String[] { "林老师", "赵老师", "孙老师" }));
panel_2.add(t1);
JPanel panel_3 = new JPanel();
panel.add(panel_3);
cb2 = new JCheckBox("世界经济");
panel_3.add(cb2);
t2 = new JComboBoxString();
t2.setModel(new DefaultComboBoxModelString(new String[] { "张老师", "刘老师" }));
panel_3.add(t2);
JPanel panel_4 = new JPanel();
panel.add(panel_4);
cb3 = new JCheckBox("音乐赏析");
panel_4.add(cb3);
t3 = new JComboBoxString();
t3.setModel(new DefaultComboBoxModelString(new String[] { "王老师", "周老师" }));
panel_4.add(t3);
JPanel panel_5 = new JPanel();
panel.add(panel_5);
JButton jbOk = new JButton("确定");
panel_5.add(jbOk);
JButton jbRest = new JButton("重填");
panel_5.add(jbRest);
JPanel panelSouth = new JPanel();
contentPane.add(panelSouth, BorderLayout.SOUTH);
JLabel labe = new JLabel("选课信息");
labe.setHorizontalAlignment(SwingConstants.LEFT);
panelSouth.add(labe);
allInfo = new JTextField();
allInfo.setColumns(30);
panelSouth.add(allInfo);
JPanel panelNorth = new JPanel();
contentPane.add(panelNorth, BorderLayout.NORTH);
JLabel labelTitle = new JLabel("学生选课界面");
labelTitle.setForeground(Color.DARK_GRAY);
labelTitle.setFont(new Font("宋体", Font.BOLD, 20));
panelNorth.add(labelTitle);
//给确定按钮添加事件处理代码
jbOk.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
StringBuilder info = new StringBuilder();
String name = tfName.getText();
String num = tfNum.getText();
String sex;
if (rb1.isSelected()) {
sex = "男";
} else {
sex = "女";
}
info.append(name + num + sex);
if (cb1.isSelected()) {
String c = cb1.getText();
String t = t1.getSelectedItem().toString();
info.append(" " + c + t);
}
if (cb2.isSelected()) {
String c = cb2.getText();
String t = t2.getSelectedItem().toString();
info.append(" " + c + t);
}
if (cb3.isSelected()) {
String c = cb3.getText();
String t = t3.getSelectedItem().toString();
info.append(" " + c + t);
}
allInfo.setText(info.toString());//把学生信息和选课信息放到文本框
}
});
//给重填按钮 设置事件处理代码
jbRest.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
tfName.setText("");
tfNum.setText("");
rb1.setSelected(true);
cb1.setSelected(false);
t1.setSelectedIndex(0);
cb2.setSelected(false);
t2.setSelectedIndex(0);
cb3.setSelected(false);
t3.setSelectedIndex(0);
allInfo.setText("");
}
});
}
}
java代码
帮你改了一下:
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);
}
}
300分急求教务选课系统的JAVA代码。
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);
}
}
}
本程序已经成功!!!望再验证!!!!
分享题目:java选课页面代码 java学生选课系统课程设计
链接地址:http://hbruida.cn/article/dojdjoi.html