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

📄 productadd.java

📁 鞋类企业信息管理系统Java,这是一个毕业设计
💻 JAVA
字号:
import java.sql.*;
import java.awt.*;
import java.awt.event.*;

import javax.swing.*;

public class ProductAdd extends JFrame {
    
	JLabel lbName,lbFuzeren,lbDepartment,lbDanwei,lbDanjia,lbDemo;
	JTextField jtName,jtFuzeren,jtDepartment,jtDanwei,jtDanjia,jtDemo;
	JButton clear,add,cancel;
	private DB_Manager db= new DB_Manager();
	private void makeGUI(){
		lbName = new JLabel("名称:",JLabel.RIGHT);
		lbFuzeren = new JLabel("负责人:",JLabel.RIGHT);
		lbDepartment = new JLabel("所属部门:",JLabel.RIGHT);
		lbDanwei = new JLabel("单位:",JLabel.RIGHT);
		lbDanjia = new JLabel("单价:",JLabel.RIGHT);
		lbDemo = new JLabel("描述:",JLabel.RIGHT);
		
		jtName = new JTextField(10);
		jtFuzeren= new JTextField(10);
		jtDepartment= new JTextField(10);
		jtDanwei= new JTextField(10);
		jtDanjia= new JTextField(10);
		jtDemo= new JTextField(10);
		
		clear = new JButton("清空");
		add = new JButton("添加");
		cancel = new JButton("取消");
		
		Container cp = getContentPane();
		JPanel jp = new JPanel();
		JPanel jp2 = new JPanel();
		jp.setLayout(new GridLayout(6,2,20,18));
		//jp.setLayout(new FlowLayout());
		jp2.setLayout(new FlowLayout());
		
		jp.add(lbName);jp.add(jtName);
		jp.add(lbFuzeren);jp.add(jtFuzeren);
		jp.add(lbDepartment);jp.add(jtDepartment);
		jp.add(lbDanwei); jp.add(jtDanwei);
		jp.add(lbDanjia); jp.add(jtDanjia); 
		jp.add(lbDemo); jp.add(jtDemo);
		cp.setLayout(new BorderLayout());
		
		jp2.add(clear);
		jp2.add(add);
		jp2.add(cancel);
		
		cp.add(jp,BorderLayout.CENTER);
		cp.add(new JLabel("                             "),BorderLayout.EAST);
		cp.add(jp2,BorderLayout.SOUTH);
		
	}
	
	private void addAction(){
		
		clear.addActionListener(
			new ActionListener(){
				public void actionPerformed(ActionEvent e){
					jtName.setText("");
					jtFuzeren.setText("");
					jtDepartment.setText("");
					jtDanwei.setText("");
					jtDanjia.setText("");
					jtDemo.setText("");
				}
			});
		
		add.addActionListener(
			new ActionListener(){
				public void actionPerformed(ActionEvent e){
					String sql;
					if(jtName.getText().trim().equals("")){
						JOptionPane.showMessageDialog(null,"产品名称不可为空,请确认");
						return;
					}
					if(jtFuzeren.getText().trim().equals("")){
						JOptionPane.showMessageDialog(null,"负责人不可为空,请确认");
						return;
					}
					if(jtDepartment.getText().trim().equals("")){
						JOptionPane.showMessageDialog(null,"产品所属部门不可为空,请确认");
						return;
					}
					sql = "insert into productinfo(Name,Principal,Department,Units,Unitprice,Comment) values('";
					sql += jtName.getText().trim()+"','";
					sql+= jtFuzeren.getText().trim() +"','";
					sql += jtDepartment.getText().trim() +"','";
					sql += jtDanwei.getText().trim() +"','";
					sql += jtDanjia.getText().trim() +"','";
					sql+=jtDemo.getText().trim()+"')";
					if(db.executeSql(sql)){
						JOptionPane.showMessageDialog(null,"成功添加");}
					else{
						JOptionPane.showMessageDialog(null,"添加失败,请重新操作!!!");}												
												
				}
			});
		
		
		cancel.addActionListener(
				new ActionListener(){
					public void actionPerformed(ActionEvent e){
					    exit();
					}
				});
		
		
		
	}
	
	public ProductAdd(String title)
	{
		super(title);
		makeGUI();	
		addAction();
		addWindowListener(new WinLis());
	}
	
	class WinLis extends WindowAdapter
	{
		public void windowClosing(WindowEvent e)
		{
			exit();
		}
	}
	
	public void exit(){
		this.dispose();
	}
	
	public static void main(String[] args){
		ProductAdd newAdd = new ProductAdd("添加产品信息");
		newAdd.setBounds(120,120,400,350);
		newAdd.validate();
		newAdd.setVisible(true);				
	}
}
/*
class WinLis extends WindowAdapter{
	public void windowClosing(WindowEvent e){
		System.exit(0);
	}
}

*/

⌨️ 快捷键说明

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