?? jctx.java
字號(hào):
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
import java.sql.*;
//主函數(shù)、主要類
public class JCTX{
public static void main(String []args)
{
new Frm_Main();
}
}
//實(shí)現(xiàn)類
class Frm_Main implements ActionListener //throws IOException
{
int bz;
JFrame frame;
Container c;
JMenuBar menuBar;
JMenu mainMenu1;
JMenu mainMenu2;
JMenu mainMenu3;
JMenuItem subMenu1[] = new JMenuItem[5];
JMenuItem subMenu2[] = new JMenuItem[7];
JMenuItem subMenu3[] = new JMenuItem[2];
JButton toolBarButton[] = new JButton[8];
JToolBar toolBar;
//////////////////////////////////////////////
String strTip[] = {"查詢您要找的學(xué)生記錄...","添加學(xué)生記錄...","刪除已有的學(xué)生記錄","修改學(xué)生記錄...","保存你的操作結(jié)果","向下逐個(gè)瀏覽記錄","退出本系統(tǒng)..."};
//////////////////////////////////////////////
String id = new String();
String name = new String();
String xb = new String();
String dw = new String();
String dh1 = new String();
String dh2 = new String();
String zw = new String();
String email = new String();
String dz = new String();
String yb = new String();
//////////////////////////////////////////////
///////////////////////////////////////////////
public JLabel idL = new JLabel("編號(hào):");
public JLabel nameL = new JLabel("姓名:");
public JLabel xbL = new JLabel("性別:");
public JLabel dwL = new JLabel("單位:");
public JLabel zwL = new JLabel("職務(wù):");
public JLabel dh1L = new JLabel("電話一:");
public JLabel dh2L = new JLabel("電話二:");
public JLabel emailL = new JLabel("電子信箱:");
public JLabel dzL = new JLabel("地址:");
public JLabel ybL = new JLabel("郵編:");
public JTextField idT = new JTextField();
public JTextField nameT = new JTextField();
public JTextField xbT = new JTextField();
public JTextField dwT = new JTextField();
public JTextField zwT = new JTextField();
public JTextField dh1T = new JTextField();
public JTextField dh2T = new JTextField();
public JTextField emailT = new JTextField();
public JTextField dzT = new JTextField();
public JTextField ybT = new JTextField();
public JButton next=new JButton("下一個(gè)");
//////////////////////////////////////////////
public Connection con;
public ResultSet rs;
public Statement st;
//////////////////////////////////////////////
public Frm_Main()
{
/////////////////////////////////////////////////
frame = new JFrame("簡易名片信息管理子系統(tǒng)");
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ù)名片信息");
String str2[] = {"查詢記錄","添加記錄","刪除記錄","修改記錄","保存結(jié)果"};
for(int i=0;i<5;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[] ={"查詢","添加","刪除","修改","保存","瀏覽","退出"};
for(int i=0;i<7;i++)
{
toolBarButton[i] = new JButton(strToolBar[i]);
toolBarButton[i].setToolTipText(strTip[i]);
toolBarButton[i].addActionListener(this);
toolBar.add(toolBarButton[i]);
}
toolBarButton[4].setEnabled(false);
toolBar.setLocation(0,0);
toolBar.setSize(400,30);
c.add(toolBar);
////////////////////////////////////////////////
idL.setLocation(35,40);
idL.setSize(40,20);
c.add(idL);
idT.setLocation(110,40);
idT.setSize(200,20);
idT.setEnabled(false);
c.add(idT);
nameL.setLocation(35,70);
nameL.setSize(40,20);
c.add(nameL);
nameT.setLocation(110,70);
nameT.setSize(200,20);
c.add(nameT);
xbL.setLocation(35,100);
xbL.setSize(40,20);
c.add(xbL);
xbT.setLocation(110,100);
xbT.setSize(200,20);
c.add(xbT);
dwL.setLocation(35,130);
dwL.setSize(40,20);
c.add(dwL);
dwT.setLocation(110,130);
dwT.setSize(200,20);
c.add(dwT);
dh1L.setLocation(35,160);
dh1L.setSize(60,20);
c.add(dh1L);
dh1T.setLocation(110,160);
dh1T.setSize(200,20);
c.add(dh1T);
dh2L.setLocation(35,190);
dh2L.setSize(60,20);
c.add(dh2L);
dh2T.setLocation(110,190);
dh2T.setSize(200,20);
c.add(dh2T);
zwL.setLocation(35,220);
zwL.setSize(40,20);
c.add(zwL);
zwT.setLocation(110,220);
zwT.setSize(200,20);
c.add(zwT);
emailL.setLocation(35,250);
emailL.setSize(80,20);
c.add(emailL);
emailT.setLocation(110,250);
emailT.setSize(200,20);
c.add(emailT);
dzL.setLocation(35,280);
dzL.setSize(40,20);
c.add(dzL);
dzT.setLocation(110,280);
dzT.setSize(200,20);
c.add(dzT);
ybL.setLocation(35,310);
ybL.setSize(40,20);
c.add(ybL);
ybT.setLocation(110,310);
ybT.setSize(200,20);
c.add(ybT);
next.setLocation(150,350);
next.setSize(80,20);
next.addActionListener(this);
next.setVisible(false);
c.add(next);
idT.setEnabled(false);
nameT.setEnabled(false);
xbT.setEnabled(false);
dwT.setEnabled(false);
dh1T.setEnabled(false);
dh2T.setEnabled(false);
zwT.setEnabled(false);
emailT.setEnabled(false);
dzT.setEnabled(false);
ybT.setEnabled(false);
/////////////////////////////////////////////////
JLabel information = new JLabel("樣例程序");
information.setFont(new Font("宋體",Font.BOLD,24));
information.setSize(200,110);
information.setLocation(10,320);
c.add(information);
////////////////////////////////////////////////
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(400,450);
frame.setVisible(true);
bz=0;
conDB();
}
//以上是設(shè)置數(shù)據(jù)庫面版、框架(構(gòu)造函數(shù))
//以下是連接數(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:zht","","");
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()==toolBarButton[5]) //瀏覽記錄
{
next.setVisible(true);
String strSQL = "select * from user_1";
try
{
rs = st.executeQuery(strSQL);
if(rs.next())
{
id = rs.getString("id");
name = rs.getString("name");
xb=rs.getString("xb");
dw=rs.getString("dw");
dh1=rs.getString("dh1");
dh2=rs.getString("dh2");
zw=rs.getString("zw");
email=rs.getString("email");
dz=rs.getString("dz");
yb=rs.getString("yb");
}
else
{
JOptionPane.showMessageDialog(null,"對不起,沒有您要查找客戶");
}
idT.setText(id);
nameT.setText(name);
xbT.setText(xb);
dwT.setText(dw);
dh1T.setText(dh1);
dh2T.setText(dh2);
zwT.setText(zw);
emailT.setText(email);
dzT.setText(dz);
ybT.setText(yb);
nameT.setEnabled(false);
xbT.setEnabled(false);
dwT.setEnabled(false);
dh1T.setEnabled(false);
dh2T.setEnabled(false);
zwT.setEnabled(false);
emailT.setEnabled(false);
dzT.setEnabled(false);
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -