当前位置:编程学习 > JAVA >>

关于特别简单的学生信息管理系统的问题。。求解

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class MainFrame extends JFrame{
    JMenuBar jmb;
JMenu insert,query,delete,modify,option;
JPanel panel,panel1,panel2;
public MainFrame()
{
// TODO Auto-generated method stub
jmb=new JMenuBar();
setJMenuBar(jmb);

ImageIcon img=new ImageIcon("12.jpg");
JLabel text1,text2,picture=new JLabel(img);

       JFrame frame=new JFrame("学生成绩管理系统");
       
       option=new JMenu("菜单选项");
       insert=new JMenu("录入学生信息");
       insert.setBackground(Color.green);
       insert.addActionListener(new insertActionPerformed());
       
       query=new JMenu("查询学生信息");
       query.addActionListener(new queryActionPerformed());
       query.setBackground(Color.green);
       
       modify=new JMenu("修改学生信息");
       modify.setBackground(Color.green);
       modify.addActionListener(new modifyActionPerformed());
       
       delete=new JMenu("删除学生信息");
       delete.setBackground(Color.green);
       delete.addActionListener(new deleteActionPerformed());
       
       frame.setSize(360,200);
       frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
       Container contentPane=frame.getContentPane();
       contentPane.setLayout(new BorderLayout());
       text1=new JLabel("欢迎使用学生成绩管理系统",JLabel.CENTER);
       text1.setFont(new Font("宋体",Font.BOLD,24));
   text1.setForeground(Color.blue);
   
   
   panel1=new JPanel();
       panel1.add(insert);
       panel1.add(query);
       panel2=new JPanel();
       panel2.add(modify);
       panel2.add(delete);
       panel1.setOpaque(false);
       panel2.setOpaque(false);
       panel=new JPanel();
       
       panel.add(option,BorderLayout.NORTH);
    
       panel.add(panel1,BorderLayout.NORTH);
       panel.add(panel2,BorderLayout.SOUTH);
       panel.setOpaque(false);
       contentPane.add(text1,BorderLayout.NORTH); //欢迎
       contentPane.add(panel,BorderLayout.CENTER);//panel1+panel2
       
   
     
     
       frame.getLayeredPane().add(picture,new Integer(Integer.MIN_VALUE));
      
       Toolkit kit = Toolkit.getDefaultToolkit();
       Dimension screenSize = kit.getScreenSize();
       int screenWidth = screenSize.width/2;
       int screenHeight = screenSize.height/2;
       int height = this.getHeight(); 
       int width = this.getWidth();
       
       picture.setBounds(0,0,360,360);
      ((JPanel)contentPane).setOpaque(false);
       
       frame.setLocation(screenWidth-width/2, screenHeight-height/2);
       frame.setVisible(true); 
}
 public class insertActionPerformed implements ActionListener
     {
     public void actionPerformed(ActionEvent e)
       {
       new Insert().setVisible(true);
       }    
     }
 public class modifyActionPerformed implements ActionListener
     {
     public void actionPerformed(ActionEvent e)
       {
       new Modify().setVisible(true);
       }    
     }
 public class queryActionPerformed implements ActionListener
     {
     public void actionPerformed(ActionEvent e)
       {
       new Query().setVisible(true);
       }    
     }
 public class deleteActionPerformed implements ActionListener
     {
     public void actionPerformed(ActionEvent e)
       {
       new Delete().setVisible(true);
       }    
     }
       public static void main(String[] args)
       {
     new MainFrame();   
}
}

以上是一个主类 
--------------------编程问答--------------------
插入类
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;

public class Insert extends JFrame 
{
JTextField input1,input2,input3,input4,input5,input6;
JLabel label1,label2,label3,label4,label5;
JButton button;

    static Statement st; 
    static{
     try{
     Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
     Connection  con=DriverManager.getConnection("jdbc:odbc:student");
     st=con.createStatement();
     }
     catch(Exception e){}
    }
    ResultSet rs;

public Insert()
{
input1=new JTextField(15);
input2=new JTextField(15);
input3=new JTextField(15);
input4=new JTextField(15);
input5=new JTextField(15);
input6=new JTextField(15);
JPanel panel=new JPanel();
panel.setLayout(new GridLayout(6,2));
panel.add(new JLabel("学号"),BorderLayout.CENTER);
panel.add(input1);
panel.add(new JLabel("姓名"),BorderLayout.CENTER);
panel.add(input2);
panel.add(new JLabel("班级"),BorderLayout.CENTER);
panel.add(input3);
panel.add(new JLabel("语文"),BorderLayout.CENTER);
panel.add(input4);
panel.add(new JLabel("英语"));
panel.add(input5);
panel.add(new JLabel("数学"));
panel.add(input6);
button=new JButton("添加");
button.addActionListener(new mysql());
Container container=getContentPane();
container.add(panel,BorderLayout.CENTER);
container.add(button,BorderLayout.SOUTH);
setTitle("添加数据窗口");
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setSize(250,250);
  Toolkit kit = Toolkit.getDefaultToolkit();
       Dimension screenSize = kit.getScreenSize();
       int screenWidth = screenSize.width/2;
       int screenHeight = screenSize.height/2;
       int height = this.getHeight(); 
       int width = this.getWidth(); 
      setLocation(screenWidth-width/2, screenHeight-height/2);
setVisible(true);
}

class mysql implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
try
{
String number=input1.getText().trim();
String name=input2.getText().trim();
String clas=input3.getText().trim();
String temp=input4.getText();
int chinese=Integer.parseInt(temp);
temp=input4.getText();
int english=Integer.parseInt(temp);
temp=input4.getText();
int maths=Integer.parseInt(temp);
if(number.equals("")|name.equals("")| clas.equals("")|temp.equals(""))
{
JOptionPane.showMessageDialog(Insert.this,"请重新输入","提示对话框",1);
}
else
{
String sql="insert into ScoreInfo(ID,name,class,Chinese,English,Maths) values('"+number+"','"+name+"','"+clas+"',"+chinese+","+english+","+maths+");";
    st.executeUpdate(sql);
    JOptionPane.showMessageDialog(Insert.this, "数据添加成功","提示对话框",1);
    input1.setText("");
    input2.setText("");
    input3.setText("");
    input4.setText("");
    input5.setText("");
    input6.setText("");
}
}
catch(Exception ee){}
}
}
}
查询类
import java.awt.*;
import javax.swing.event.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;

public class Query extends JFrame{

JTextArea show;
JButton button1,button2,button3,button4,button5;
JTextField field1,field2,field3;
JComboBox comoBox;

static Statement st; 
    static{
     try{
     Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
     Connection  con=DriverManager.getConnection("jdbc:odbc:student");
     st=con.createStatement();
     }
     catch(Exception e){}
    }

public Query()
{
show=new JTextArea(5,10);
button1=new JButton("显示所有信息");
button1.addActionListener(new Mysql1());
Container container=getContentPane();
 container.setLayout(new BorderLayout());
JPanel panel=new JPanel();
JPanel mainpanel=new JPanel();

button2=new JButton("按学号查询");
button2.addActionListener(new Mysql2());
panel.add(button2);
field1=new JTextField(7);
panel.add(field1);
panel.setVisible(true);
mainpanel.add(panel);

button3=new JButton("按姓名查询");
button3.addActionListener(new Mysql3());
panel.add(button3);
field2=new JTextField(6);
panel.add(field2);
panel.setVisible(true);
mainpanel.add(panel);

button4=new JButton("按班级查询");
button4.addActionListener(new Mysql4());
panel.add(button4);
field3=new JTextField(6);
panel.add(field3);
panel.setVisible(true);
mainpanel.add(panel);

String items[]={"请选择","语文","英语","数学"};
comoBox=new JComboBox(items);
button5=new JButton("按课程名称查询");
button5.addActionListener(new Mysql5());
panel.add(button5);
panel.add(comoBox);
panel.setVisible(true);
mainpanel.add(panel);

panel=new JPanel();
panel.add(button1);
container.add(mainpanel,BorderLayout.NORTH);
container.add(panel,BorderLayout.SOUTH);
container.add(new JScrollPane(show),BorderLayout.CENTER);
setTitle("查询数据");
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setSize(750,400);
  Toolkit kit = Toolkit.getDefaultToolkit();
       Dimension screenSize = kit.getScreenSize();
       int screenWidth = screenSize.width/2;
       int screenHeight = screenSize.height/2;
       int height = this.getHeight(); 
       int width = this.getWidth(); 
       setLocation(screenWidth-width/2, screenHeight-height/2);
setVisible(true);
}
class Mysql1 implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
try
{
String sql="select * from ScoreInfo";
ResultSet rs=st.executeQuery(sql);
show.setText("");
show.append("序号               学号                           姓名                        班级                  语文                  英语                  数学"+"\n");
while(rs.next())
{
show.append(rs.getInt(1)+"              ");
show.append(rs.getString(2)+"                ");
show.append(rs.getString(3)+"               ");
show.append(rs.getString(4)+"               ");
show.append(rs.getInt(5)+"                 ");
show.append(rs.getInt(6)+"                ");
show.append(rs.getInt(7)+"\n");
}
}
catch(Exception ee){}
}
}
class Mysql2 implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
try
{
String ss=field1.getText().trim();
String sql="select * from ScoreInfo where ID='"+ss+"'";
ResultSet rs=st.executeQuery(sql);
show.setText("");
show.append("序号               学号                           姓名                        班级                  语文                  英语                  数学"+"\n");
while(rs.next())
{
show.append(rs.getInt(1)+"              ");
show.append(rs.getString(2)+"                ");
show.append(rs.getString(3)+"               ");
show.append(rs.getString(4)+"               ");
show.append(rs.getInt(5)+"                 ");
show.append(rs.getInt(6)+"                ");
show.append(rs.getInt(7)+"\n");
}
}
catch(Exception ee){}
}
}
class Mysql3 implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
try
{
String ss=field2.getText().trim();
String sql="select * from ScoreInfo where name='"+ss+"'";
ResultSet rs=st.executeQuery(sql);
show.setText("");
show.append("序号               学号                           姓名                        班级                  语文                  英语                  数学"+"\n");
while(rs.next())
{
show.append(rs.getInt(1)+"              ");
show.append(rs.getString(2)+"                ");
show.append(rs.getString(3)+"               ");
show.append(rs.getString(4)+"               ");
show.append(rs.getInt(5)+"                 ");
show.append(rs.getInt(6)+"                ");
show.append(rs.getInt(7)+"\n");
}
}
catch(Exception ee){}
}
}
class Mysql4 implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
try
{
String ss=field3.getText().trim();
String sql="select * from ScoreInfo where class='"+ss+"'";
ResultSet rs=st.executeQuery(sql);
show.setText("");
show.append("序号               学号                           姓名                        班级                  语文                  英语                  数学"+"\n");
while(rs.next())
{
show.append(rs.getInt(1)+"              ");
show.append(rs.getString(2)+"                ");
show.append(rs.getString(3)+"               ");
show.append(rs.getString(4)+"               ");
show.append(rs.getInt(5)+"                 ");
show.append(rs.getInt(6)+"                ");
show.append(rs.getInt(7)+"\n");
}
}
catch(Exception ee){}
}
}
class Mysql5 implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
try
{
String sql="";
String ss=comoBox.getSelectedItem().toString();
if(ss.equals("语文"))
{
sql="select ID,name,class,Chinese from ScoreInfo ";
show.setText("");
show.append("序号               学号                           姓名                        班级                  语文"+"\n");
}
else if(ss.equals("英语"))
{
sql="select ID,name,class,English from ScoreInfo ";
show.setText("");
show.append("序号               学号                           姓名                        班级                 英语 "+"\n");
}
else if(ss.equals("数学"))
{
sql="select ID,name,class,Maths from ScoreInfo ";
show.setText("");
show.append("序号               学号                           姓名                        班级                   数学"+"\n");
}
ResultSet rs=st.executeQuery(sql);
int i=0;
while(rs.next())
{
i++;
show.append(""+i+"       "+rs.getString(1)+"              ");
show.append(rs.getString(2)+"               ");
show.append(rs.getString(3)+"              ");
show.append(rs.getInt(4)+"\n");
}
}
catch(Exception ee){}
}
}
}
--------------------编程问答-------------------- 修改类
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;

public class Modify extends JFrame{

JTextField input1,input2,input3,input4,input5,input6;
JLabel label1,label2,label3,label4,label5;
JButton button;

    static Statement st; 
    static{
     try{
     Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
     Connection  con=DriverManager.getConnection("jdbc:odbc:student");
     st=con.createStatement();
     }
     catch(Exception e){}
    }
    ResultSet rs;

public Modify()
{
input1=new JTextField(15);
input2=new JTextField(15);
input3=new JTextField(15);
input4=new JTextField(15);
input5=new JTextField(15);
input6=new JTextField(15);
JPanel panel=new JPanel();
panel.setLayout(new GridLayout(6,2));
panel.add(new JLabel("学号"));
panel.add(input1);
panel.add(new JLabel("姓名"));
panel.add(input2);
panel.add(new JLabel("班级"));
panel.add(input3);
panel.add(new JLabel("语文"));
panel.add(input4);
panel.add(new JLabel("英语"));
panel.add(input5);
panel.add(new JLabel("数学"));
panel.add(input6);
button=new JButton("修改");
button.addActionListener(new mysql());
Container container=getContentPane();
container.add(panel,BorderLayout.CENTER);
container.add(button,BorderLayout.SOUTH);
setTitle("修改数据窗口");
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setSize(300,150);
    Toolkit kit = Toolkit.getDefaultToolkit();
    Dimension screenSize = kit.getScreenSize();
    int screenWidth = screenSize.width/2;
    int screenHeight = screenSize.height/2;
    int height = this.getHeight(); 
    int width = this.getWidth(); 
    setLocation(screenWidth-width/2, screenHeight-height/2);
setVisible(true);
}

class mysql implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
try
{
String number=input1.getText().trim();
String name=input2.getText().trim();
String clas=input3.getText().trim();
String temp=input4.getText();
int chinese=Integer.parseInt(temp);
temp=input4.getText();
int english=Integer.parseInt(temp);
temp=input4.getText();
int maths=Integer.parseInt(temp);
if(number.equals(""))
{
JOptionPane.showMessageDialog(Modify.this,"学号不能为空!","提示对话框",1);
}
else
{
try{
String sql="update ScoreInfo set name='"+name+"',class='"+clas+"',Chinese="+chinese+",English="+english+",Maths="+maths+" where ID='"+number+"'";
    st.executeUpdate(sql);
    JOptionPane.showMessageDialog(Modify.this, "数据修改成功","提示对话框",1);
    input1.setText("");
    input2.setText("");
    input3.setText("");
    input4.setText("");
    input5.setText("");
    input6.setText("");
}
catch(Exception ee)
{
JOptionPane.showMessageDialog(Modify.this,"请确认需要修改的学号是否存在","提示对话框",1);
 System.out.println(ee);
}
}
}
catch(Exception eee)
{
 System.out.println(eee);
}
}
}  
}

还有一个Delete类
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;

public class Delete extends JFrame
{
JButton search;
JTextField input;
JTextArea show;

Connection con;
    Statement st; 

public Delete()
{
JPanel p=new JPanel();
search= new JButton("删除");
input= new JTextField(10);
show= new JTextArea(6,43);
p.add(new JLabel("输入要删除的学号"));
p.add(input);
p.add(search);
setTitle("删除数据窗口");
search.addActionListener(new Mysql());
show.setEditable(false);
add(p,BorderLayout.NORTH);
add(show,BorderLayout.CENTER);
setSize(400,150);
    Toolkit kit = Toolkit.getDefaultToolkit();
    Dimension screenSize = kit.getScreenSize();
    int screenWidth = screenSize.width/2;
    int screenHeight = screenSize.height/2;
    int height = this.getHeight(); 
    int width = this.getWidth(); 
    setLocation(screenWidth-width/2, screenHeight-height/2);
setVisible(true);
validate();
addWindowListener(new WindowAdapter()
        {
public void windowClosing(WindowEvent e)
        {
dispose();
}
});
}

class Mysql implements ActionListener
{
public void actionPerformed(ActionEvent ee) 
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");  
        }
         catch(ClassNotFoundException eee)
        { 
          System.out.println(""+eee);
        }
    try
    { 
     String ss=input.getText().trim();
        con=DriverManager.getConnection("jdbc:odbc:student");
           st=con.createStatement();
           String sql="select * from ScoreInfo where ID='"+ss+"'";
           show.setText(sql);
ResultSet rs=st.executeQuery(sql);
while(rs.next())
{
          String  number=rs.getString("ID");
        
          String  name=rs.getString("name");  
             String    clas=rs.getString("class");
             int     chinese=rs.getInt("Chinese"); 
             int  english=rs.getInt("English");
             int     math=rs.getInt("Maths"); 
              show.setText("你删除了:\n");
              show.append("学号:"+number+"\n姓名:"+name+"\n班级:"+clas+"\n语文"+chinese+"\n英语 "+english+"\n数学 "+math);
              show.append("\n");
             sql="delete * from ScoreInfo where ID='"+ss+"'";
             st.executeUpdate(sql);
}
          con.close();
         }
           catch(SQLException e) 
           {  
            show.setText("无此条记录");
            System.out.println(e);
           }
   }    

}
这就是这个程序的内容
我想把程序做成这个样子 --------------------编程问答-------------------- 但是运行起来就蛋疼了,代码我是借鉴的,然后自己修改了下,但是还是做不到这个效果,求帮助 --------------------编程问答-------------------- 又到了一年该做毕业设计的时间了 --------------------编程问答-------------------- 求帮助啊,大哥,现在在烦恼中。。 --------------------编程问答-------------------- 好头疼。。。。
补充:Java ,  Eclipse
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,