Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 8 of 8

Thread: Novice: Issues With One-Armed Bandit Program

  1. #1
    Junior Member
    Join Date
    Dec 2012
    Posts
    4
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Exclamation Novice: Issues With One-Armed Bandit Program

    i am doing a assignment where i have to make a electronic bandit on ecplise.. i need to make

    hold buttons
    nudge buttons
    spin button
    exit button
    transfer winning button
    box showing how much you win when it spins
    add 1 pound button
    sound while pictures spins
    date a time displayed
    slo mo preview

    now at the moment my assignment has a okay layout but nothing works.. i don't know how to do any of the key factors as it is my first time using java script.. if anyone could help me know how to do all these you would be a star.. here the entire code i have so far..

    it is based on the Simpsons if anyone could help me know what i am doing wrong or how to do any of these it would really help..

    package electronicbandit;

    CODE:

    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); 
    	    } 
    }

    hope someone can solve all my problems ??


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Novice: Issues With One-Armed Bandit Program

    Make a list of the problems and work through them one at a time.
    What is the first problem that you are working on?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Dec 2012
    Posts
    4
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Novice: Issues With One-Armed Bandit Program

    how to make the exit button work so the code i have so far is ..

    public void actionPerformed(ActionEvent)}
    If(event.getSource()==btnexit{
    JOptionPane.showMessageDialog(null, "");
    system.exit(0);

    but its not working?

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Novice: Issues With One-Armed Bandit Program

    its not working?
    There are many ways for code to not work. Can you explain what happens when you execute the code?


    Add a call to the println method first thing in the method to see if it is called.
    If you don't understand my answer, don't ignore it, ask a question.

  5. The Following User Says Thank You to Norm For This Useful Post:

    joshstevens19 (December 5th, 2012)

  6. #5
    Junior Member
    Join Date
    Dec 2012
    Posts
    4
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Novice: Issues With One-Armed Bandit Program

    i have changed the code so it works fine now (no errors) but it does not exit the bandit machine..

    if(e.getSource()==btnexit){
    JOptionPane.showMessageDialog(null, "exit game");
    System.exit(0);}
    }

    thats the code but when clicked it does not exit the game.. all i want to do is exit the game

  7. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Novice: Issues With One-Armed Bandit Program

    Does the println message you added in the actionPerformed() method print when the exit button is pressed?


    Where is the if statement you just posted located inside of the actionPerformed method?
    Is it being executed? Add a println statement immediately before the if statement to see if the code there is executed.
    If you don't understand my answer, don't ignore it, ask a question.

  8. The Following User Says Thank You to Norm For This Useful Post:

    joshstevens19 (December 5th, 2012)

  9. #7
    Junior Member
    Join Date
    Dec 2012
    Posts
    4
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Novice: Issues With One-Armed Bandit Program

    public void actionPerformed(ActionEvent e)
    if(e.getSource()==btnexit){
    JOptionPane.showMessageDialog(null, "exit game");
    System.exit(0);}
    }

    thats what i have got.. can you change my code and il try it .. as i dont understand what you mean as im not very good at this ha

    thanks

  10. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Novice: Issues With One-Armed Bandit Program

    Add some println() statements to the code that will print out a message when they are executed. You need to see if the code in the actionPerformed() method is being executed. If the message is not printed, then you know the code is not being executed. Add several lines like the following to the actionPerformed() method: first thing in the method and also just before the if() statement you posted.
    System.out.println("in aP 1"); // show msg if executed
    Change the 1 to 2 and 3 etc so each print out has a different message.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Issues with my ordering program - if statement issues?
    By Shenaniganizer in forum What's Wrong With My Code?
    Replies: 5
    Last Post: October 31st, 2012, 10:17 PM
  2. [SOLVED] Using recursion issues for basic program
    By ash12 in forum What's Wrong With My Code?
    Replies: 0
    Last Post: August 5th, 2012, 10:40 PM
  3. [SOLVED] Having Issues Wish this Program
    By userct in forum What's Wrong With My Code?
    Replies: 17
    Last Post: February 9th, 2012, 03:46 PM
  4. Address Book Program Issues
    By Gamb1t in forum What's Wrong With My Code?
    Replies: 208
    Last Post: August 25th, 2011, 08:43 PM
  5. Issues with ascending number program
    By newtojava2011 in forum What's Wrong With My Code?
    Replies: 21
    Last Post: June 30th, 2011, 06:23 PM

Tags for this Thread