[b]challenge[/b]:
1. Use NetBeans’ GUIBuilder to create your user interface
2. The user should have a button to “fish” or “exit”
3. Show pictures of what has been caught so far
4. When “exit” is clicked, show a total score (how you score is up to you)
in this game, a six-sided die is rolled to determine what the user has caught. Each possibility item is worth a certain number of fishing points. The points will all remain hidden until the user is finished fishing, and then a message is displayed congratulating the user, depending on the number of fishing points gained
-> I did this code listed below by myself and it working rest
BUT the output that i keep getting is exactly the same no matter if i put different number in
i also did not get how can i make my output run in the same window as where i insert my number...please help
public class fish extends java.awt.Frame {
int pointTotal=0; //total points for this game
/**
* Creates new form fish
*/
public fish() {
initComponents();
}
/**
* 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.
*/
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
jButton1 = new javax.swing.JButton();
jLabel1 = new javax.swing.JLabel();
jTextField1 = new javax.swing.JTextField();
jLabel2 = new javax.swing.JLabel();
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
exitForm(evt);
}
});
jPanel1.setBackground(new java.awt.Color(255, 255, 255));
jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "*** Let's Go Fishing! ***", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.BELOW_TOP));
jButton1.setText("FISH :D/>");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jPanel1.add(jButton1);
jLabel1.setFont(new java.awt.Font("Matura MT Script Capitals", 0, 18)); // NOI18N
jLabel1.setText("How many times do you want to try?");
jPanel1.add(jLabel1);
jTextField1.setHorizontalAlignment(javax.swing.JTextField.CENTER);
jTextField1.setText("text here");
jTextField1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextField1ActionPerformed(evt);
}
});
jPanel1.add(jTextField1);
jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/fishinggame/Penguin-fishing-animation.gif"))); // NOI18N
jPanel1.add(jLabel2);
add(jPanel1, java.awt.BorderLayout.CENTER);
pack();
}// </editor-fold>//GEN-END:initComponents
/**
* Exit the Application
*/
private void exitForm(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_exitForm
}//GEN-LAST:event_exitForm
private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField1ActionPerformed
Random num = new Random();
// these are the "prizes"
String [] prizes = {"Old Shoe", "Basketball", "DVD", "Wet towel",
"Huge fish", "Gold coin"};
int [] points = {-5, 5, 10, -3, 10, 20};
int prizeNum = 0;
int numTimes = 0;
for (int i = 0; i<numTimes; i++) //arbitrarily does it 10 times
{
prizeNum = num.nextInt(6); //random number 0 - 5
pointTotal += points[prizeNum]; //accumulate points
System.out.println("You won: "+prizes[prizeNum]+" for " +points[prizeNum] +" points");
} // end for loop
}//GEN-LAST:event_jTextField1ActionPerformed
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
Random num = new Random();
// these are the "prizes"
String [] prizes = {"Old Shoe", "Basketball", "DVD", "Wet towel",
"Huge fish", "Gold coin"};
int [] points = {-5, 5, 10, -3, 10, 20};
int prizeNum = 0;
int numTimes = 0;
for (int i = 0; i<numTimes; i++) //arbitrarily does it 10 times
{
prizeNum = num.nextInt(6); //random number 0 - 5
pointTotal += points[prizeNum]; //accumulate points
System.out.println("You won: "+prizes[prizeNum]+" for " +points[prizeNum] +" points");
} // end for loop
FishingGame1 fg = new FishingGame1(0);
System.out.println("Your catch is "+prizes[prizeNum]+" for " +points[prizeNum] +" points");
// end constructor
System.exit(0);
}//GEN-LAST:event_jButton1ActionPerformed
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
new fish().setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton jButton1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JPanel jPanel1;
private javax.swing.JTextField jTextField1;
// End of variables declaration//GEN-END:variables
}

New Topic/Question
Reply



MultiQuote


|