rendered paste bodyimport java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class GingerFrame extends JFrame implements ActionListener {
Icon ginger_icon;
Icon toffee_icon;
Icon jumbo_icon;
Icon cashew_icon;
Icon omega_icon;
Icon candy_icon;
JButton bar1;
JButton bar2;
JButton bar3;
JButton bar4;
JButton bar5;
JButton bar6;
JButton money;
public GingerFrame(int bar) {
if(bar == 0) {
setTitle("Click to take your change!");
money = new JButton("0.00");
money.setActionCommand("refund");
money.addActionListener(this);
getContentPane().add(money);
setSize(140, 140);
setLocation(50, 70);
}
else {
setTitle("Enjoy");
}
if(bar == 1) {
ginger_icon = new ImageIcon("ginger.gif");
bar1 = new JButton(ginger_icon);
bar1.setActionCommand("bar1");
bar1.addActionListener(this);
getContentPane().add(bar1);
setSize(160, 140);
setLocation(60,80);
setVisible(true);
}
if(bar == 2) {
toffee_icon = new ImageIcon("toffee.gif");
bar2 = new JButton(toffee_icon);
bar2.setActionCommand("bar2");
bar2.addActionListener(this);
getContentPane().add(bar2);
setSize(160, 140);
setLocation(60,80);
setVisible(true);
}
if(bar == 3) {
jumbo_icon = new ImageIcon("jumbo.gif");
bar3 = new JButton(jumbo_icon);
bar3.setActionCommand("bar3");
bar3.addActionListener(this);
getContentPane().add(bar3);
setSize(160, 140);
setLocation(60,80);
setVisible(true);
}
if(bar == 4) {
cashew_icon = new ImageIcon("cashew.gif");
bar4 = new JButton(cashew_icon);
bar4.setActionCommand("bar4");
bar4.addActionListener(this);
getContentPane().add(bar4);
setSize(160, 140);
setLocation(60,80);
setVisible(true);
}
if(bar == 5) {
omega_icon = new ImageIcon("omega.gif");
bar5 = new JButton(omega_icon);
bar5.setActionCommand("bar5");
bar5.addActionListener(this);
getContentPane().add(bar5);
setSize(160, 140);
setLocation(60,80);
setVisible(true);
}
if(bar == 6) {
candy_icon = new ImageIcon("candy.gif");
bar6 = new JButton(candy_icon);
bar6.setActionCommand("bar6");
bar6.addActionListener(this);
getContentPane().add(bar6);
setSize(160, 140);
setLocation(60,80);
setVisible(true);
}
this.addWindowListener
(
new WindowAdapter() {
public void windowClosing(WindowEvent e) {
setVisible(false);
}
}
);
}
public void actionPerformed(java.awt.event.ActionEvent e) {
setVisible(false);
}
}