Java swing(1)自己設(shè)計完善的獨(dú)特功能圖書管理系統(tǒng),獲取下拉框等的文字內(nèi)容

結(jié)構(gòu)總框架:

本篇所含框架:

gif圖片素材:


package denglu;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
public class chongzhimimajiemian extends JFrame {
static JButton JButton_QuRen = null;
static JLabel JLabel1, JLabel2 = null;
static JPasswordField JPasswordField_qslmm1, JPasswordField_qslmm2 = null;
public chongzhimimajiemian() {
this.setLayout(null);
this.setTitle("重置密碼頁面");
this.setSize(500, 500);
this.setLocationRelativeTo(null);
this.setVisible(true);
JLabel1 = new JLabel("請輸入密碼");
JLabel2 = new JLabel("請再次輸入密碼");
JLabel1.setBounds(100, 100, 100, 30);
this.add(JLabel1);
JLabel2 = new JLabel("請再次輸入密碼");
JLabel2.setBounds(100, 140, 100, 30);
this.add(JLabel2);
JButton_QuRen = new JButton("確認(rèn)修改");
JButton_QuRen.setBounds(100, 290, 150, 30);
this.add(JButton_QuRen);
JButton_QuRen.addActionListener(new shijian_queRenXiuGai(this));
JPasswordField_qslmm1 = new JPasswordField();
JPasswordField_qslmm2 = new JPasswordField();
JPasswordField_qslmm1.setBounds(280, 100, 100, 30);
JPasswordField_qslmm2.setBounds(280, 140, 100, 30);
this.add(JPasswordField_qslmm1);
this.add(JPasswordField_qslmm2);
}
}
class shijian_queRenXiuGai implements ActionListener {
static chongzhimimajiemian chuangKou = null;
public shijian_queRenXiuGai(chongzhimimajiemian chuanzhi) {
this.chuangKou = chuanzhi;
/*
* 個人理解:先聲明空的窗口(chuangKou),之后屬性都儲存到窗口中,之后傳值(chuanzhi)賦值給窗口的所有屬性,
* 因為“chongzhimimajiemian
* chuanzhi”的聲明,chuanzhi有chongzhimimajiemian中的所有內(nèi)容
*/
}
@Override
public void actionPerformed(ActionEvent arg0) {
if (arg0.getActionCommand().equals("確認(rèn)修改")) {
JOptionPane.showMessageDialog(null, "點(diǎn)擊了修改密碼按鈕");
// 點(diǎn)擊了“確認(rèn)修改”之后要用if比較一下兩個密碼輸入的是否一致
String pwd1 = chuangKou.JPasswordField_qslmm1.getText();
String pwd2 = chuangKou.JPasswordField_qslmm2.getText();
if (pwd1.equals(pwd2)) {
// 如果相等就做進(jìn)一步的修改密碼
// SQL語句如何加條件:就是where后面加上zhmm(找回密碼)頁面的uname屬性,可以直接調(diào)用
// 聲明一個工具類,用來保存用戶要修改的用戶名,什么時候想要使用直接調(diào)用就好
String uname = gongjvClass.uname;// 獲取到用戶要修改的用戶名
String sql = "update yonghu set yh_pwd='" + pwd1
+ "' where yh_uname= '" + uname + "'";
if (DBUtils.ZSG(sql)) {
JOptionPane.showMessageDialog(null, "密碼重置成功");
} else {
JOptionPane.showMessageDialog(null, "出現(xiàn)了未知的錯誤,請重試!");
}
} else {
// 不相等就提示用戶兩次密碼輸入不一致
JOptionPane.showMessageDialog(null, "兩次密碼輸入不一致");
return;
}
}
}
}


package denglu;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
/*DBUtis封裝了對JDBC的操作,簡化了JDBC操作??梢陨賹懘a。
?1對于數(shù)據(jù)表的讀操作,他可以把結(jié)果轉(zhuǎn)換成List,Aray, Set等java集合, 便于程序員操作:
?2.對于數(shù)據(jù)表的寫操作,也變得很簡單(只需寫sql語句)
?3.可以使用數(shù)據(jù)源,使用JNDI, 數(shù)據(jù)庫連接池等技術(shù)來優(yōu)化性能-重用已經(jīng)構(gòu)建好的數(shù)據(jù)庫連
?注意,在使用DBUtis過程中,需要在C3P0Utils中添加getDateSource方法。*/
public class DBUtils {
private static Connection con = null;
private static ResultSet res = null;
private static Statement sta = null;
static {
try {
Class.forName("com.microsoft.sqlserver." + "jdbc.SQLServerDriver");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
public static Connection getCon() {
if (con == null) {
try {
con = DriverManager.getConnection(
"jdbc:sqlserver://DESKTOP-49FTFSP;"
+ "databaseName=yonghu", "sa", "1234abcd");
} catch (SQLException e) {
e.printStackTrace();
}
}
return con;
}
public static ResultSet Select(String sql) {
/* Select為用于查找的靜態(tài)方法 */
con = getCon();
try {
sta = con.createStatement();
res = sta.executeQuery(sql);
} catch (SQLException e) {
e.printStackTrace();
}
return res;
}
public static boolean ZSG(String sql) {
/* ZXG為用于增加(Z)或修改(G)或刪除(S)的靜態(tài)方法,命名不可太長不然這里會不管用 */
boolean b = false;
con = getCon();
try {
sta = con.createStatement();
int num = sta.executeUpdate(sql);
if (num > 0) {
b = true;
}
} catch (SQLException e) {
e.printStackTrace();
}
return b;
}
}


package denglu;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
public class denglu extends JFrame {
public static JButton JButton_dl, JButton_qx, JButton_zc,
JButton_zhmm, JButton_gly = null;
static JComboBox JComboBox_type = null;
public static JLabel JLabel_uname, JLabel_pwd, lb_img = null;
public static JPasswordField JPasswordField_pwd1 = null;
public static JTextField JTextField_unametxt1 = null;
public JPanel jp1 = null;
public denglu() {
this.setLayout(null);
this.setSize(640, 400);
this.setLocationRelativeTo(null);
JLabel_uname = new JLabel("用戶名");
JLabel_pwd = new JLabel("密碼");
JComboBox_type = new JComboBox();
JComboBox_type.addItem("普通用戶");
JComboBox_type.addItem("管理員用戶");
JComboBox_type.setBounds(370, 100, 170, 30);
this.add(JComboBox_type);
JLabel_uname.setBounds(100, 100, 70, 30);
JLabel_pwd.setBounds(100, 140, 70, 30);
// 圖片
lb_img = new JLabel();
lb_img.setBounds(30, 0, 580, 100);
lb_img.setIcon(new ImageIcon("img//beijing.gif"));
jp1 = new JPanel();
jp1.setLayout(null);
jp1.setBounds(30, 0, 580, 100);
jp1.add(lb_img);
this.add(jp1);
this.add(JLabel_uname);
this.add(JLabel_pwd);
JTextField_unametxt1 = new JTextField();
JPasswordField_pwd1 = new JPasswordField();
JTextField_unametxt1.setBounds(180, 100, 140, 30);
JPasswordField_pwd1.setBounds(180, 140, 140, 30);
this.add(JTextField_unametxt1);
this.add(JPasswordField_pwd1);
JButton_dl = new JButton("普通用戶登錄");
JButton_dl.setBounds(60, 180, 130, 35);
JButton_dl.addActionListener(new shijian_denglu(this));
JButton_qx = new JButton("取消");
JButton_qx.setBounds(250, 240, 70, 35);
JButton_gly = new JButton("管理員用戶登錄");
JButton_gly.setBounds(60, 240, 130, 35);
JButton_gly.addActionListener(new shijian_denglu(this));
// JButton_qx.setBounds(arg0(下標(biāo)為0的值), arg1, arg2, arg3);
JButton_qx.addActionListener(new shijian_denglu(this));
JButton_zc = new JButton("普通用戶注冊");
JButton_zc.setBounds(250, 180, 120, 35);
JButton_zc.addActionListener(new shijian_denglu(this));
JButton_zhmm = new JButton("找回密碼");
JButton_zhmm.setBounds(430, 180, 90, 35);
JButton_zhmm.addActionListener(new shijian_denglu(this));
this.add(JButton_zc);
this.add(JButton_dl);
this.add(JButton_qx);
this.add(JButton_zhmm);
this.add(JButton_gly);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
}
class shijian_denglu implements ActionListener {
public denglu shijian_dengLu1 = null;
public shijian_denglu(denglu shijian_dengLu2) {
shijian_dengLu1 = shijian_dengLu2;
}
@Override
public void actionPerformed(ActionEvent arg0) {
// JOptionPane.showMessageDialog(null, "點(diǎn)擊");
if (arg0.getActionCommand().equals("管理員用戶登錄")) {
String uname = shijian_dengLu1.JTextField_unametxt1.getText()
.trim();// 從shijian_dengLu1中的JTextField_unametxt1獲取用戶輸入的用戶名文本內(nèi)容
String pwd = shijian_dengLu1.JPasswordField_pwd1.getText().trim();// 獲取密碼
String String_type = shijian_dengLu1.JComboBox_type
.getSelectedItem().toString();
String sql = "select * from yonghu where yh_uname='" + uname
+ "'and yh_pwd='" + pwd + "'and yh_type='" + String_type + "'";
ResultSet res = DBUtils.Select(sql);
try {// res.next()表明尋找res中的內(nèi)容,如果res中有數(shù)據(jù),登錄成功,否則登錄失敗
if (res.next()) {
JOptionPane.showMessageDialog(null, "登錄成功");
new guanLiYuanYongHuJieMian();
shijian_dengLu1.setVisible(false);
} else {
JOptionPane.showMessageDialog(null,
"用戶名或密碼錯誤或你不是管理員用戶或用戶類型選擇錯誤");
}
} catch (SQLException e) {
e.printStackTrace();
}
}
if (arg0.getActionCommand().equals("普通用戶登錄")) {
String uname = shijian_dengLu1.JTextField_unametxt1.getText()
.trim();// 從shijian_dengLu1中的JTextField_unametxt1獲取用戶輸入的用戶名文本內(nèi)容
String pwd = shijian_dengLu1.JPasswordField_pwd1.getText().trim();// 獲取密碼
String String_type = shijian_dengLu1.JComboBox_type
.getSelectedItem().toString();
String sql = "select * from yonghu where yh_uname='" + uname
+ "'and yh_pwd='" + pwd + "'and yh_type='" + String_type + "'";
ResultSet res = DBUtils.Select(sql);
try {// res.next()表明尋找res中的內(nèi)容,如果res中有數(shù)據(jù),登錄成功,否則登錄失敗
if (res.next()) {
JOptionPane.showMessageDialog(null, "登錄成功");
new puTongYongHuJieMian();
shijian_dengLu1.setVisible(false);
} else {
JOptionPane.showMessageDialog(null,
"用戶名或密碼錯誤或你不是普通用戶或用戶類型選擇錯誤");
}
} catch (SQLException e) {
e.printStackTrace();
}
}
else if (arg0.getActionCommand().equals("普通用戶注冊")) {
JOptionPane.showMessageDialog(null, "點(diǎn)擊了注冊按鈕");
new zhuCe();
} else if (arg0.getActionCommand().equals("找回密碼")) {
JOptionPane.showMessageDialog(null, "點(diǎn)擊了找回密碼按鈕");
new zhaoHuiMiMa();
// dd. setVisible(false);
} else if (arg0.getActionCommand().equals("取消")) {
JOptionPane.showMessageDialog(null, "點(diǎn)擊了取消按鈕");
// dd. setVisible(false);
}
}
}


package denglu;
public class gongjvClass {
public static String uname = "";
}


package denglu;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.table.DefaultTableModel;
public class guanLiYuanYongHuJieMian extends JFrame {
class shijian_table2 implements MouseListener, ActionListener {
public guanLiYuanYongHuJieMian HanDengLuHouJieMianNeiRong = null;
public shijian_table2(guanLiYuanYongHuJieMian dengLuHouJieMianNeiRong2) {
this.HanDengLuHouJieMianNeiRong = dengLuHouJieMianNeiRong2;
}
@Override
public void actionPerformed(ActionEvent arg0) {
String name = HanDengLuHouJieMianNeiRong.wenBenKuang_name.getText();
String price = HanDengLuHouJieMianNeiRong.wenBenKuang_price
.getText();
String type = HanDengLuHouJieMianNeiRong.wenBenKuang_typeid
.getText();
String jieshao = HanDengLuHouJieMianNeiRong.wenBenKuang_spjieshao
.getText();
// ArrayList<String> jiHe = new ArrayList<String>();
// // jiHe集合
//
// if (HanDengLuHouJieMianNeiRong.address1.isSelected()) {
// jiHe.add(HanDengLuHouJieMianNeiRong.address1.getText());
// }
// if (HanDengLuHouJieMianNeiRong.address2.isSelected()) {
// jiHe.add(HanDengLuHouJieMianNeiRong.address2.getText());
// }
// if (HanDengLuHouJieMianNeiRong.address3.isSelected()) {
// jiHe.add(HanDengLuHouJieMianNeiRong.address3.getText());
// }
// String typeName = HanDengLuHouJieMianNeiRong.xiaLaKuang
// .getSelectedItem().toString();
String sql = "insert into tushu values('" + name + "'" + ","
+ price + "," + type + ",'" + jieshao + "')";
// String sql2 = "insert into ts_type(ts_typename) values('"
// + typeName + "')";
// if (DBUtils.ZSG(sql) && DBUtils.ZSG(sql2)) {
if (DBUtils.ZSG(sql)) {
JOptionPane.showMessageDialog(null, "增加成功");
HanDengLuHouJieMianNeiRong.chaxunchushihua();
} else {
JOptionPane.showMessageDialog(null, "出現(xiàn)了未知的錯誤,增加失敗");
}
}
@Override
public void mouseClicked(MouseEvent arg0) {
if (arg0.getClickCount() == 2) {
int row = HanDengLuHouJieMianNeiRong.biaoGe1.getSelectedRow();
String leixing = HanDengLuHouJieMianNeiRong.biaoGe1.getValueAt(
row, 4).toString();
HanDengLuHouJieMianNeiRong.wenBenKuang_Bianhao
.setText(HanDengLuHouJieMianNeiRong.biaoGe1.getValueAt(
row, 0).toString());
HanDengLuHouJieMianNeiRong.wenBenKuang_name
.setText(HanDengLuHouJieMianNeiRong.biaoGe1.getValueAt(
row, 1).toString());
HanDengLuHouJieMianNeiRong.wenBenKuang_price
.setText(HanDengLuHouJieMianNeiRong.biaoGe1.getValueAt(
row, 2).toString());
HanDengLuHouJieMianNeiRong.wenBenKuang_typeid
.setText(HanDengLuHouJieMianNeiRong.biaoGe1.getValueAt(
row, 3).toString());
HanDengLuHouJieMianNeiRong.wenBenKuang_spjieshao
.setText(HanDengLuHouJieMianNeiRong.biaoGe1.getValueAt(
row, 5).toString());
HanDengLuHouJieMianNeiRong.wenBenKuang_typename
.setText(leixing);
// 給下拉框內(nèi)容賦值:
for (int i = 0; i < HanDengLuHouJieMianNeiRong.xiaLaKuang
.getItemCount(); i++) {
if (HanDengLuHouJieMianNeiRong.xiaLaKuang.getItemAt(i)
.toString().equals(leixing)) {
HanDengLuHouJieMianNeiRong.xiaLaKuang
.setSelectedItem(leixing);
}
}
}
if (arg0.isMetaDown()) {
int num = JOptionPane.showConfirmDialog(null, "是否確認(rèn)刪除這條信息?");
if (num == 0) {
int row = HanDengLuHouJieMianNeiRong.biaoGe1
.getSelectedRow();
String sql = "delete tushu where ts_id="
+ HanDengLuHouJieMianNeiRong.biaoGe1.getValueAt(
row, 0) + "";
if (DBUtils.ZSG(sql)) {
JOptionPane.showMessageDialog(null, "冊除成功");
HanDengLuHouJieMianNeiRong.chaxunchushihua();
// 刪除成功再查詢一遍表格就可以實(shí)現(xiàn)表格的刷新,但是我們的查詢寫在了構(gòu)造方法里,內(nèi)容很多,
// 這里想要使用又要在寫一遍,很麻煩,那么現(xiàn)在我們寫一個方法 將查詢內(nèi)容封裝進(jìn)去,再想查詢的
// 時候只要調(diào)用查詢的方法即可
} else {
JOptionPane.showMessageDialog(null, "出現(xiàn)了未知的錯誤,請重試");
}
}
}
}
@Override
public void mouseEntered(MouseEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void mouseExited(MouseEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void mousePressed(MouseEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void mouseReleased(MouseEvent arg0) {
// TODO Auto-generated method stub
}
}
static JButton anNiu_zengJia = null;
// gunDongTiao(滾動條)
static JTable biaoGe1 = null;
// xiaLaKuang(下拉框)
static DefaultTableModel biaoGeMoXing1 = null;
// biaoGeMoXing1(表格模型1)
static JScrollPane gunDongTiao = null;
// 集合(jiHe),標(biāo)題(biaoti)
static Vector<Vector<Object>> Vector_jiHe_biaoGeNeiRong = null;
// wenBenKuang(文本框)
static Vector<Object> Vector_jiHe_biaoti = null;
// 文字(wenZi)
static JTextField wenBenKuang_Bianhao, wenBenKuang_name, wenBenKuang_price,
wenBenKuang_typeid, wenBenKuang_spjieshao, wenBenKuang_typename;
// biaoGe1(表格1)
static JLabel wenZi_Bianhao, wenZi_name, wenZi_price, wenZi_typeid,
wenZi_tjtypeName_xiaLaKuang, wenZi_spjieshao, wenZi_tjtypeName;
// anNiu_zengJia按鈕_增加
public static JComboBox xiaLaKuang = null;
// biaoGeNeiRong(表格內(nèi)容)
JPanel mianBan1, mianBan2 = null;
// mianBan(面板)
public guanLiYuanYongHuJieMian() {
this.setTitle("管理員用戶登錄后的界面");
this.setSize(800, 600);
this.setLayout(null);
this.setLocationRelativeTo(null);
wenZi_Bianhao = new JLabel("添加或查找編號");
wenZi_name = new JLabel("添加或查找名稱");
wenZi_price = new JLabel("添加或查找價格");
wenZi_tjtypeName = new JLabel("添加或查找類型名稱");
wenZi_tjtypeName_xiaLaKuang = new JLabel("查找類型名稱");
wenZi_typeid = new JLabel("添加或查找類型ID");
wenZi_spjieshao = new JLabel("添加或查找介紹");
anNiu_zengJia = new JButton("添加數(shù)據(jù)");
anNiu_zengJia.setBounds(530, 390, 100, 30);
anNiu_zengJia.addActionListener(new shijian_table2(this));
this.add(anNiu_zengJia);
wenZi_Bianhao.setBounds(510, 100, 100, 30);
wenZi_name.setBounds(510, 140, 100, 30);
wenZi_price.setBounds(510, 180, 100, 30);
wenZi_typeid.setBounds(510, 220, 130, 30);
wenZi_spjieshao.setBounds(510, 260, 100, 30);
wenZi_tjtypeName.setBounds(510, 300, 170, 30);
wenZi_tjtypeName_xiaLaKuang.setBounds(510, 340, 170, 30);
this.add(wenZi_Bianhao);
this.add(wenZi_name);
this.add(wenZi_price);
this.add(wenZi_typeid);
this.add(wenZi_spjieshao);
this.add(wenZi_tjtypeName_xiaLaKuang);
this.add(wenZi_tjtypeName);
wenBenKuang_Bianhao = new JTextField();// 畫框框的界面
wenBenKuang_Bianhao.setEditable(false);
wenBenKuang_name = new JTextField();
wenBenKuang_price = new JTextField();
wenBenKuang_typeid = new JTextField();
wenBenKuang_spjieshao = new JTextField();
wenBenKuang_typename = new JTextField();
wenBenKuang_Bianhao.setBounds(640, 100, 130, 30);
wenBenKuang_name.setBounds(640, 140, 130, 30);
wenBenKuang_price.setBounds(640, 180, 130, 30);
wenBenKuang_typeid.setBounds(640, 220, 130, 30);
wenBenKuang_spjieshao.setBounds(640, 260, 130, 30);
wenBenKuang_typename.setBounds(640, 300, 130, 30);
this.add(wenBenKuang_Bianhao);
this.add(wenBenKuang_name);
this.add(wenBenKuang_price);
this.add(wenBenKuang_typeid);
this.add(wenBenKuang_spjieshao);
this.add(wenBenKuang_typename);
Vector_jiHe_biaoti = new Vector<Object>();
Vector_jiHe_biaoti.add("編號");
Vector_jiHe_biaoti.add("名稱");
Vector_jiHe_biaoti.add("價格");
Vector_jiHe_biaoti.add("類型ID");
Vector_jiHe_biaoti.add("類型名稱");
Vector_jiHe_biaoti.add("介紹");
String sql = "select * from tushu as a inner join ts_Type as"
+ " b on(a.ts_TypeID=b.ts_TypeID)";
ResultSet res = DBUtils.Select(sql);
try {
Vector_jiHe_biaoGeNeiRong = new Vector<Vector<Object>>();
while (res.next()) {
Vector<Object> v = new Vector<Object>();
v.add(res.getInt("ts_ID"));
v.add(res.getString("ts_Name"));
v.add(res.getDouble("ts_price"));
v.add(res.getInt("ts_TypeID"));
v.add(res.getString("ts_TypeName"));
v.add(res.getString("ts_Jieshao"));
Vector_jiHe_biaoGeNeiRong.add(v);
biaoGeMoXing1 = new DefaultTableModel(
Vector_jiHe_biaoGeNeiRong, Vector_jiHe_biaoti);
}
biaoGeMoXing1 = new DefaultTableModel(Vector_jiHe_biaoGeNeiRong,
Vector_jiHe_biaoti) {
@Override
public boolean isCellEditable(int a, int b) {
return false;
}
};
biaoGe1 = new JTable(biaoGeMoXing1);
biaoGe1.addMouseListener(new shijian_table2(this));
biaoGe1.setBounds(0, 0, 400, 500);
gunDongTiao = new JScrollPane(biaoGe1);
gunDongTiao.setBounds(0, 0, 450, 150);
mianBan1 = new JPanel();/*
* JPanel1 = new JPanel(); 不可在gundong = new
* JScrollPane(JTable1);上面
*/
mianBan1.add(gunDongTiao);
// 加this.add(gundong);刪mianBan1.add(gunDongTiao );會有直接的滾動條,但變只可刪一次
mianBan1.setBounds(0, 0, 450, 250);
this.add(mianBan1);
} catch (SQLException e) {
e.printStackTrace();
}
shangPinLeiXingXiaLaKuang();
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
// 這里引用chaxunchushihua();沒作用
}
// public void XXX() 格式就是封裝查詢的方法,可調(diào)用,無加靜態(tài)屬性的單詞
public void chaxunchushihua() {
// 判斷JPanel是不是為空
if (this.mianBan1 != null) {
// 面板1不為空說明面板1中有內(nèi)容,就把面板1內(nèi)容用從this中用remove移除,下面再加新內(nèi)容
this.remove(mianBan1);
}
Vector_jiHe_biaoti = new Vector<Object>();
Vector_jiHe_biaoti.add("編號");
Vector_jiHe_biaoti.add("名稱");
Vector_jiHe_biaoti.add("價格");
Vector_jiHe_biaoti.add("類型ID");
Vector_jiHe_biaoti.add("類型名稱");
Vector_jiHe_biaoti.add("介紹");
String sql = "select * from tushu as a inner join ts_Type as"
+ " b on(a.ts_TypeID=b.ts_TypeID)";
ResultSet res = DBUtils.Select(sql);
try {
Vector_jiHe_biaoGeNeiRong = new Vector<Vector<Object>>();
while (res.next()) {
Vector<Object> v = new Vector<Object>();
v.add(res.getInt("ts_ID"));
v.add(res.getString("ts_Name"));
v.add(res.getDouble("ts_price"));
v.add(res.getInt("ts_TypeID"));
v.add(res.getString("ts_TypeName"));
v.add(res.getString("ts_Jieshao"));
Vector_jiHe_biaoGeNeiRong.add(v);
biaoGeMoXing1 = new DefaultTableModel(
Vector_jiHe_biaoGeNeiRong, Vector_jiHe_biaoti);
}
biaoGeMoXing1 = new DefaultTableModel(Vector_jiHe_biaoGeNeiRong,
Vector_jiHe_biaoti) {
@Override
public boolean isCellEditable(int a, int b) {
return false;
}
};
biaoGe1 = new JTable(biaoGeMoXing1);
// XXX.addMouseListener(new XXX(this));為給表格添加鼠標(biāo)點(diǎn)擊事件的格式,多總結(jié)和記錄格式等法
biaoGe1.addMouseListener(new shijian_table2(this));
gunDongTiao = new JScrollPane(biaoGe1);
gunDongTiao.setBounds(0, 0, 450, 150);
mianBan1 = new JPanel();
mianBan1.add(gunDongTiao);
mianBan1.setBounds(0, 0, 450, 250);
this.add(mianBan1);
} catch (SQLException e) {
e.printStackTrace();
}
// 釋放資源:this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
// shangPinLeiXingXiaLaKuang(商品類型下拉框)
public void shangPinLeiXingXiaLaKuang() {
String sql = "select * from ts_type";
ResultSet res = DBUtils.Select(sql);
xiaLaKuang = new JComboBox();
try {
while (res.next()) {
// com1. setSelectedIndex(Integer.parseInt(res. getObject(1).
// toString()));
xiaLaKuang.addItem(res.getObject(2).toString());
// xiaLaKuang.addItem(res.getObject(1).toString());
}
} catch (SQLException e) {
e.printStackTrace();
}
xiaLaKuang.setBounds(640, 340, 130, 30);
this.add(xiaLaKuang);
}
}


package denglu;
public class main {
public static void main(String[] args) {
new denglu();
// new zhuce();
// new zhmm();
// new zhaohuimima();
}
}
