• Post Reply Bookmark Topic Watch Topic
  • New Topic

problem drawOval() cant be found.  RSS feed

 
Ben Hultin
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying out this tutorial to get this drawOval() to work but the compiler tells me that the drawOval cant be found.

I triple checked that my initialization is in place, and I have imported the proper library to get it to work. So I am at a loss here.

my code:



I appreciate the help
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying out this tutorial to get this drawOval() to work but the compiler tells me that the drawOval cant be found.


"drawOval" is not part of any standard Java library, but your code as written suggests that you have created a class called drawOval that appears to be derived from a JPanel. Have you done this? Can we see the code for this class?
 
Ben Hultin
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well now that I look at it. It does seem that drawOval wouldnt be a class but merely a method from the graphics library.
And the way in which myPanel is used it would suggest that it is a JPanel as you said. So to make this work better I made these adjustments:



I have two problems left in my code:




C:\Documents and Settings\ben\Desktop\park>javac Oval.java
.\Oval_Sub.java:14: call to super must be first statement in constructor
super("the title");
^
.\Oval_Sub.java:28: <anonymous Oval_Sub$1> is not abstract and does not override
abstract method stateChanged(javax.swing.event.ChangeEvent) in javax.swing.even
t.ChangeListener
new ChangeListener() {
^
2 errors



I am clueless about the first one. It must be something else
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Constructors do not have a return type do they?
 
Ben Hultin
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot for the help, I guess I am rustier than I thought with java.

Do you have any idea about the ChangeListener not being abstract and needing? to be in order to work with SateChanged()

I appreciate the help
 
Rob Spoor
Sheriff
Posts: 21092
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
stateChanged, not StateChanged.
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Case does matter in Java
Its always a good idea to have the API docs open and ready for reference while coding.
 
Ben Hultin
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot for the help, That fixed it. I compiled it without any errors but now I belive I may have shot myself in the foot.

I have another driven class that uses JPanel as the superclass:



Mainly this was holding setD() which is called into use in Oval_Sub class. So I decided I should make an object of this class to gain acess to setD().

While the program loaded no prb, the Oval would not appear, only the JPanel and slider works so far. Any thoughts on how I could rectify this?

Thanks
 
Rob Spoor
Sheriff
Posts: 21092
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you calling setD on the existing Oval_Sub_1 instance, or are you creating a new one?
 
Ben Hultin
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well these are the two lines I used to properly reference it, so I would imagine on the original instance, seeing as there wasnt one before.



This is all found in Oval_Sub.java

Originally I had it set up as so:



But this wouldnt make much sense seeing as myPanel refers to a JPanel (or would it?) plus the compiler has no idea where setD() is located, so thats why I made the object to make a reference.
 
Rob Spoor
Sheriff
Posts: 21092
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The instance you are creating on line 2 of that code snippet is never added to the user interface. It's different from the instance you are seeing, which is myPanel. You should use that one, but not declare it as a JPanel but as an Oval_Sub_1. Then you will be able to call its setD method.
 
Ben Hultin
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
At first I wasnt sure what you were meaning, I had one funky idea, but figured that must not be it. So I tried another way that made a lot more sense the more I thought about it.

myPanel can be used to set the background color and call setD() bc Oval_Sub_1 has the super class JPanel. No need to create another one. Once that clicked, then I knew what you were saying and what I needed to do to finish the program.

Works great, thanks a lot for the help
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!