?? 2004060610031029501java
字號:
//import java.lang.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
import java.sql.*;
//華瑞工作室\uFFFD簡易學(xué)生信息管理系統(tǒng)1.0版
//程序作者:蔡茂華
//制作日期:2004-04-25
//聯(lián)系方式QQ:253692170
//單位:長沙民政學(xué)院計算機系計應(yīng)0235
//////////////////////////////////////////////
//程序說明
//您要建立一個數(shù)據(jù)庫(DBMS不限)
//屬性為id sex name nation deparment birthday
//都為字符型
//然后建立數(shù)據(jù)源
//數(shù)據(jù)源名稱為jctx
//表名:Coolboy
//本人編譯器J2SDK1.4.2
//////////////////////////////////////////////
//主函數(shù)、主要類
public class JCTX{
public static void main(String []args)
{
new Frm_Main();
}
}
//實現(xiàn)類
class Frm_Main implements ActionListener //throws IOException
{
public JFrame frame;
public Container c;
public JMenuBar menuBar;
public JMenu mainMenu1;
public JMenu mainMenu2;
public JMenu mainMenu3;
public JMenuItem subMenu1[] = new JMenuItem[5];
public JMenuItem subMenu2[] = new JMenuItem[7];
public JMenuItem subMenu3[] = new JMenuItem[2];
JButton toolBarButton[] = new JButton[8];
public JToolBar toolBar;
//////////////////////////////////////////////
String strTip[] = {"查詢您要找的學(xué)生記錄...","添加學(xué)生記錄...","刪除已有的學(xué)生記錄","修改學(xué)生記錄...","使您修改的學(xué)生記錄生效...","使您添加的學(xué)生記錄生效...","確認(rèn)刪除當(dāng)前記錄...","退出本系統(tǒng):)"};
//////////////////////////////////////////////
String id = new String();
String name = new String();
String sex = new String();
String nation = new String();
String birthday = new String();
String department = new String();
//////////////////////////////////////////////
Connection con;
ResultSet rs;
Statement st;
///////////////////////////////////////////////
public JLabel idL = new JLabel("學(xué)號:");
public JLabel nameL = new JLabel("姓名:");
public JLabel sexL = new JLabel("性別:");
public JLabel nationL = new JLabel("民族:");
public JLabel departmentL = new JLabel("專業(yè):");
public JLabel birthdayL = new JLabel("生日:");
public JTextField idT = new JTextField();
public JTextField nameT = new JTextField();
public JTextField sexT = new JTextField();
public JTextField nationT = new JTextField();
public JTextField departmentT = new JTextField();
public JTextField birthdayT = new JTextField();
//////////////////////////////////////////////
//////////////////////////////////////////////
public Frm_Main()
{
/////////////////////////////////////////////////
frame = new JFrame("華瑞工作室-簡易學(xué)生信息管理子系統(tǒng)1.0版");
c = frame.getContentPane();
c.setLayout(null);
menuBar = new JMenuBar();
toolBar = new JToolBar();
toolBar.setFloatable(false);
frame.setJMenuBar(menuBar);
frame.setResizable(false);
////////////////////////////////////////////////
mainMenu1 = new JMenu("管理");
String str1[] = {"添加用戶","刪除用戶","查詢用戶"," ","退出"};
for(int i=0;i<5;i++)
{
if(i==3)
mainMenu1.addSeparator();
else
{
subMenu1[i] = new JMenuItem(str1[i]);
subMenu1[i].addActionListener(this);
mainMenu1.add(subMenu1[i]);
}
}
menuBar.add(mainMenu1);
/////////////////////////////////////////////////
mainMenu2 = new JMenu("維護(hù)學(xué)生信息");
String str2[] = {"查詢記錄","添加記錄","刪除記錄","修改記錄","提交修改","提交添加","確認(rèn)刪除"};
for(int i=0;i<7;i++)
{
subMenu2[i] = new JMenuItem(str2[i]);
subMenu2[i].addActionListener(this);
mainMenu2.add(subMenu2[i]);
}
menuBar.add(mainMenu2);
/////////////////////////////////////////////////
mainMenu3 = new JMenu("幫助");
String str3[] = {"幫助...","關(guān)于..."};
for(int i=0;i<2;i++)
{
subMenu3[i] = new JMenuItem(str3[i]);
subMenu3[i].addActionListener(this);
mainMenu3.add(subMenu3[i]);
}
menuBar.add(mainMenu3);
////////////////////////////////////////////////
String strToolBar[] ={"查詢","添加","刪除","修改","提交修改","提交添加","確認(rèn)刪除","關(guān)于"};
for(int i=0;i<8;i++)
{
toolBarButton[i] = new JButton(strToolBar[i]);
toolBarButton[i].setToolTipText(strTip[i]);
toolBarButton[i].addActionListener(this);
toolBar.add(toolBarButton[i]);
}
toolBar.setLocation(0,0);
toolBar.setSize(400,30);
c.add(toolBar);
////////////////////////////////////////////////
idL.setLocation(35,40);
idL.setSize(40,20);
//idL.setFont(new Font("宋體",Font.BOLD,12));
c.add(idL);
idT.setLocation(90,40);
idT.setSize(200,20);
//idT.setEnabled(false);
c.add(idT);
nameL.setLocation(35,70);
nameL.setSize(40,20);
c.add(nameL);
nameT.setLocation(90,70);
nameT.setSize(200,20);
c.add(nameT);
sexL.setLocation(35,100);
sexL.setSize(40,20);
c.add(sexL);
sexT.setLocation(90,100);
sexT.setSize(200,20);
c.add(sexT);
nationL.setLocation(35,130);
nationL.setSize(40,20);
c.add(nationL);
nationT.setLocation(90,130);
nationT.setSize(200,20);
c.add(nationT);
departmentL.setLocation(35,160);
departmentL.setSize(40,20);
c.add(departmentL);
departmentT.setLocation(90,160);
departmentT.setSize(200,20);
c.add(departmentT);
birthdayL.setLocation(35,190);
birthdayL.setSize(40,20);
c.add(birthdayL);
birthdayT.setLocation(90,190);
birthdayT.setSize(200,20);
c.add(birthdayT);
/////////////////////////////////////////////////
JLabel information = new JLabel("華瑞工作室");
information.setFont(new Font("宋體",Font.BOLD,35));
information.setSize(380,110);
information.setLocation(10,210);
c.add(information);
////////////////////////////////////////////////
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(400,400);
frame.setLocation(200,200);
frame.setVisible(true);
conDB();
}
//以上是設(shè)置數(shù)據(jù)庫面版、框架
//以下是連接數(shù)據(jù)庫
public void conDB()
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e)
{
JOptionPane.showMessageDialog(null,"華瑞工作室提示您數(shù)據(jù)庫加載失敗了,呵呵!");
}
try
{
con = DriverManager.getConnection("jdbc:odbc:jctx","sa","");
st = con.createStatement();
}
catch(SQLException e)
{
JOptionPane.showMessageDialog(null,"華瑞工作室提示您數(shù)據(jù)庫連接失敗了,呵呵!");
}
}
//以下是關(guān)閉數(shù)據(jù)庫
public void closeDB()
{
try
{
st.close();
con.close();
}
catch(SQLException e )
{
JOptionPane.showMessageDialog(null,"華瑞工作室提示您數(shù)據(jù)庫關(guān)閉失敗了,呵呵!");
}
}
//以下是針對數(shù)據(jù)庫的各種操作
public void actionPerformed(ActionEvent e)
{
//////////////////////////////////////////////////////////////////////////////////////
if(e.getSource()==subMenu3[1] ||e.getSource()==toolBarButton[7])
JOptionPane.showMessageDialog(null,"本軟件由華瑞工作室編寫");
///////////////////////////////////////////////////////////////////////////////////
if(e.getSource()==subMenu1[0] || e.getSource()==subMenu1[1] || e.getSource()==subMenu1[2] )
JOptionPane.showMessageDialog(null,"本功能不打算實現(xiàn)了,您可以自己編寫!");
/////////////////////////////////////////////////////////////////////////////////////
//查找功能的實現(xiàn)
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -