基于javaweb+Swing+Java+MySQL商品管理系统
开发工具:eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
name.setColumns(10);
name.setBounds(147, 140, 142, 21);
getContentPane().add(name);
JLabel label_2 = new JLabel("数量:");
label_2.setBounds(85, 193, 87, 22);
getContentPane().add(label_2);
num = new JTextField();
num.setColumns(10);
num.setBounds(147, 194, 142, 21);
getContentPane().add(num);
JLabel label_3 = new JLabel("单价:");
label_3.setBounds(85, 241, 87, 22);
getContentPane().add(label_3);
price = new JTextField();
price.setColumns(10);
price.setBounds(147, 242, 142, 21);
getContentPane().add(price);
goodsid = goods.getGoodsID();
id.setText(Integer.toString(goods.getGoodsID()));
public int getNum() {
return num;
}
public void setNum(int num) {
this.num = num;
}
public String getPrice() {
return price;
}
public void setPrice(String price) {
this.price = price;
}
}
package com.demo.main;
import com.demo.view.GoodsManagement;
public class AppStart {
public static void main(String[] args) {
GoodsManagement t = new GoodsManagement();
t.setVisible(true);
});
}
}
package com.demo.view;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.ScrollPaneConstants;
import javax.swing.table.DefaultTableModel;
import com.demo.Dao.Select;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
}
package com.demo.Dao;
import com.mysql.jdbc.Statement;
import javax.swing.*;
import java.sql.*;
public class DbConnection {
//驱动类的类名
private static final String DRIVERNAME = "com.mysql.jdbc.Driver";
//连接数据的URL路径
private static final String URL = "jdbc:mysql://localhost:3306/project_000000000000?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai&autoReconnect=true&failOverReadOnly=false&allowPublicKeyRetrieval=true";
//数据库登录账号
private static final String USER = "root";
//数据库登录密码
@Override
public void actionPerformed(ActionEvent e) {
String sql = "SELECT goodsID,goodsname,num,price FROM goods";
Object[][] data = Select.getGoods(sql);
df.setDataVector(data, header);
}
});
button_1.setBounds(535, 80, 127, 30);
getContentPane().add(button_1);
JButton button_2 = new JButton("修改商品");
button_2.setBounds(535, 140, 127, 30);
getContentPane().add(button_2);
button_2.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (jTable.getSelectedColumn()<0) {
JOptionPane.showMessageDialog(null, "请选择要修改的数据!");
} else {
int goodsID = Integer.parseInt(jTable.getValueAt(jTable.getSelectedRow(), 0).toString());
String name = jTable.getValueAt(jTable.getSelectedRow(), 1).toString();
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class GoodsManagement extends JFrame {
Select select = new Select();
private JTextField textField;
Object[] header= {"商品编号","商品名称","数量","单价"};
String sql = "SELECT goodsID,goodsname,num,price FROM goods";
Object[][] data= select.getGoods(sql);
DefaultTableModel df = new DefaultTableModel(data, header);
import javax.swing.ScrollPaneConstants;
import javax.swing.table.DefaultTableModel;
import com.demo.Dao.Select;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class GoodsManagement extends JFrame {
Select select = new Select();
private JTextField textField;
Object[] header= {"商品编号","商品名称","数量","单价"};
String sql = "SELECT goodsID,goodsname,num,price FROM goods";
Object[][] data= select.getGoods(sql);
DefaultTableModel df = new DefaultTableModel(data, header);
int v=ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;
int h=ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
package com.demo.view;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.ScrollPaneConstants;
import javax.swing.table.DefaultTableModel;
import com.demo.Dao.Select;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class GoodsManagement extends JFrame {
Select select = new Select();
private JTextField textField;
public class GoodsManagement extends JFrame {
Select select = new Select();
private JTextField textField;
Object[] header= {"商品编号","商品名称","数量","单价"};
String sql = "SELECT goodsID,goodsname,num,price FROM goods";
Object[][] data= select.getGoods(sql);
DefaultTableModel df = new DefaultTableModel(data, header);
int v=ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;
int h=ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
public GoodsManagement() {
super("商品管理系统");
this.setBounds(0, 0, 700, 450);
this.setLocationRelativeTo(null);//让窗口在屏幕中间显示
this.setResizable(false);//让窗口大小不可改变
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//用户单击窗口的关闭按钮时程序执行的 *** 作
getContentPane().setLayout(null);
JLabel label = new JLabel("请输入商品名称:");
label.setBounds(151, 39, 112, 32);
} else {
JOptionPane.showMessageDialog(null, "添加失败!");
}
}
}
});
button_1 = new JButton("取消");
button_1.setBounds(208, 317, 93, 23);
getContentPane().add(button_1);
button_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
dispose();
}
});
}
}
package com.demo.view;
运行环境
Java≥6、MySQL≥5.5
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
技术框架
Java Swing
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
商品信息管理,简单的增删改查
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)