I am trying to work on a little program just for fun, and I want it so when I click the pineapple button it adds a pineapple to a string of text that I want under the buttons, same for rock. So basically I need a counter for the rock and pineapple that goes under the buttons that just counts up each time the rock button is hit, and the pineapple button is hit.
This is what I have so far.
public class BGUI extends JFrame{
private JButton pine;
private JButton rock;
public BGUI(){
super("Bikini Bottom Builder Game");
setLayout(new FlowLayout());
Icon p = new ImageIcon(getClass().getResource("b.png"));
pine = new JButton("Add Pineapple", p);
add(pine);
Icon r = new ImageIcon(getClass().getResource("b.png"));
rock = new JButton("Add Rock", r);
rock.setRolloverIcon(r);
add(rock);
Add handler = new Add();
pine.addActionListener(handler);
rock.addActionListener(handler);
}
private class Add implements ActionListener{
int pine = 0;
int rock = 0;
public void actionPerformed(ActionEvent event){
pine++;
rock++;
}
}
}
Any help will be greatly appreciated!