Here's the code, if anyone could guide in my a direction that would be wonderful.
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package slots;
import java.util.*;
import javax.swing.JOptionPane;
/**
*
* @author MattLampe
* Slot Machine Program
*/
public class SlotsGUI extends javax.swing.JFrame {
public int val = 50;
public int spins = 10;
/**
* Creates new form SlotsGUI
*/
public SlotsGUI() {
initComponents();
availableSpinsText.setText("10");
Reel1.setText("");
Reel2.setText("");
Reel3.setText("");
currentCreditsText.setText("50");
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
spinButton = new javax.swing.JButton();
currentCredits = new javax.swing.JLabel();
availableSpins = new javax.swing.JLabel();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
Reel1 = new javax.swing.JTextField();
Reel2 = new javax.swing.JTextField();
Reel3 = new javax.swing.JTextField();
availableSpinsText = new javax.swing.JTextField();
currentCreditsText = new javax.swing.JTextField();
quitButton = new javax.swing.JButton();
aboutButton = new javax.swing.JButton();
jLabel4 = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
spinButton.setText("SPIN");
spinButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
spinButtonActionPerformed(evt);
}
});
currentCredits.setText("Current Credits");
availableSpins.setText("Available Spins");
jLabel1.setText("Reel 1");
jLabel2.setText("Reel 2");
jLabel3.setText("Reel 3");
Reel1.setText("jTextField1");
Reel2.setText("jTextField2");
Reel3.setText("jTextField3");
quitButton.setText("Quit");
quitButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
quitButtonActionPerformed(evt);
}
});
aboutButton.setText("About");
aboutButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
aboutButtonActionPerformed(evt);
}
});
jLabel4.setFont(new java.awt.Font("Lucida Grande", 0, 36)); // NOI18N
jLabel4.setText("Slot Machine");
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.addContainerGap()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(availableSpins)
.add(layout.createSequentialGroup()
.add(6, 6, 6)
.add(availableSpinsText, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 79, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
.add(85, 85, 85)
.add(currentCredits)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(currentCreditsText, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 35, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addContainerGap(39, Short.MAX_VALUE))
.add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
.add(aboutButton)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.add(quitButton))))
.add(layout.createSequentialGroup()
.add(42, 42, 42)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
.add(layout.createSequentialGroup()
.add(jLabel2)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(Reel2))
.add(layout.createSequentialGroup()
.add(jLabel1)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(Reel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 188, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(layout.createSequentialGroup()
.add(jLabel3)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(Reel3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 188, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
.add(layout.createSequentialGroup()
.add(102, 102, 102)
.add(spinButton)))
.add(0, 0, Short.MAX_VALUE))
.add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
.addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.add(jLabel4)
.add(71, 71, 71))
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.addContainerGap()
.add(jLabel4)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 27, Short.MAX_VALUE)
.add(spinButton)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(jLabel1)
.add(Reel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(jLabel2)
.add(Reel2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(jLabel3)
.add(Reel3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(51, 51, 51)
.add(availableSpins)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(availableSpinsText, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(currentCredits)
.add(currentCreditsText, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(16, 16, 16)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(quitButton)
.add(aboutButton)))
);
pack();
}// </editor-fold>
private void spinButtonActionPerformed(java.awt.event.ActionEvent evt) {
Random r = new Random();
int reel1, reel2, reel3;
reel1 = r.nextInt(3);
reel2 = r.nextInt(3);
reel3 = r.nextInt(3);
spins--;
availableSpinsText.setText(String.valueOf(spins));
currentCreditsText.setText(String.valueOf(val - 2));
if (spins > 0)
{
if (reel1 == 0)
{
Reel1.setText("Orange");
}
else if (reel1 == 1)
{
Reel1.setText("Banana");
}
else if (reel1 == 2)
{
Reel1.setText("Apple");
}
if (reel2 == 0)
{
Reel2.setText("Orange");
}
else if (reel2 == 1)
{
Reel2.setText("Banana");
}
else if (reel2 == 2)
{
Reel2.setText("Apple");
}
if (reel3 == 0)
{
Reel3.setText("Orange");
}
else if (reel3 == 1)
{
Reel3.setText("Banana");
}
else if (reel3 == 2)
{
Reel3.setText("Apple");
}
}
if (reel3 == reel2 && reel2 == reel1)
{
currentCreditsText.setText(String.valueOf(val + 5));
JOptionPane.showMessageDialog(null, "Jackpot! You've won 5 credits.");
}
else if (reel1 == reel2 || reel2 == reel3 || reel1 == reel3)
{
currentCreditsText.setText(String.valueOf(val + 1));
JOptionPane.showMessageDialog(null, "You've matched two! You win 1 coin.");
}
else
{
JOptionPane.showMessageDialog(null, "You've lost this round.");
}
if (spins == 0)
{
JOptionPane.showMessageDialog(null, "Game Over, you have used your 10 spins.");
System.exit(0);
}
}
private void quitButtonActionPerformed(java.awt.event.ActionEvent evt) {
System.exit(0);
}
private void aboutButtonActionPerformed(java.awt.event.ActionEvent evt) {
JOptionPane.showMessageDialog(null, "You have 10 turns to play the Slot Machine.\n If you have two matching items, you win 1 coin.\n "
+ "If you have three matching items, you win 5 coins.\n Each turn costs 2 coins.", "About", WIDTH);
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/*
* Set the Nimbus look and feel
*/
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/*
* If Nimbus (introduced in Java SE 6) is not available, stay with the
* default look and feel. For details see
* http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(SlotsGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(SlotsGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(SlotsGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(SlotsGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/*
* Create and display the form
*/
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new SlotsGUI().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JTextField Reel1;
private javax.swing.JTextField Reel2;
private javax.swing.JTextField Reel3;
private javax.swing.JButton aboutButton;
private javax.swing.JLabel availableSpins;
private javax.swing.JTextField availableSpinsText;
private javax.swing.JLabel currentCredits;
private javax.swing.JTextField currentCreditsText;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JButton quitButton;
private javax.swing.JButton spinButton;
// End of variables declaration
}

New Topic/Question
Reply



MultiQuote




|