|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Basic image handling help needed!
-----------------------------------------------------------
import java.io.*; import java.awt.*; import java.awt.image.*; public class DisplayImage extends Canvas { Image image; Toolkit toolkit = Toolkit.getDefaultToolkit(); public DisplayImage() { } public void loadImage() { image = toolkit.getImage("test.jpg"); } public void paint(Graphics g) { g.drawImage(image, 0, 0, this); } public static void main(String[] args){ DisplayImage displayimage = new DisplayImage(); displayimage.loadImage(); // here is where I want to call 'paint' //method, but don't know how } } ----------------------------------------------------------- Hello everyone, I was wondering if anyone could help me with the code above. I want the program to just basically load up an image and then display it, with typing in 'java DisplayImage imagename.jpg' from the command prompt. If I just call displayimage.paint(), it won't work because it needs to have Graphics g passed into it, and if I call displayimage.paint(image), it won't work because image is an Image object, not a Graphics object - yet a Graphics object can't be directly created or something. AAAaaaargh! help! |
![]() |
| Viewing: Dev Articles Community Forums > Programming > Java Development > Basic image handling help needed! |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|