When I try to compile this program import java.awt.*;
import javax.swing.*;
public class graphics { public void paintComponent(Graphics g) {
JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(300,300); frame.setVisible(true);
Image image = new ImageIcon("Pauls_sword.gif").getImage(); g.drawImage(image,3,4,this);
} }
I get this error message MacBeverstock:~/Documents/program Brooks$ javac graphics.java graphics.java:14: cannot find symbol symbol : method drawImage(java.awt.Image,int,int,graphics) location: class java.awt.Graphics g.drawImage(image,3,4,this); ^ 1 error MacBeverstock:~/Documents/program Brooks$
Thank for any help you can offer.
Ernest Friedman-Hill
author and iconoclast
Marshal
A bit of business: you may not have read our naming policy on the way in. It requires that you use a full, real (sounding) first and last name for your display name. No cutesie-pie "handles", please; we're all adults here at the Ranch. You'll find that most people aren't too interested in helping until you follow the rules round these parts.
You can change your display name here. Thanks for your immediate attention.
Originally posted by (yberknight yo: ...I get this error message MacBeverstock:~/Documents/program Brooks$ javac graphics.java graphics.java:14: cannot find symbol symbol : method drawImage(java.awt.Image,int,int,graphics) location: class java.awt.Graphics...
If you check the API for Graphics, you will find several overridden drawImage methods. It looks like you're trying to call this one...
drawImage(Image img, int x, int y, ImageObserver observer)
The problem is that your fourth argument ("this") is an instance of graphics, which is not an ImageObserver (since it does not implement the ImageObserver interface).
Use the component you're going to draw on -- the frame or panel. All AWT and Swing components implement this interface.
Brooks MacBevers
Greenhorn
Joined: Apr 23, 2006
Posts: 9
posted
0
When I run the revised version of the program it compiles. This is it import java.awt.*; import javax.swing.*; public class graphics{ public void paintComponent(Graphics g) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(300,300); frame.setVisible(true); Image image = new ImageIcon("Pauls_sword.gif").getImage(); g.drawImage(image,3,4,frame); } } Then I get this error message MacBeverstock:~/Documents/program Brooks$ java graphics Exception in thread "main" java.lang.NoSuchMethodError: main
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32708
4
posted
0
You are supposed to put these four lines in a main() method, rather than in paintComponent():-
CR
Brooks MacBevers
Greenhorn
Joined: Apr 23, 2006
Posts: 9
posted
0
Can I get a some sample java for images.
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35252
7
posted
0
One of the Swing tutorial examples -LunarPhases- display images.