• Post Reply Bookmark Topic Watch Topic
  • New Topic

Other Classes not Recognised by NetBeans GUI  RSS feed

 
Noel Morrissey
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I'm fairly new to Java but have some programming experience. I'm working on a University project creating a simple game using Netbeans but I'm totally stuck. I've created a number of classes to perform various methods, such as throwing back formatted text but I can't get them to work from within a Swing GUI created in Netbeans.

The Main method simply creates an instance of another class called Game which then itself creates instances of a number of other classes (textEngine, timer) and also a Swing GUI Class. The GUI appears on screen ok and I've been able to get methods working inside the GUI such as changing pictures and text when clicking a button. But I CANT get the GUI class to recognise the instances of the other classes or access their methods. I've created an instance of the TextEngine class called tEng. So I type this code in the GUI class:

textField.setText(tEng.getPhrase(2));

getPhrase() returns a String based on the number passed in the argument. But Netbeans reports an error that tEng is not recognised as a symbol despit it being a member of the same package. Creating the instance of the class within the GUI class likewise fails:

TextEngine tEng = new TextEngine();

Again the class is not recognised.

Any help would be gratefully appreciated. Many thanks.
K
 
Campbell Ritchie
Marshal
Posts: 56533
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

You haven't given us a lot of details, so I can only guess what might have gone wrong. You might have to show a bit of code if we are to help.
I presume you have spelt all the names of the classes right? No CapitaL LetterS out of place?
If tEng is to be recognised, I presume as the identifier for the TextEngine object, it must be a local variable in scope or a field, or a parameter for that method.
 
Noel Morrissey
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Thanks for your reply.

The syntax all seems fine its been thoroughly checked.

It does seem to be scope issue but I have no idea how to resolve it. It is not related to the GUI class as it also doesnt work with normal non-GUI classes. I tried this:



The Game class:



However if the tEng object is created by the Main class it is NOT found if thia code is in the game Object:

System.out.println(tEng.getPhrase(1,3,6));

'Symbol not found'

So its out of scope. How do I get different classes to work together?

Thanks Again!
K

 
Campbell Ritchie
Marshal
Posts: 56533
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you should use code tags, which I have added, and they make the post look a lot better
Your indentation is inconsistent; I suggest you copy‑and‑paste from NetBeans, which ought to organise the indentation for you. But you can see what is inside methods and what outside.
You can see tEng is a local variable inside the setup method; it has no existence outside that method. Are you going to pass it to other objects via their constructors or setTextEngine methods?

What's a Layered Frame? Are you not using Swing classes throughout? Why have you got a setVisible(true) call anywhere other than the last line of the method? You ought only to call setVisible on something like a JFrame. Is layered frame a subtype of JFrame?
 
Paul Clapham
Sheriff
Posts: 22823
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So the setup() method needs a TextEngine object. And the method which calls setup() has a TextEngine object. So why isn't it just a parameter of the setup() method?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!