0

I was just wondering how to get this JButton "nextButton" to work. It is used by the actionPerformed method for the e.getSource instanceof JButton. How can I make it to work alone?

        if(e.getSource() == nextButton){
            try {
                stmt.executeUpdate("UPDATE seats SET type = 'booked' WHERE seatNum = 3");

            } catch (SQLException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
        }

        if(e.getSource() instanceof JButton){
            bookedIcon = new ImageIcon("images/bookedSeat.png");

            int a = Integer.parseInt(e.getActionCommand());
            int seat = a;
            a =- 1;
            seatsA[a].setIcon(bookedIcon);

        }
Jakub Badacz
  • 63
  • 1
  • 7
  • Please define "make it to work alone" -- what exactly are you trying to do? It's always best to explain the details of your code and your problem if at all possible. – Hovercraft Full Of Eels Apr 08 '16 at 00:14
  • Welcome to stack overflow. Please review http://stackoverflow.com/help/how-to-ask which details the way to ask a good question. – Tal Avissar Apr 08 '16 at 00:18
  • @HovercraftFullOfEels Well, I have an array of buttons for which I use the if statement with instanceof, but i want the nextButton to change values in the db and go to another frame – Jakub Badacz Apr 08 '16 at 00:18
  • Then go ahead and do that. You can put that code in the if block above, or you can give the JButton its own ActionListener, often an anonymous inner class. – Hovercraft Full Of Eels Apr 08 '16 at 00:20
  • Oh yeah, inner classes! Forgot about that, thank you! :) – Jakub Badacz Apr 08 '16 at 00:36

0 Answers0