欢迎光临散文网 会员登陆 & 注册

第一

2023-06-30 10:28 作者:天尘灬厌宇  | 我要投稿

package com.yunjisuan; import java.awt.EventQueue; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.border.EmptyBorder; import javax.swing.table.DefaultTableModel; import com.conn.SqlTest; import com.conn.shops; import javax.swing.JButton; import javax.swing.JDialog; import java.awt.event.ActionListener; import java.sql.SQLException; import java.util.ArrayList; import java.awt.event.ActionEvent; import javax.swing.JLabel; import javax.swing.JTextField; import javax.swing.JScrollPane; import java.awt.BorderLayout; import java.awt.FlowLayout; import javax.swing.JTable; import javax.swing.SwingConstants; public class first extends JFrame { private JPanel contentPane; private JTextField textField; private JTable table; private Object[][]data; private String [] head= {"goodId","goodName","num","price"}; DefaultTableModel model=new DefaultTableModel(data,head); /** * Launch the application. */ public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { try { first frame = new first(); frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); } /** * Create the frame. */ public first() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(100, 100, 853, 519); contentPane = new JPanel(); setContentPane(contentPane); contentPane.setLayout(new BorderLayout(0, 0)); JPanel panel = new JPanel(); contentPane.add(panel, BorderLayout.NORTH); panel.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5)); JLabel lblNewLabel = new JLabel("商品名称"); panel.add(lblNewLabel); textField = new JTextField(); panel.add(textField); textField.setColumns(10); JButton btnNewButton = new JButton("查询"); btnNewButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { SqlTest sqlTest=new SqlTest(); try { ArrayList shopss panel.add(btnNewButton); JButton btnNewButton_2 = new JButton("添加"); panel.add(btnNewButton_2); JScrollPane scrollPane = new JScrollPane(); contentPane.add(scrollPane, BorderLayout.CENTER); table = new JTable(model); scrollPane.setViewportView(table); JButton btnNewButton_1 = new JButton("删除"); btnNewButton_1.setVerticalAlignment(SwingConstants.TOP); contentPane.add(btnNewButton_1, BorderLayout.EAST); btnNewButton_1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { int num=table.getSelectedRow(); int id= (int) table.getValueAt(num, 0); SqlTest sqlTest=new SqlTest(); try { sqlTest.delete_shop(id); } catch (SQLException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } try { ArrayList shopss= sqlTest.query(); Object[][] shop_query=new Object[shopss.size()][4]; for (int i = 0; i < shop_query.length; i++) { shop_query[i][0]=shopss.get(i).getGoodId(); shop_query[i][1]=shopss.get(i).getGoodName(); shop_query[i][2]=shopss.get(i).getNum(); shop_query[i][3]=shopss.get(i).getPrice(); } data=shop_query; model.setDataVector(data, head); } catch (SQLException e2) { // TODO Auto-generated catch block e2.printStackTrace(); } } }); btnNewButton_2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { three three=new three(first.this); three.setVisible(true); } }); } }

第一的评论 (共 条)

分享到微博请遵守国家法律