Java swing(1)自己设计完善的独特功能图书管理系统,获取下拉框等的文字内容

结构总框架:

本篇所含框架:

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("确认修改");
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中的所有内容
*/
}
@Override
public void actionPerformed(ActionEvent arg0) {
if (arg0.getActionCommand().equals("确认修改")) {
JOptionPane.showMessageDialog(null, "点击了修改密码按钮");
// 点击了“确认修改”之后要用if比较一下两个密码输入的是否一致
String pwd1 = chuangKou.JPasswordField_qslmm1.getText();
String pwd2 = chuangKou.JPasswordField_qslmm2.getText();
if (pwd1.equals(pwd2)) {
// 如果相等就做进一步的修改密码
// SQL语句如何加条件:就是where后面加上zhmm(找回密码)页面的uname属性,可以直接调用
// 声明一个工具类,用来保存用户要修改的用户名,什么时候想要使用直接调用就好
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, "出现了未知的错误,请重试!");
}
} 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操作。可以少写代码。
1对于数据表的读操作,他可以把结果转换成List,Aray, Set等java集合, 便于程序员操作:
2.对于数据表的写操作,也变得很简单(只需写sql语句)
3.可以使用数据源,使用JNDI, 数据库连接池等技术来优化性能-重用已经构建好的数据库连
注意,在使用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为用于查找的静态方法 */
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)的静态方法,命名不可太长不然这里会不管用 */
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(下标为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, "点击");
if (arg0.getActionCommand().equals("管理员用户登录")) {
String uname = shijian_dengLu1.JTextField_unametxt1.getText()
.trim();// 从shijian_dengLu1中的JTextField_unametxt1获取用户输入的用户名文本内容
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中的内容,如果res中有数据,登录成功,否则登录失败
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获取用户输入的用户名文本内容
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中的内容,如果res中有数据,登录成功,否则登录失败
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, "点击了注册按钮");
new zhuCe();
} else if (arg0.getActionCommand().equals("找回密码")) {
JOptionPane.showMessageDialog(null, "点击了找回密码按钮");
new zhaoHuiMiMa();
// dd. setVisible(false);
} else if (arg0.getActionCommand().equals("取消")) {
JOptionPane.showMessageDialog(null, "点击了取消按钮");
// 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, "出现了未知的错误,增加失败");
}
}
@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);
// 给下拉框内容赋值:
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, "是否确认删除这条信息?");
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();
// 删除成功再查询一遍表格就可以实现表格的刷新,但是我们的查询写在了构造方法里,内容很多,
// 这里想要使用又要在写一遍,很麻烦,那么现在我们写一个方法 将查询内容封装进去,再想查询的
// 时候只要调用查询的方法即可
} else {
JOptionPane.showMessageDialog(null, "出现了未知的错误,请重试");
}
}
}
}
@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),标题(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(表格内容)
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("添加数据");
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() 格式就是封装查询的方法,可调用,无加静态属性的单词
public void chaxunchushihua() {
// 判断JPanel是不是为空
if (this.mianBan1 != null) {
// 面板1不为空说明面板1中有内容,就把面板1内容用从this中用remove移除,下面再加新内容
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));为给表格添加鼠标点击事件的格式,多总结和记录格式等法
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();
}
}
