• Post Reply Bookmark Topic Watch Topic
  • New Topic

Error: Cannot Find Symbol  RSS feed

 
Jim Morris
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all, I am trying to make a program that has a rectangle move across the screen in a GUI window from left to right. I am getting the "Cannot Find Symbol" error on lines 27 and 32 with my personal makeEm() method, and with paintComponent(); Can someone understand why I get this error and what I might need to do to correct it? I've posted my code below:

//while loop to keep advancing the frame

import java.awt.*;
import BreezySwing.*;

/** Draw with Graphics context. **/
public class sdf extends GBFrame{

int x=10;
int y=10;
private GBPanel panel;

public void makeEm(){
panel=addPanel(new GBPanel(),1,1,1,1);
panel.setBackground(Color.green);
}

public void paintComponent(Graphics g){
g.fillRect(x,y,50,20);
x+=10;
}

public static void main(String[] args){

int counter=100000;

makeEm teGUI= new makeEm(); //<--------line 27
teGUI.setSize(500,500);
teGUI.setVisible(true);

while(counter>= 1){
paintComponent(); //<-----------line 32
counter--;
}
}
}
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"SlashBack,"

Welcome to JavaRanch! Please check your private messages by clicking on My Private Messages. Thanks!
 
Mark Vedder
Ranch Hand
Posts: 624
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch

The problem on Line 27 is you are calling 'new' on a method. The 'new' keyword is used to create a new Object by calling that object's constructor. The constructor is named the same thing as the class. If you do not declare a constructor, a no arguments constructor is implicitly available. (In other words, you automatically get a default constructor that doesn't take any parameters.)

So your class is named 'sdf'. So you need to make an sdf object by calling the sdf() constructor using the 'new' keyword. Then you can call the 'makeEm()' method on that instance of the object.

That will solve the problem on line 27. Take a look at the The Java Tutorial -- especially the lesson on Objects and their creation. That will give you some guidance through it. Give that a try and let us know how it goes. Post your code one you have it. Please UseCodeTags when you post code so it is easier to read.

As for line 32, we can solve that once you have the line 27 problem solved.
[ December 31, 2008: Message edited by: Mark Vedder ]
 
Jim Morris
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alrighty, I believe I have fixed the line correctly. I have recompiled and now only have one error (Yay!) on line 33 that states "paintComponent(java.awt.Graphics) cannot be applied to ()" I don't quite understand this new error. Here is my new code:

What do you suppose would be the next step?

[ January 01, 2009: Message edited by: Jim Morris ]
[ January 01, 2009: Message edited by: Jim Morris ]
 
Campbell Ritchie
Sheriff
Posts: 53779
128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't call paintComponent() yourself. Leave the JVM to call it. If you need to call anything, try the repaint() method.

This now appears to be a GUI-related thread; these are usually discussed on the Swing forum.
Moving.
 
Campbell Ritchie
Sheriff
Posts: 53779
128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't call paintComponent() or repaint() like that from the main() method. That is because they are not static. You could say teGUI.repaint().
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> I am trying to make a program that has a rectangle move across the screen in a GUI window from left to right.

1) use a javax.swing.Timer to do:
x += 10;
repaint();

2) just have your graphics in paintComponent, not the x += 10
(many things could cause a repaint, each would be adding 10 to x,
so your movement may get out of sync)

3) to show movement across the screen, not 'expansion' of your rectangle,
you would need to clear the screen between repaints, easiest way is to
have as the first line of paintComponent
super.paintComponent(g);

should be enough to start you off
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!