Plaatjes niet te zien en holdknoppen fruitmachine

Status
Niet open voor verdere reacties.

vandermees

Nieuwe gebruiker
Lid geworden
30 okt 2007
Berichten
1
Beste mensen,

Na lange tijd knutslen aan deze programma (fruitmachine) kan ik nog steeds geen plaatjes te zien en de holdknoppen erbij te zetten.

Weet iemand raad.

Alvast bedankt

DE CODE:
Code:
/*
 * Bandit.java
 */
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.net.URL;
import java.applet.*;
import java.util.Random;

public class Bandit extends JFrame 
{
  static JLabel bankLabel = new JLabel();
  static JTextField bankTextField = new JTextField();
  static JLabel messageLabel = new JLabel();
  static JLabel bandit0Label = new JLabel();
  static JLabel bandit1Label = new JLabel();
  static JLabel bandit2Label = new JLabel();
  static ImageIcon bell = new ImageIcon("bigbell.gif");
  static ImageIcon cherry = new ImageIcon("bigcherry.gif");
  static ImageIcon lemon = new ImageIcon("biglemon.gif");
  static ImageIcon orange = new ImageIcon("bigorange.gif");
  static ImageIcon plum = new ImageIcon("bigplum.gif");
  static ImageIcon star = new ImageIcon("jackpot.gif");
  static JButton spinButton = new JButton();
  static JButton exitButton = new JButton();
  static Timer stop0Timer;
  static Timer stop1Timer;
  static Timer stop2Timer;
  static Timer spinTimer;
  static Random myRandom = new Random();
  static int bankRoll = 100;
  static int[] finalValue = new int[3];
  static String noWin;
  static String win;
  static String jackpot;
  static ImageIcon[] choices = new ImageIcon[6];
  static final int LEMON = 0;
  static final int CHERRY = 1;
  static final int ORANGE = 2;
  static final int PLUM = 3;
  static final int BELL = 4;
  static final int STAR = 5;
 	static AudioClip spinSound;
 	static AudioClip jackpotSound;
 	static AudioClip wonSound;
 	static AudioClip sorrySound;
  
  public static void main(String args[]) 
  {
     
    // create frame
    new Bandit().show();
    try
    {
    	spinSound = Applet.newAudioClip(new URL("file:" + "spin.wav"));
    	jackpotSound = Applet.newAudioClip(new URL("file:" + "jackpot.wav"));
    	wonSound = Applet.newAudioClip(new URL("file:" + "tada.wav"));
    	sorrySound = Applet.newAudioClip(new URL("file:" + "uhoh.wav"));
    }
    catch (Exception ex)
    {
    }

  }
  public Bandit() 
  {
    // frame constructor
    setTitle("Prog03 Fruitmachine");
    setResizable(false);
    getContentPane().setBackground(Color.CYAN);
    addWindowListener(new WindowAdapter() 
    {
      public void windowClosing(WindowEvent evt) 
      {
        exitForm(evt);
      }
    });
    getContentPane().setLayout(new GridBagLayout());
    // position controls
    GridBagConstraints gridConstraints;
    bankLabel.setText("Bank");
    bankLabel.setFont(new Font("Arial", Font.BOLD, 18));
    gridConstraints = new GridBagConstraints();
    gridConstraints.gridx = 1;
    gridConstraints.gridy = 0;
    gridConstraints.insets = new Insets(5, 0, 0, 0);
    getContentPane().add(bankLabel, gridConstraints);
    bankTextField.setText("100");
    bankTextField.setFont(new Font("Arial", Font.PLAIN, 18));
    bankTextField.setColumns(6);
    bankTextField.setEditable(false);
    bankTextField.setBackground(Color.WHITE);
    bankTextField.setHorizontalAlignment(SwingConstants.CENTER);
    gridConstraints = new GridBagConstraints();
    gridConstraints.gridx = 1;
    gridConstraints.gridy = 1;
    gridConstraints.insets = new Insets(5, 0, 0, 0);
    getContentPane().add(bankTextField, gridConstraints);
    messageLabel.setText("   ");
    messageLabel.setFont(new Font("Arial", Font.BOLD, 18));
    gridConstraints = new GridBagConstraints();
    gridConstraints.gridx = 0;
    gridConstraints.gridy = 2;
    gridConstraints.gridwidth = 3;
    gridConstraints.insets = new Insets(5, 0, 0, 0);
    getContentPane().add(messageLabel, gridConstraints);
    gridConstraints = new GridBagConstraints();
    bandit0Label.setPreferredSize(new Dimension(120, 120));
    bandit0Label.setHorizontalAlignment(SwingConstants.CENTER);
    bandit0Label.setIcon(star);
    bandit0Label.setOpaque(true);
    bandit0Label.setBackground(Color.WHITE);
    gridConstraints.gridx = 0;
    gridConstraints.gridy = 3;
    gridConstraints.insets = new Insets(10, 10, 10, 10);
    getContentPane().add(bandit0Label, gridConstraints);
    gridConstraints = new GridBagConstraints();
    bandit1Label.setPreferredSize(new Dimension(120, 120));
    bandit1Label.setHorizontalAlignment(SwingConstants.CENTER);
    bandit1Label.setIcon(star);
    bandit1Label.setOpaque(true);
    bandit1Label.setBackground(Color.WHITE);
    gridConstraints.gridx = 1;
    gridConstraints.gridy = 3;
    gridConstraints.insets = new Insets(10, 10, 10, 10);
    getContentPane().add(bandit1Label, gridConstraints);
    gridConstraints = new GridBagConstraints();
    bandit2Label.setPreferredSize(new Dimension(120, 120));
    bandit2Label.setHorizontalAlignment(SwingConstants.CENTER);
    bandit2Label.setIcon(star);
    bandit2Label.setOpaque(true);
    bandit2Label.setBackground(Color.WHITE);
    gridConstraints.gridx = 2;
    gridConstraints.gridy = 3;
    gridConstraints.insets = new Insets(10, 10, 10, 10);
    getContentPane().add(bandit2Label, gridConstraints);
    spinButton.setText("Draai");
    gridConstraints = new GridBagConstraints();
    gridConstraints.gridx = 1;
    gridConstraints.gridy = 4;
    gridConstraints.insets = new Insets(10, 0, 10, 0);
    getContentPane().add(spinButton, gridConstraints);
    spinButton.addActionListener(new ActionListener() 
    {
      public void actionPerformed(ActionEvent e) 
      {
        spinButtonActionPerformed(e);
      }
    });
    exitButton.setText("Verlaat");
    gridConstraints = new GridBagConstraints();
    gridConstraints.gridx = 1;
    gridConstraints.gridy = 5;
    gridConstraints.insets = new Insets(0, 0, 5, 0);
    getContentPane().add(exitButton, gridConstraints);
    exitButton.addActionListener(new ActionListener() 
    {
      public void actionPerformed(ActionEvent e) 
      {
        exitButtonActionPerformed(e);
      }
    });
    spinTimer = new Timer(100, new ActionListener() 
    {
      public void actionPerformed(ActionEvent e) 
      {
        spinTimerActionPerformed(e);
      }
    });
    stop0Timer = new Timer(1000, new ActionListener() 
    {
      public void actionPerformed(ActionEvent e) 
      {
        stop0TimerActionPerformed(e);
      }
    });
    stop1Timer = new Timer(2000, new ActionListener() 
    {
      public void actionPerformed(ActionEvent e) 
      {
        stop1TimerActionPerformed(e);
      }
    });
    stop2Timer = new Timer(3000, new ActionListener() 
    {
      public void actionPerformed(ActionEvent e) 
      {
        stop2TimerActionPerformed(e);
      }
    });
    pack();
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    setBounds((int) (0.5 * (screenSize.width - getWidth())), (int) (0.5 * (screenSize.height - getHeight())), getWidth(), getHeight());
    choices[0] = lemon;
    choices[1] = cherry;
    choices[2] = orange;
    choices[3] = plum;
    choices[4] = bell;
    choices[5] = star;
  }
  private void spinButtonActionPerformed(ActionEvent e)
  {
    if (bankRoll == 0)
    {
      JOptionPane.showConfirmDialog(null, "Je hebt geen geld meer", "Je ligt eruit", JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE);
      System.exit(0);
    }
    bankRoll--;
    bankTextField.setText(String.valueOf(bankRoll));
    spinTimer.start();
    stop0Timer.start();
    stop1Timer.start();
    stop2Timer.start();
    messageLabel.setText("Draaien ...");
  }
  private void exitButtonActionPerformed(ActionEvent e)
  {
    JOptionPane.showConfirmDialog(null, "Je bent geeindigd " + bankRoll + " punten.", "Je ligt eruit", JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE);
    System.exit(0);
  }

  private void spinTimerActionPerformed(ActionEvent e)
  {
  	// Randomly display pictures
    // play spin sound
    spinSound.play();
    if (stop0Timer.isRunning())
    {
 	    bandit0Label.setIcon(choices[newIndex()]);
    }
    if (stop1Timer.isRunning())
    {
 	    bandit1Label.setIcon(choices[newIndex()]);
    }
    if (stop2Timer.isRunning())
    {
 	    bandit2Label.setIcon(choices[newIndex()]);
    }
  }

  private void stop0TimerActionPerformed(ActionEvent e)
  {
		// Stop spinning of first display
    stop0Timer.stop();
    finalValue[0] = newIndex();
    bandit0Label.setIcon(choices[finalValue[0]]);
  }
  private void stop1TimerActionPerformed(ActionEvent e)
  {
		// Stop spinning of second display
    stop1Timer.stop();
    finalValue[1] = newIndex();
    bandit1Label.setIcon(choices[finalValue[1]]);
	}
  private void stop2TimerActionPerformed(ActionEvent e)
  {
    int winnings = 0;
		// Stop spinning of final display
    spinTimer.stop();
    spinSound.stop();
    stop2Timer.stop();
    finalValue[2] = newIndex();
    bandit2Label.setIcon(choices[finalValue[2]]);
    // check for win
    if (finalValue[0] == CHERRY)
    {
    	winnings = 2;
      if (finalValue[1] == CHERRY)
      {
    		winnings = 2;
    		if (finalValue[2] == CHERRY)
    		{
          winnings = 6;
    		}
      }
    }
    else if (finalValue[0] == ORANGE && finalValue[1] == ORANGE && finalValue[2] == ORANGE)
    {
      winnings = 10;
    }
    else if (finalValue[0] == PLUM && finalValue[1] == PLUM && finalValue[2] == PLUM)
    {
      winnings = 20;
    }
    else if (finalValue[0] == BELL && finalValue[1] == BELL && finalValue[2] == BELL)
    {
      winnings = 30;
    }
    else if (finalValue[0] == STAR && finalValue[1] == STAR && finalValue[2] == STAR)
    {
      winnings = 50;
    }
    bankRoll += winnings;
    if (winnings == 50)
    {
    	messageLabel.setText("Jackpot! Gewonnen $50");
    	// play jackpot sound
    	jackpotSound.play();
    }
    else if (winnings > 0)
    {
    	messageLabel.setText("Gewonnen $" + String.valueOf(winnings));
    	// play tada sound
    	wonSound.play();
    }
    else
    {
    	messageLabel.setText("Sorry, deze ronde verloren");
    	// play uhoh sound
    	sorrySound.play();
    }
    bankTextField.setText(String.valueOf(bankRoll));
  }

  private void exitForm(WindowEvent evt) 
  {
    System.exit(0);
  }

  private int newIndex()
  {
  	return myRandom.nextInt(6);
  } 

}
 
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan