⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 addshop.java

📁 个人消费助理 早期的在学校的实训作品 使用ACCESS 数据库
💻 JAVA
字号:
package shophelper.factory;

import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
import java.sql.*;
import shophelper.database.*;

public class AddShop extends JInternalFrame {
	
	private JButton butCancel,butOk,jb1,jb2,jb3;
    private JLabel jLabel1,jLabel2,jLabel3,jLabel4,jLabel5;
    private JTextField jtf1,jtf2;
	private JComboBox jnum1,jnum2,jnum3;
    public AddShop() 
	{
		super("购买事件记录添加");
        initComponents();
        
        this.setVisible(true);
        this.setClosable(true);
        this.setSize(480,380);        
   }
    private void initComponents() {
    	
    	//实例化并添加控件
        jLabel1 = new JLabel("购买人");
        jLabel2 = new JLabel("商品");
		jLabel3 = new JLabel("店铺");
		jLabel4 = new JLabel("定单号");
		jLabel5 = new JLabel("时间");

		jnum1 = new JComboBox();
		jnum2 = new JComboBox();
		jnum3 = new JComboBox();

   
        jtf1 = new JTextField();
        jtf2= new JTextField();
		
        butOk = new JButton();
        butCancel = new JButton();     
		
		jb1 = new JButton("添加购买人");
		jb2 = new JButton("添加商品");
		jb3 = new JButton("添加店铺");
        //实例化并添加控件完成

        getContentPane().setLayout(null);//设置布局
        
        
        //为空间放置具体位置
        getContentPane().add(jLabel1);
        jLabel1.setBounds(55, 30, 70, 20);

        getContentPane().add(jLabel2);
        jLabel2.setBounds(55, 60, 70, 20);
		
        getContentPane().add(jLabel3);
        jLabel3.setBounds(55, 90, 70, 20); 

		getContentPane().add(jLabel4);
        jLabel4.setBounds(55, 120, 70, 20);

		getContentPane().add(jLabel5);
        jLabel5.setBounds(55, 150, 70, 20);
                
        getContentPane().add(jnum1);
        jnum1.setBounds(100, 30, 130, 24);

        getContentPane().add(jnum2);
        jnum2.setBounds(100, 60, 130, 24);

		getContentPane().add(jnum3);
        jnum3.setBounds(100, 90, 130, 24);

		getContentPane().add(jtf1);
        jtf1.setBounds(100, 120, 130, 24);

		getContentPane().add(jtf2);
        jtf2.setBounds(100, 150, 130, 24);

		getContentPane().add(jb1);
        jb1.setBounds(240, 30, 100, 27);

		getContentPane().add(jb2);
        jb2.setBounds(240, 60, 100, 27);

		getContentPane().add(jb3);
        jb3.setBounds(240, 90, 100, 27);

        
        butOk.setText("添加");

        getContentPane().add(butOk);
        butOk.setBounds(80, 180, 70, 27);

        butCancel.setText("取消");
        getContentPane().add(butCancel);
        butCancel.setBounds(160, 180, 70, 27);

		try{//三个下拉表 读入数据
			ResultSet rs1 = AccessSql.showUser();
         	while(rs1.next()){
				String s1 = rs1.getString(1);
				String s2 = rs1.getString(2);
				jnum1.addItem(new Us(s1,s2));
         	}
			rs1.close();

			ResultSet rs2 = AccessSql.showShoping();
         	while(rs2.next()){
				String s1 = rs2.getString(1);
				String s2 = rs2.getString(2);
				jnum2.addItem(new Us(s1,s2));
         	}
			rs2.close();

			ResultSet rs3 = AccessSql.showStore();
         	while(rs3.next()){
				String s1 = rs3.getString(1);
				String s2 = rs3.getString(2);
				jnum3.addItem(new Us(s1,s2));
         	}
			rs3.close();
         }
       	catch(Exception ea)
		{
			System.out.println("AddShop Exception:"+ea);
		}
      
//为添加和取消按钮加事件-----------------------------------------
		jb1.addActionListener(new ActionListener(){//添加购买人
        	public void actionPerformed(ActionEvent e){
        		System.out.println("添加购买人");
				getDesktopPane().add(new AddUser());
				dispose();
        		}
        });/*

		jb2.addActionListener(new ActionListener(){//添加商品
        	public void actionPerformed(ActionEvent e){
        		System.out.println("添加商品");
				deskpane.add(new AddUser());
				dispose();
				deskpane.add(new AddShop());
        		}
        });*/

		jb3.addActionListener(new ActionListener(){//+店铺
        	public void actionPerformed(ActionEvent e){
        		System.out.println("+店铺");
				getDesktopPane().add(new AddShop());
				dispose();
        		}
        });


     
        butOk.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				
				String id1=((Us)jnum1.getSelectedItem()).s1;
				String id2=((Us)jnum2.getSelectedItem()).s1;
				String id3=((Us)jnum3.getSelectedItem()).s1;
				String order=jtf1.getText();
				String time=jtf2.getText();

				AccessSql.insertShop(id1,id2,id3,order,time);
				new JOptionPane().showMessageDialog(null,"添加成功");
        	}
        });	
        	
	
        butCancel.addActionListener(new ActionListener(){
        	public void actionPerformed(ActionEvent e){	
			dispose();
        		}
        	});

    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -