猿问

为什么采购(UpdateBtn)按钮调用不了方法

package jiemian;


import java.awt.*;

import java.awt.event.*;


import javax.swing.*;


import java.sql.*;

public class BookPurchase extends JFrame implements ActionListener

{

JPanel panel1,panel2,panel3,panel4;

JLabel TipLabel=new JLabel("我们来看看仓库里有没有这本书呢");

JLabel BookNameLabel,PressNameLabel,

      AuthorLabel,BookIdLabel,

      PressDateLabel,PriceLabel,StationLabel;

JTextField BookNameTextField,PressNameTextField,

          AuthorTextField,BookIdTextField,

          PressDateTextField,PriceTextField,StationTextField;

Container c;

JButton ClearBtn,YesBtn,UpdateBtn/*,ExitBtn*/;

public BookPurchase()

{

super("图书采购");

c=getContentPane();

c.setLayout(null);

panel3=new JPanel();

panel3.add(TipLabel);

panel3.setBounds(0,0,300,30);

c.add(panel3,BorderLayout.NORTH);

BookIdLabel=new JLabel("编号",JLabel.CENTER);

BookNameLabel=new JLabel("书名",JLabel.CENTER);

AuthorLabel=new JLabel("作者",JLabel.CENTER);

PressNameLabel=new JLabel("出版社",JLabel.CENTER);

PressDateLabel=new JLabel("采购数量",JLabel.CENTER);

PriceLabel=new JLabel("采购价格",JLabel.CENTER);

StationLabel=new JLabel("采购金额",JLabel.CENTER);

BookNameTextField=new JTextField(20);

PressNameTextField=new JTextField(20);

AuthorTextField=new JTextField(20);

BookIdTextField=new JTextField(20);

PressDateTextField=new JTextField(20);

PriceTextField=new JTextField(20);

StationTextField=new JTextField(15);

panel1=new JPanel();

panel4=new JPanel();

panel1.setLayout(new GridLayout(7,1));

panel4.setLayout(new GridLayout(7,1));

panel1.add(BookIdLabel);

panel4.add(BookIdTextField);

panel1.add(BookNameLabel);

panel4.add(BookNameTextField);

panel1.add(PressNameLabel);

panel4.add(PressNameTextField);

panel1.add(AuthorLabel);

panel4.add(AuthorTextField);

panel1.add(PressNameLabel);

panel4.add(PressNameTextField);

panel1.add(PressDateLabel);

panel4.add(PressDateTextField);

panel1.add(PriceLabel);

panel4.add(PriceTextField);

panel1.add(StationLabel);

panel4.add(StationTextField);

panel1.setBounds(0,30,100,220);

panel4.setBounds(100,30,220,220);

panel2=new JPanel();

panel2.setBounds(10,260,300,30);

panel2.setLayout(new GridLayout(1,4));

ClearBtn=new JButton("清空");

YesBtn=new JButton("查询");

UpdateBtn=new JButton("采购");

//ExitBtn=new JButton("计算");

panel2.add(ClearBtn);

panel2.add(YesBtn);

panel2.add(UpdateBtn);

//panel2.add(ExitBtn);

ClearBtn.addActionListener(this);

YesBtn.addActionListener(this);

UpdateBtn.addActionListener(this);

//ExitBtn.addActionListener(this);

//UpdateBtn.setEnabled(false);

c.add(panel3);

c.add(panel1);

c.add(panel4);

c.add(panel2);

setVisible(true);

setBounds(100,50,330,320);

}

public void actionPerformed(ActionEvent e)

{

Connection con;

        PreparedStatement sql;

        ResultSet rs;

if(e.getSource()==ClearBtn)

{

BookNameTextField.setText("");

PressNameTextField.setText("");

AuthorTextField.setText("");

BookIdTextField.setText("");

PressDateTextField.setText("");

PriceTextField.setText("");

StationTextField.setText("");

}

else if(e.getSource()==YesBtn)

{

try {  Class.forName("com.mysql.jdbc.Driver");  

          }

     catch(ClassNotFoundException f){}

      try {  

             String Id;

             Id=BookIdTextField.getText();

             con=DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/book","root","123456");

              sql=con.prepareStatement("SELECT * FROM essential where Id=?");

              sql.setString(1,Id);

              rs=sql.executeQuery();

              if(!rs.next()){

              JOptionPane.showMessageDialog(this,"这本书我们仓库没有,老板","提示对话框",JOptionPane.WARNING_MESSAGE);

                 }

              else{

             JOptionPane.showMessageDialog(this,"老板这本书我们有了,买不买你说了算","提示对话框",JOptionPane.WARNING_MESSAGE);

              }

      }

      catch(SQLException e2) 

         {  System.out.println(e2);

        }

      if(e.getSource()==UpdateBtn){

   

  if(BookIdLabel.getText().trim().equals(""))

  {

  JOptionPane.showMessageDialog(null,"编号不能为空!");

  }

  else if(BookNameLabel.getText().trim().equals(""))

  {

  JOptionPane.showMessageDialog(null,"书名不能为空!");

  }

  else if(AuthorLabel.getText().trim().equals(""))

  {

  JOptionPane.showMessageDialog(null,"作者不能为空!");

  }

  else if(PressNameLabel.getText().trim().equals(""))

  {

  JOptionPane.showMessageDialog(null,"出版社不能为空!");

  }

  else if(PressDateLabel.getText().trim().equals(""))

  {

  JOptionPane.showMessageDialog(null,"采购数量");

  }

  else if(PriceLabel.getText().trim().equals(""))

  {

  JOptionPane.showMessageDialog(null,"采购价格不能为空!");

  }

  else if(StationLabel.getText().trim().equals(""))

  {

  JOptionPane.showMessageDialog(null,"采购金额不能为空!");

  }

  else {

  int n=JOptionPane.showConfirmDialog(this,"确认要采购吗?老板","确认对话框",JOptionPane.YES_NO_OPTION );

              if(n==JOptionPane.YES_OPTION){

             

              }

 

 

  else{

  /*String SerialPrice,quantity;

  Double tamount;

  SerialPrice=PriceTextField.getText();

  quantity=PressDateLabel.getText();

  StationTextField.setText("str");

  tamount=Double.parseDouble(SerialPrice)*Double.parseDouble(quantity);

  String str = String.valueOf(tamount);*/

  UpdateBtn.addMouseListener(new MouseListener(){

  public void mouseClicked(MouseEvent e) {

  int value1 = Integer.parseInt(PressDateLabel.getText().trim());

  int value2 = Integer.parseInt(PriceLabel.getText().trim());

 

  StationLabel.setText(String.valueOf(value1 + value2));

  }

  public void mouseEntered(MouseEvent e) {

  // TODO Auto-generated method stub

 

  }

  public void mouseExited(MouseEvent e) {

  // TODO Auto-generated method stub

 

  }

  public void mousePressed(MouseEvent e) {

  // TODO Auto-generated method stub

 

  }

  public void mouseReleased(MouseEvent e) {

  // TODO Auto-generated method stub

 

  }

 

  });

  }

  }

        }

      

     

     }

      }

public static void main(String args[]){

new BookPurchase();

}

}

      


不凡的蚂蚁
浏览 1313回答 0
0回答
随时随地看视频慕课网APP

相关分类

Java
我要回答