main.java
来自「电子与信息工程学生信息管理系统」· Java 代码 · 共 1,558 行 · 第 1/5 页
JAVA
1,558 行
four.prev.next=four;
four=four.prev;
four.id=stu.id;
four.name=stu.name;
four.sex=stu.sex;
four.age=stu.age;
four.grade=stu.grade;
four.gclass=stu.gclass;o++;
}
else{
three.next=new Student();
three.next.prev=three;
three=three.next;
three.id=stu.id;
three.name=stu.name;
three.sex=stu.sex;
three.age=stu.age;
three.grade=stu.grade;
three.gclass=stu.gclass;
}
}
if(o==0){Object[] options = {"yes"};
String str = "none!";
JOptionPane.showOptionDialog(null,str,"warning",JOptionPane.DEFAULT_OPTION,
JOptionPane.WARNING_MESSAGE,null,options,options[0]);
return;}
four.prev=three;
three.next=four;
while(four.next!=null){four=four.next;}
four=four.prev;first=four;first.next=null;
for(int i=0;i<listlenth-1;i++){four=four.prev;}
two.next=four;
four.prev=two;
shuaxin();page=1;
displayTable(page);
return;//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@id&&name is not null
}
if(searchname.length()!=0){
Student stu=two;//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@id&&name is not null
three=new Student();
four=new Student();
three.prev=null;
four.next=null;
int o=0;
for(int i=0;i<listlenth;i++){
stu=stu.next;
if(stu.name.contains(searchname)){
four.prev=new Student();
four.prev.next=four;
four=four.prev;
four.id=stu.id;
four.name=stu.name;
four.sex=stu.sex;
four.age=stu.age;
four.grade=stu.grade;
four.gclass=stu.gclass;o++;
}
else{
three.next=new Student();
three.next.prev=three;
three=three.next;
three.id=stu.id;
three.name=stu.name;
three.sex=stu.sex;
three.age=stu.age;
three.grade=stu.grade;
three.gclass=stu.gclass;
}
}
if(o==0){Object[] options = {"yes"};
String str = "none!";
JOptionPane.showOptionDialog(null,str,"warning",JOptionPane.DEFAULT_OPTION,
JOptionPane.WARNING_MESSAGE,null,options,options[0]);
return;}
four.prev=three;
three.next=four;
while(four.next!=null){four=four.next;}
four=four.prev;first=four;first.next=null;
for(int i=0;i<listlenth-1;i++){four=four.prev;}
two.next=four;
four.prev=two;
shuaxin();page=1;
displayTable(page);
return;//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@name is not null
}
if(searchid.length()!=0){
Student stu=two;//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@id is not null
three=new Student();
four=new Student();
three.prev=null;
four.next=null;
int o=0;
for(int i=0;i<listlenth;i++){
stu=stu.next;
if(stu.id.contains(searchid)){
four.prev=new Student();
four.prev.next=four;
four=four.prev;
four.id=stu.id;
four.name=stu.name;
four.sex=stu.sex;
four.age=stu.age;
four.grade=stu.grade;
four.gclass=stu.gclass;o++;
}
else{
three.next=new Student();
three.next.prev=three;
three=three.next;
three.id=stu.id;
three.name=stu.name;
three.sex=stu.sex;
three.age=stu.age;
three.grade=stu.grade;
three.gclass=stu.gclass;
}
}
if(o==0){Object[] options = {"yes"};
String str = "none!";
JOptionPane.showOptionDialog(null,str,"warning",JOptionPane.DEFAULT_OPTION,
JOptionPane.WARNING_MESSAGE,null,options,options[0]);
return;}
four.prev=three;
three.next=four;
while(four.next!=null){four=four.next;}
four=four.prev;first=four;first.next=null;
for(int i=0;i<listlenth-1;i++){four=four.prev;}
two.next=four;
four.prev=two;
shuaxin();page=1;
displayTable(page);
return;//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@id is not null
}
}
}
//******************************************************************************button_search action
//******************************************************************************button_first action
if(obj==button_first){page=1;shuaxin();displayTable(page);comboBox_page.setSelectedIndex(page);}
//******************************************************************************button_first action
//******************************************************************************button_last action
if(obj==button_last){page=listlenth/20+1;shuaxin();displayTable(page);comboBox_page.setSelectedIndex(page);}
//******************************************************************************button_last action
}
}
class PopupMenuEvent implements ActionListener{
public void actionPerformed(ActionEvent e){
Object obj = e.getSource();
if(obj==menuEdit){
if(!(listlenth>((page-1)*20+row)))return;
new EditDialog();
}
if(obj==menuDelete){
if(!(listlenth>((page-1)*20+row)))return;
delete();
}
}
}
class EditDialog extends JDialog implements ActionListener{
JLabel idLabel;
JTextField idText;
JLabel nameLabel;
JTextField nameText;
JLabel sexLabel;
JComboBox sexCombo;
JLabel ageLabel;
JComboBox ageCombo;
JLabel gradeLabel;
JComboBox gradeCombo;
JLabel classLabel;
JComboBox gclassCombo;
JButton button_ok;
JButton button_cancel;
int index = 0;
String[] sex = {"men","women"};
String[] age = new String [90];
String[] grade = {"dianxin","tongxin"};
String[] gclass ={"0501","0502","0503","0504","0505","0506","0507","0508"};
public EditDialog(){
this.setModal(true);
pane5 = new JPanel();
pane6 = new JPanel();
pane = new JPanel();
for(int i=10;i<100;i++){age[i-10]=String.valueOf(i);}
idLabel = new JLabel("id");//id
idText = new JTextField(10);
idText.setToolTipText("revise the student id here!");
idText.addKeyListener(new TextId());
idText.setText(data[row][0]);//id
nameLabel = new JLabel("name");//name
nameText = new JTextField(10);
nameText.setToolTipText("revise the student name here!");
nameText.addKeyListener(new TextName());
nameText.setText(data[row][1]);//name
sexLabel = new JLabel("sex");//sex
sexCombo = new JComboBox(sex);
sexCombo.setToolTipText("revise the student sex here!");
if(data[row][2].equals("women"))sexCombo.setSelectedIndex(1);//sex
ageLabel = new JLabel("age");//age
ageCombo = new JComboBox(age);
ageCombo.setToolTipText("revise the student age here!");
ageCombo.setSelectedIndex(Integer.parseInt(data[row][3])-10);//age
gradeLabel = new JLabel("grade");//grade
gradeCombo = new JComboBox(grade);
gradeCombo.setToolTipText("revise the student grade here!");
if(data[row][4].equals("tongxin"))gradeCombo.setSelectedIndex(1);//grade
classLabel = new JLabel("class");//class
gclassCombo = new JComboBox(gclass);
gclassCombo.setToolTipText("revise the student class here!");
gclassCombo.setSelectedIndex(Integer.parseInt(data[row][5])-501);//class
button_ok = new JButton("ok");//button
button_ok.setToolTipText("click this to makesure the revision!");
button_ok.addActionListener(this);
button_cancel = new JButton("cancel");
button_cancel.setToolTipText("click here to cancel the revision!");
button_cancel.addActionListener(this);//button
BoxLayout layoutPane = new BoxLayout(pane,BoxLayout.Y_AXIS);//set pane1 begin
pane.setLayout(layoutPane);
pane.add(pane5);
pane.add(pane6);
BoxLayout layoutPane5 = new BoxLayout(pane5,BoxLayout.X_AXIS);
pane5.setLayout(layoutPane5);
pane5.add(idLabel);
pane5.add(idText);
pane5.add(nameLabel);
pane5.add(nameText);
pane5.add(sexLabel);
pane5.add(sexCombo);
pane5.add(ageLabel);
pane5.add(ageCombo);
pane5.add(gradeLabel);
pane5.add(gradeCombo);
pane5.add(classLabel);
pane5.add(gclassCombo);
pane6.add(button_ok);
pane6.add(button_cancel);//set pane1 end
this.add(pane);
this.setSize(600,90);
this.setLocation(400,200);
this.setVisible(true);
}
public void actionPerformed(ActionEvent e){
Object obj = e.getSource();
if(obj==button_ok){
String id=idText.getText();
if (id.length()==0||id.length()>9){
Object[] options = {"yes"};
String str = "id lenth wrong";
JOptionPane.showOptionDialog(null,str,"warning",JOptionPane.DEFAULT_OPTION,
JOptionPane.WARNING_MESSAGE,null,options,options[0]);
return;
}
for(three=first;three.prev!=null;three=three.prev){
if(id.equals(three.prev.id)&&!id.equals(data[row][0])){
Object[] options = {"yes"};
String str = "the id exist!";
JOptionPane.showOptionDialog(null,str,"warning",JOptionPane.DEFAULT_OPTION,
JOptionPane.WARNING_MESSAGE,null,options,options[0]);
two.id=null;
return;
}
}
String name=nameText.getText();
if (name.length()==0){
Object[] options = {"yes"};
String str = "name lenth wrong!";
JOptionPane.showOptionDialog(null,str,"warning",JOptionPane.DEFAULT_OPTION,
JOptionPane.WARNING_MESSAGE,null,options,options[0]);
return;
}
data[row][0] = idText.getText();
data[row][1] = nameText.getText();
data[row][2] = sex[sexCombo.getSelectedIndex()];
data[row][3] = age[ageCombo.getSelectedIndex()];
data[row][4] = grade[gradeCombo.getSelectedIndex()];
data[row][5] = gclass[gclassCombo.getSelectedIndex()];
table.repaint();
three=first;
for(int k=0;k<(page-1)*20+row;k++){
three=three.prev;
}
three.id=data[row][0];
three.name=data[row][1];
three.sex=data[row][2];
three.age=data[row][3];
three.grade=data[row][4];
three.gclass=data[row][5];
writeFile();
this.setVisible(false);
}
if(obj==button_cancel){
this.setVisible(false);
}
}
}
}
public class Main {
public Main() {
}
public static void main(String[] args) throws IOException{
/**try{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}catch(Exception win){}*/
ButtonAction menu = new ButtonAction();
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?