📄 a0ea0653f82f001d17a39fa8a118b5a5
字号:
import java.awt.*;
import java.awt.event.*;
import java.sql.PreparedStatement;
import javax.swing.*;
import javax.swing.event.*;
public class InputProduct extends JPanel implements ActionListener{
private JLabel lbTitle=new JLabel("进货信息注册界面");
private JLabel lbID=new JLabel("零件编号:");
private JLabel lbName=new JLabel("零件名称:");
private JLabel lbPrice=new JLabel("零件价格");
private JLabel lbNum=new JLabel("零件数量:");
private JLabel lbPerson=new JLabel("经手人员:");
private JTextField tfID=new JTextField("",10);
private JTextField tfName=new JTextField("",10);
private JTextField tfPrice=new JTextField("",10);
private JTextField tfNum=new JTextField("",10);
private JTextField tfPerson=new JTextField("",10);
private JButton btnSend=new JButton("提交");
private JButton btnCancle=new JButton("取消");
private ImageIcon icon=new ImageIcon("2.jpg");
private JLabel lbImg=new JLabel(icon);
private Color color;
public InputProduct()
{
lbTitle.setBounds(230, 70, 150, 80);
Font font=new Font("楷体",Font.BOLD,15);
lbTitle.setFont(font);
lbTitle.setForeground(Color.BLUE);
lbID.setBounds(200, 130, 150, 40);
lbName.setBounds(200, 160, 150, 40);
lbPrice.setBounds(200, 190, 150, 40);
lbNum.setBounds(200, 220, 150, 40);
lbPerson.setBounds(200, 250, 150, 40);
Color g=Color.green;
lbID.setForeground(g);
lbName.setForeground(g);
lbPrice.setForeground(g);
lbNum.setForeground(g);
lbPerson.setForeground(g);
tfID.setBounds(280, 138, 140, 20);
tfName.setBounds(280, 168, 140, 20);
tfPrice.setBounds(280, 198, 140, 20);
tfNum.setBounds(280, 228, 140, 20);
tfPerson.setBounds(280, 258, 140, 20);
btnSend.setBounds(210, 300, 80, 22);
btnCancle.setBounds(330, 300, 80, 22);
btnSend.addActionListener(this);
btnCancle.addActionListener(this);
lbImg.add(lbTitle);
lbImg.add(lbID);
lbImg.add(lbName);
lbImg.add(lbPrice);
lbImg.add(lbNum);
lbImg.add(lbPerson);
lbImg.add(tfID);
lbImg.add(tfName);
lbImg.add(tfPrice);
lbImg.add(tfNum);
lbImg.add(tfPerson);
lbImg.add(btnSend);
lbImg.add(btnCancle);
add(lbImg,SwingConstants.CENTER);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==btnSend)
{
dealBtnSend();
}
else if(e.getSource()==btnCancle)
{
dealBtnCancle();
}
}
public void dealBtnSend()
{
try
{
String ID = tfID.getText();
String Name=tfName.getText();
String p=tfPrice.getText();
String n=tfNum.getText();
String name=tfPerson.getText();
if(ID.equals(""))
{
JOptionPane.showMessageDialog(this, "零件编号不能为空!");
}
else if(Name.equals(""))
{
JOptionPane.showMessageDialog(this, "零件名称不能为空!");
}
else if(p.equals(""))
{
JOptionPane.showMessageDialog(this, "零件价格不能为空!")
}
else if(n.equals(""))
{
JOptionPane.showMessageDialog(this, "零件进购数量不能为空!");
}
else if(name.equals(""))
{
JOptionPane.showMessageDialog(this, "经受人员姓名不能为空!");
}
else
{
float Price=Float.parseFloat(tfPrice.getText().trim());
int Num=Integer.parseInt(tfNum.getText().trim());
float AllMenoy=Price*Num;
String Person=tfPerson.getText().trim();
ConToDB DB=new ConToDB();
DB.LinkDB();
String sql="insert into Product values(?,?,?,?,?,?)";
PreparedStatement st=DB.con.prepareStatement(sql);
st.setString(1, ID);
st.setString(2, Name);
st.setFloat(3, Price);
st.setInt(4, Num);
st.setFloat(5, AllMenoy);
st.setString(6, Person);
int i=st.executeUpdate();
if(i>=0)
JOptionPane.showMessageDialog(this, "添加零件操作成功!");
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
public void dealBtnCancle()
{
try
{
tfID.setText("");
tfName.setText("");
tfPrice.setText("");
tfNum.setText("");
tfPerson.setText("");
}
catch(Exception e)
{
e.printStackTrace();
}
}
public void chooseColor()
{
try
{
color=JColorChooser.showDialog(InputProduct.this, "修改颜色", color);
tfID.setBackground(color);
tfName.setBackground(color);
tfPrice.setBackground(color);
tfNum.setBackground(color);
tfPerson.setBackground(color);
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -