View Single Post
  #1 (permalink)  
Old 08-06-2007, 08:11 PM
cachi cachi is offline
Member
 
Join Date: Jul 2007
Posts: 40
cachi is on a distinguished road
Error: cannot find symbol
Hello, After a little while of trying to figure this one out myself, I have given up on what should be a simple fix.

Error:

Code:
GuiGuessingGameApp.java:7: cannot find symbol symbol : constructor GuiGuessingGameFrame() location: class GuiGuessingGameFrame GuiGuessingGameFrame frame = new GuiGuessingGameFrame();
Code:
public class GuiGuessingGameTest { public static void main(String[] args) { GuiGuessingGameApp game = new GuiGuessingGameApp(); game.play(); } }
Code:
import java.util.Random; public class GuiGuessingGameApp { Random rnd = new Random(); int secretNumber = 0; GuiGuessingGameFrame frame = new GuiGuessingGameFrame(); public GuiGuessingGameApp() { secretNumber = 1 + rnd.nextInt(100); } public void play() { if (frame != null) frame.show(); } }

Code:
import javax.swing.JFrame; import javax.swing.*; import java.awt.event.*; import java.awt.*; public class GuiGuessingGameFrame { JFrame myFrame = new JFrame(); JTextField myField = new JTextField("",2); JLabel myLabel = new JLabel("Enter A Guess"); JButton myButton = new JButton ("Guess!"); int mySecretNumber = -1; public GuiGuessingGameFrame(int mySecretNumber) { myFrame = new JFrame("Guessing Game!"); myFrame.setSize(200,95); myFrame.setVisible(true); myFrame.addWindowListener(new WinHandler()); Container contain = myFrame.getContentPane(); contain.setLayout(new FlowLayout()); contain.add(myField); contain.add(myButton); contain.add(myLabel); myButton.addActionListener(new ButtonListener()); } public void show() { myFrame.show(); } class ButtonListener implements ActionListener { public void actionPerformed( ActionEvent evt) { int guess = 0; try { guess = Integer.parseInt(myField.getText()); } catch (NumberFormatException e) { guess = 0; } System.out.println("The Number In The Text Box Is " + guess); } } } class WinHandler extends WindowAdapter { public void windowClosing(WindowEvent e) {System.exit(0);} }
Thanks.
Reply With Quote
Sponsored Links