package electronicbandit;
// Josh Stevens b1007780
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Random;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.Timer;
public class Electronicbandit extends JFrame implements ActionListener{
private JPanel paper;
private JButton btnspin,btncash,btnaddcash,btnexit,btnpic1,btnpic2,btnpic3,btnnudge1,btnnudge2,btnnudge3,btnhold1,btnhold2,btnhold3;
private Timer timer;
private int a = 0,b = 0,c = 0, counter, num, cash;
private ImageIcon iconpic1,iconpic2,iconpic3,iconpic4,iconpic5,iconpic6,iconpic7,iconpic8,iconpic9;
private Random random;
private JTextField txtbalance, txtwinnings;
private JLabel threesanta, twopudding, oneelf;
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==btnaddcash)
{
cash = cash +100;
txtbalance.setText("Funds £" + btncash);
if (cash >=500)
{
btnaddcash.setEnabled(false);
JOptionPane.showMessageDialog(null, "Can't add more funds");
}
if (cash <= 0)
{
btnaddcash.setEnabled(true);
}
if (cash >=10)
{
btnspin.setEnabled(true);
}
}
if(e.getSource()==btnspin){
counter=0;
timer.start();
txtbalance.setForeground(Color.white);
cash = cash - 10;
txtbalance.setText(cash + " ");
if (cash <= 0)
{
btnspin.setEnabled(false);
JOptionPane.showMessageDialog(null, "Insert more cash to play");
}
}
}
public Electronicbandit()
{
JOptionPane.showMessageDialog(null, "Electronic Bandit");
iconpic1= new ImageIcon("bin/Bart.jpg"); // add own images
iconpic2= new ImageIcon("bin/Baby.jpg");
iconpic3= new ImageIcon("bin/Bully.jpg");
iconpic4= new ImageIcon("bin/Burns.jpg");
iconpic5= new ImageIcon("bin/Busguy.jpg");
iconpic6= new ImageIcon("bin/Homer.gif");
iconpic7= new ImageIcon("bin/Lisa.png");
iconpic8= new ImageIcon("bin/Mayor.jpg");
iconpic9= new ImageIcon("bin/Smitheres.jpg");
setLayout(new FlowLayout());
timer = new Timer(500, this);
random = new Random();
setBackground(Color.red);
setLayout(new FlowLayout());
btnpic1=new JButton(iconpic2);
btnpic1.setPreferredSize(new Dimension(100, 100));
btnpic1.setBackground(Color.white);
btnpic2=new JButton(iconpic1);
btnpic2.setPreferredSize(new Dimension(100, 100));
btnpic2.setBackground(Color.white);
btnpic3=new JButton(iconpic1);
btnpic3.setPreferredSize(new Dimension(100, 100));
btnpic3.setBackground(Color.white);
//btnpic1=random.nextlnt(8);
//btnpic2=random.nextInt(8);
//btnpic3=random.nextInt(8); // need to sort out to make it random
btnspin=new JButton();
btnspin.setBackground(new Color(50, 255, 50));
btnspin.setToolTipText("Click to spin the bandit!");
btnspin.setText("Spin");
btnspin.setMaximumSize(new Dimension(200, 50));
btnspin.setMinimumSize(new Dimension(200, 50));
btnspin.setBackground(Color.blue);
//Electronicbandit spinApp = new Electronicbandit();
//spinApp.setVisible(true); // makes it spin
btnexit=new JButton();
btnexit.setBackground(new Color(50, 255, 50));
btnexit.setToolTipText("Click to spin the quit bandit!");
btnexit.setText("Exit");
btnexit.setMaximumSize(new Dimension(200, 50));
btnexit.setMinimumSize(new Dimension(200, 50));
btnexit.setBackground(Color.blue);
btncash=new JButton(iconpic1);
btncash.setPreferredSize(new Dimension(100, 100));
btncash.setBackground(Color.black);
btnaddcash=new JButton();
btnaddcash.setText("Add Cash");
btnaddcash.setToolTipText("Click to add credits");
btnaddcash.setPreferredSize(new Dimension(100, 100));
btnaddcash.setBackground(Color.green);;
btnnudge1=new JButton();
btnnudge1.setText("Nudge");
btnnudge1.setToolTipText("Nudge the picture");
btnnudge1.setPreferredSize(new Dimension(100, 100));
btnnudge1.setBackground(Color.yellow);;
btnnudge2=new JButton();
btnnudge2.setText("Nudge");
btnnudge2.setToolTipText("Nudge the picture");
btnnudge2.setPreferredSize(new Dimension(100, 100));
btnnudge2.setBackground(Color.yellow);;
btnnudge3=new JButton();
btnnudge3.setText("Nudge");
btnnudge3.setToolTipText("Nudge the picture");
btnnudge3.setPreferredSize(new Dimension(100, 100));
btnnudge3.setBackground(Color.yellow);;
btnhold1=new JButton();
btnhold1.setText("Hold");
btnhold1.setToolTipText("Hole this picture");
btnhold1.setPreferredSize(new Dimension(100, 100));
btnhold1.setBackground(Color.red);;
btnhold2=new JButton();
btnhold2.setText("Hold");
btnhold2.setToolTipText("Hole this picture");
btnhold2.setPreferredSize(new Dimension(100, 100));
btnhold2.setBackground(Color.red);;
btnhold3=new JButton();
btnhold3.setText("Hold");
btnhold3.setToolTipText("Hole this picture");
btnhold3.setPreferredSize(new Dimension(100, 100));
btnhold3.setBackground(Color.red);;
threesanta = new JLabel (iconpic4);
twopudding = new JLabel (iconpic1);
oneelf = new JLabel (iconpic1);
add(btnpic1);
add(btnpic2);
add(btnpic3);
add(btnspin);
btnspin.setEnabled(false);
add(btnexit);
add(btnnudge1);
add(btnnudge2);
add(btnnudge3);
add(btnaddcash);
add(btnhold1);
add(btnhold2);
add(btnhold3);
add(threesanta);
add(twopudding);
add(oneelf);
add(btncash);
txtbalance = new JTextField("Funds £");
txtbalance.setMaximumSize(new Dimension(200, 50));
txtbalance.setMinimumSize(new Dimension(200, 50));
txtwinnings = new JTextField("Winnings");
txtwinnings.setMaximumSize(new Dimension(200, 50));
txtwinnings.setMinimumSize(new Dimension(200, 50));
btnspin.addActionListener(this);
btnexit.addActionListener(this);
btncash.addActionListener(this);
btnaddcash.addActionListener(this);
setTitle("ElectronicBanditMachine");
setSize(500,500);
}
public static void main(String args[]) {
JFrame electronicBandit = new Electronicbandit();
electronicBandit.setVisible(true);
}
}