Results 1 to 4 of 4
- 05-25-2012, 03:38 AM #1
Member
- Join Date
- May 2012
- Posts
- 1
- Rep Power
- 0
Paint is invalid type for variable paint.
I am making a game and when I type in "public void paint(Graphics g) {", it says "graphics is an invalid type for variable paint." How do I fix it? Here is my code.
package maze;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class board extends JPanel implements ActionListener {
private Timer timer;
public board() {
timer = new Timer(25, this);
timer.start();
}
public void actionPerformed(ActionEvent e) {
repaint();
public void paint(Graphics g) {
super.paint(g);
g.setColor(Color.red);
g.fillRect(45, 60, 32, 32);
}
}
}
This is a snapshot of my screen.
- 05-25-2012, 04:16 AM #2
Senior Member
- Join Date
- Jun 2007
- Location
- Bali, Indonesia
- Posts
- 696
- Rep Power
- 6
Re: Paint is invalid type for variable paint.
You can't have a method inside another method. paint method should not be placed inside the actionPerformed method. It should be like this:
Java Code:... ... public void actionPerformed(ActionEvent e) { repaint(); } public void paint(Graphics g) { super.paint(g); g.setColor(Color.red); g.fillRect(45, 60, 32, 32); } ... ...Last edited by wsaryada; 05-25-2012 at 04:18 AM.
Website: Learn Java by Examples
- 05-25-2012, 05:52 AM #3
Re: Paint is invalid type for variable paint.
Why do they call it rush hour when nothing moves? - Robin Williams
- 05-25-2012, 05:52 AM #4
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,608
- Rep Power
- 5
Re: Paint is invalid type for variable paint.
...and do custom painting within paintComponent, not paint
Painting in AWT and Swing
Similar Threads
-
Paint
By ninjaturtlez in forum AWT / SwingReplies: 4Last Post: 12-17-2011, 04:15 AM -
paint and paintcomponent
By wired-in=p in forum New To JavaReplies: 3Last Post: 10-01-2011, 06:49 PM -
paint program
By dewdadamnthang in forum New To JavaReplies: 4Last Post: 03-30-2011, 11:40 AM -
Paint????
By seanfmglobal in forum New To JavaReplies: 3Last Post: 02-15-2011, 08:00 AM -
print variable with paint(Graphics g) ??
By tghn2b in forum New To JavaReplies: 10Last Post: 12-29-2008, 12:11 PM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks