📄 viewmycourse.java
字号:
import java.util.*;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.util.Vector;
public class ViewMyCourse extends JFrame implements ActionListener,ItemListener
{
private Student astudent;
private Vector aVector;
private Course mycourse;
private EditerCourse ec;
private JLabel title=new JLabel("删除课程",SwingConstants.CENTER);
private JButton deletebutton=new JButton("确认删除");
private JButton leavebutton=new JButton("退出");
private JComboBox jchoose=new JComboBox();
private JPanel panelup=new JPanel();
private JPanel paneldown=new JPanel();
private JPanel panelleft=new JPanel();
private JPanel panelright=new JPanel();
private JTable aTable;
private JScrollPane aJScrollPane;
public ViewMyCourse(Student newStudent)
{
super("查看我的课表");
this.setStudent(newStudent);
this.setBounds(100,100,350, 350);
this.setVisible(true);
// setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container c=this.getContentPane();
c.setLayout(new GridLayout(2,1));
ec=new EditerCourse(astudent);
aVector=ec.getMyCourse();
Object[] columnNames = {"课程班号",
"课程名","学分","授课老师","上课时间","地点"};
Object[][] rowData = new Object[50][6];
for(int i=0;i<aVector.size();i++)
{
Course mycourse=(Course)aVector.elementAt(i);
rowData[i][0]=mycourse.getCourseClassNo();
rowData[i][1]=mycourse.getCourseName();
rowData[i][2]=mycourse.getCourseXuefen();
rowData[i][3]=mycourse.getCourseTeach();
rowData[i][4]=mycourse.getCourseClassTime();
rowData[i][5]=mycourse.getCourseClassRoom();
}
aTable=new JTable(rowData,columnNames);
aTable.setAutoscrolls(true);
aTable.getColumn("课程名").setMaxWidth(80);
aTable.getColumn("学分").setMaxWidth(40);
aTable.getColumn("上课时间").setMaxWidth(80);
aJScrollPane=new JScrollPane(aTable);
panelup.setBorder(BorderFactory.createLineBorder(Color.black));
panelup.add(aJScrollPane);
c.add(panelup);
paneldown.setLayout(new GridLayout(1,2));
for(int i=0;i<aVector.size();i++)
{
Course acourse=(Course)aVector.elementAt(i);
jchoose.addItem(acourse.getCourseClassNo());
}
panelleft.setLayout(new GridLayout(1,2));
panelleft.add(title);
jchoose.addItemListener(this);
panelleft.add(jchoose);
panelleft.setBorder(BorderFactory.createLineBorder(Color.black));
paneldown.add(panelleft);
panelright.setLayout(new GridLayout(2,1));
deletebutton.addActionListener(this);
panelright.add(deletebutton);
leavebutton.addActionListener(this);
panelright.add(leavebutton);
panelright.setBorder(BorderFactory.createLineBorder(Color.black));
paneldown.add(panelright);
paneldown.setBorder(BorderFactory.createLineBorder(Color.black));
c.add(paneldown);
c.validate();
this.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent event)
{
dispose();
}
}
);
}
public void setStudent(Student s)
{
astudent=s;
}
public Student getStudent()
{
return astudent;
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==leavebutton)
{
shutDown();
}
if(e.getSource()==deletebutton)
{
String mystring;
Course course1;
mystring=(String) jchoose.getSelectedItem();
ec.deleteCourse(mystring);
JOptionPane.showMessageDialog(this,"删除课程成功");
}
}
public void itemStateChanged(ItemEvent e)
{
}
public void shutDown()
{
this.dispose();
}
// public static void main(String arg[])
// {
// Student aa=new Student("34060817","222","34060817","222","222","222");
// ViewMyCourse a=new ViewMyCourse(aa);
// }
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -