• Post Reply Bookmark Topic Watch Topic
  • New Topic

Java cannot resolve word into type?  RSS feed

 
Samuel Weston
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, I am creating a user friendly program that allows the user to adjust the dimensions of an oval (painted onto a window) via a 'slider'
Everything is fine for the most part, except in the main code- when I tried coding for a window object for some reason java didn't recognize the type
(that is, I used the keyword TheWindow and java didn't recognize it) the following is the full code set across 2 classes, but I think the problem is centered around the main class.

I took out my comments to keep things neat- but I don't know for sure if I erased anything important.

thank you for your help




the following is 2 of 3





finally, the following is 3 of 3 (the main class)
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you have a class called TheWindow ? There isn't one in the standard API.
 
Stan Giggs
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
In order to create new object "w", class called "TheWindow" should exist.
Did you create it?
Otherwise you might want to use java.lang.JFrame instead.
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stan Giggs wrote:Otherwise you might want to use java.lang.JFrame instead.


Did you mean javax.swing.JFrame?
 
Campbell Ritchie
Marshal
Posts: 56529
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't like your names for classes nor for identifiers, I am afraid.
TheWindow, L23_DrawinganOvalwithSlider, myPanelz???

You might have been told to use such names, but have a look at the old Sun conventions. I wish they would update them rather than saying they are for archive purposes only.
 
Robert D. Smith
Ranch Hand
Posts: 221
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Some good advice has been given.

You are correct that the problem is in Main and with TheWindow.
will never return anything, until you create TheWindow object. It is the same as calling something like JPanel without including the java.awt.* (more or less). Your main has no clue what TheWindow is or what it is supposed to be.

Secondly, Campbell is, as usual, spot on regarding your variable names. Looking at the names, I assumed it was for a school project and didn't give it another thought. I suggest you listen to him and follow the link. One of my first "programming" jobs was as a COBOL programmer for the local school board. The lead programmer used really descriptive variable names like X, XX, XXX, XXXX, XXXIV -- you get the idea. Fortunately, I was a much better programmer than he, and my first mentor had me programming in C along side all the other languages they were using.

Anyway, (sorry, I have a propensity for making a short story long), my point is it is much better to start with good habits. In the long run, your code will be easier to read, maintain and modify -- for you and the poor guy who has to come in after you.

Regards,
Robert
 
Junilu Lacar
Sheriff
Posts: 11477
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:I don't like your names for classes nor for identifiers, I am afraid.
TheWindow, L23_DrawinganOvalwithSlider, myPanelz???

I agree. Just read these out loud and listen to yourself to get an idea of how, well, silly they are.

Code should be almost conversational when you read it. To achieve this, classes and object references should have names that are nouns or noun phrases. Methods generally should have names that are verb phrases. The main exception to this are boolean methods and boolean variables. The names of these should suggest a state of being, such as "isEmpty", "hasElements", "done", or "found".

Read these two sentences out loud:
1. "This special kind of JPanel is an L23_DrawinganOvalWithSlider"
2. "This special kind of JPanel is an OvalWithSlider"

The first one sounds rather silly when you read it out loud, doesn't it?
 
Samuel Weston
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah! Yes, I thought so. I since made a Window class to reflect the programs needs. Thank you
And thank you all for the recommendations on the naming conventions. I am now aware that they're an offense to the eye.
I'll take your advice into consideration in the future.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!