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

📄 dbjpbutton.java

📁 刚刚学习jdbc数据库
💻 JAVA
字号:
package myprojects.smalldatabase;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class dbJPButton extends JPanel implements ActionListener
{
	JPanel jp1=new JPanel();
	private JTextField nametext,agetext,jobtext;
	private JComboBox sexcombox,levcombox;
	JButton addButton,findButton,delButton,modButton;
	public dbJPButton(JTextField nametext,JTextField agetext,JTextField jobtext,JComboBox sexcombox,JComboBox levcombox) 
	{		
		this.nametext=nametext;
		this.agetext=agetext;
		this.jobtext=jobtext;
		this.sexcombox=sexcombox;
		this.levcombox=levcombox;
		
		this.setLayout(new FlowLayout(FlowLayout.CENTER));
		jp1.setLayout(new GridLayout(1,1,5,5));
		addButton=new JButton("添加");
		addButton.addActionListener(this);
		
		findButton=new JButton("查询");
		findButton.addActionListener(this);
		
		delButton=new JButton("删除");
		delButton.addActionListener(this);
		
		modButton=new JButton("修改");
		modButton.addActionListener(this);
		
		jp1.add(addButton);
		jp1.add(findButton);
		jp1.add(delButton);
		jp1.add(modButton);
		this.add(jp1);	
	}
	public void actionPerformed(ActionEvent e)
	{
		if(e.getSource()==addButton)
		{
			insert();
		}
		if(e.getSource()==delButton)
		{
			delete();
		}
		if(e.getSource()==modButton)
		{
			modify();
		}
		if(e.getSource()==findButton)
		{
			find();
		}
	}
	public void insert()
	{
		String name=dbJPShow.name();
		int age=dbJPShow.age();
		String sex=dbJPShow.sex();
		String level=dbJPShow.level();
		String job=dbJPShow.job();
		Sampledb sql=new Sampledb();
		boolean f=sql.insertSql(name,age,sex,level,job);
		if(f)
		{
			JOptionPane.showMessageDialog(null,"数据添加成功");
		}
		else
		{
			JOptionPane.showMessageDialog(null,"数据添加失败");
		}		
	}
	public void delete()
	{
		String name=dbJPShow.name();
		Sampledb sql=new Sampledb();
		boolean f=sql.deleteSql(name);
		if(f)
		{
			JOptionPane.showMessageDialog(null,"数据删除成功");
		}
		else
		{
			JOptionPane.showMessageDialog(null,"数据删除失败");
		}		
	}
	public void modify()
	{
		String name=dbJPShow.name();
		int age=dbJPShow.age();
		String sex=dbJPShow.sex();
		String level=dbJPShow.level();
		String job=dbJPShow.job();
		Sampledb sql=new Sampledb();
		boolean f=sql.modifySql(name,age,sex,level,job);
		if(f)
		{
			JOptionPane.showMessageDialog(null,"数据修改成功");
		}
		else
		{
			JOptionPane.showMessageDialog(null,"数据修改失败");
		}		
	}
	public void find()
	{
		String name=this.nametext.getText().trim();
		int age=new Integer(this.agetext.getText().trim());
		String sex=this.sexcombox.getSelectedItem().toString().trim();
		String level=this.levcombox.getSelectedItem().toString().trim();
		String job=jobtext.getText().trim();
		Sampledb sql=new Sampledb(this.nametext,this.agetext,this.jobtext,this.sexcombox,this.levcombox);
		sql.findSql(name,age,sex,level,job);
			
	}		
}

⌨️ 快捷键说明

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