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

📄 adduser.java.bak

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

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

public class AddUser extends JInternalFrame {
	
	private JButton butCancel,butOk;
    private JLabel jLabel1,jLabel2,jLabel3;
    private JTextField jtf1,jtf2;
    public AddUser() 
	{
		super("增加用户(购买人)");
        initComponents();
        
        this.setVisible(true);
        this.setClosable(true);
        this.setSize(260,240);        
   }
    private void initComponents() {
    	
    	//实例化并添加控件
        jLabel1 = new JLabel();
        jLabel2 = new JLabel();
		jLabel3 = new JLabel();
   
        jtf1 = new JTextField();
        jtf2=new JTextField();    
        butOk = new JButton();
        butCancel = new JButton();       
        //实例化并添加控件完成

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

        jLabel2.setText("资   金");
        getContentPane().add(jLabel2);
        jLabel2.setBounds(35, 60, 70, 20);
		
        getContentPane().add(jLabel3);
        jLabel3.setBounds(55, 120, 180, 20); 
                
        getContentPane().add(jtf1);
        jtf1.setBounds(100, 30, 130, 24);

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

        
        butOk.setText("添加");

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

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

		try{
			ResultSet rs = AccessSql.showUser();
         	while(rs.next()){
				String s1 = rs.getString(1);
				String s2 = rs.getString(2);
				jnum.addItem(new Us(s1,s2));
         	}
			rs.close();
         }
       	catch(Exception ea)
		{
			System.out.println("DeleUser Exception:"+ea);
		}
      
//为添加和取消按钮加事件-----------------------------------------
     
        butOk.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				String name=jtf1.getText();
				String money=jtf2.getText();
				jLabel3.setText("");
				try
				{
					Double.parseDouble(money);
					AccessSql.insertUser(name,money);
					jLabel3.setText("添加成功");

				}
				catch (NumberFormatException k)
				{
					new JOptionPane().showMessageDialog(null,"请输入正确的资金(实数,不带$/¥)");
					jLabel3.setText("请输入正确的资金(实数,不带$/¥)");
				}
					
        	}
        });	
        	

        butCancel.addActionListener(new ActionListener(){
        	public void actionPerformed(ActionEvent e){	
			dispose();
        		}
        	});

    }
}

⌨️ 快捷键说明

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