Hello -
I am currently practicing on developing a small game where you have to guess a number from 1 to 10, with three attempts allowed. The game will tell you if the secret number is lower or greater than your guess. I have already done it with user's keyboard input; now I want to do it using only the mouse.
My problem is that I'm missing something, and I believe it's somethng simple, but I still can't find it. Here's the code:
/* * Filename: GTNB.java * Created: 10-24-2012 by MH * * Purpose: Conversion of Guess The Number game to button input. */ import javax.swing.*; import java.awt.*; import java.util.Random; public class GTNB extends JFrame { // set frame size private static final int WIDTH = 500; private static final int HEIGHT = 175; // declare component objects private JLabel labelB; private JButton j1B, j2B, j3B, j4B, j5B, j6B, j7B, j8B, j9B, j10B, jYB, jNB; // declare reference variables for event handlers private button1Handler j1BHandler; private button2Handler j2BHandler; private button3Handler j3BHandler; private button4Handler j4BHandler; private button5Handler j5BHandler; private button6Handler j6BHandler; private button7Handler j7BHandler; private button8Handler j8BHandler; private button9Handler j9BHandler; private button10Handler j10BHandler; private buttonYHandler jYBHandler; private buttonNHandler jNBHandler; //frame constructor public GuessTheNumberButton() { // frame properties JFrame frame = new JFrame(); setTitle("Guess The Number"); setSize( WIDTH, HEIGHT ); Container pane = getContentPane(); // JFrame method // create panel A JPanel panelA = new JPanel(); // create panel B JPanel panelB = new JPanel(); // instantiate panel A buttons JButton j1B = new JButton("1"); JButton j2B = new JButton("2"); JButton j3B = new JButton("3"); JButton j4B = new JButton("4"); JButton j5B = new JButton("5"); JButton j6B = new JButton("6"); JButton j7B = new JButton("7"); JButton j8B = new JButton("8"); JButton j9B = new JButton("9"); JButton j10B = new JButton("10"); // instantiate panel B label JLabel labelB = new JLabel(" "); // instantiate panel B buttons JButton jYB = new JButton("Yes"); JButton jNB = new JButton("No"); // add panel A buttons panelA.add(j1B); panelA.add(j2B); panelA.add(j3B); panelA.add(j4B); panelA.add(j5B); panelA.add(j6B); panelA.add(j7B); panelA.add(j8B); panelA.add(j9B); panelA.add(j10B); // add panel B label panelB.add(labelB); // yes/no buttons to be added later return 0; } // end method public static void main (Strings[] args) { JFrame aGuessTheNumberButton = new GuessTheNumberButton(); //GuessTheNumberButton(); aGuessTheNumberButton.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); aGuessTheNumberButton.getContentPane().add(BorderLayout.NORTH,panelA); aGuessTheNumberButton.setVisible(true); } // end main } // end class
I haven't written the event handling yet; I'm just creating the frame at this moment. My problem is in line 38, the declaration of the method, where I get "Invalid method declaration; return type required". It can't be void, so what would it be then? Can someone provide a hint?
Thanks!