Latest Tutorials| Questions and Answers|Ask Questions?|Site Map




Have Programming Question? Ask it here!
 
 
 


gayathri
java-awt
2 Answer(s)      6 years and a month ago
Posted in : Java Beginners



Advertisement
View Answers

August 23, 2008 at 12:00 PM


hai frnd....
"\" is a special character...
i think u must use "\\" whereever u want "\"
try using this......
img = Toolkit.getDefaultToolkit().getImage("C:\\Documents and Settings\\gayathri\\My Documents\\My Pictures\\photo\\Image010.jpg");


or


img = Toolkit.getDefaultToolkit().getImage("C://Documents and Settings//gayathri//My Documents//My Pictures//photo//Image010.jpg");
hope it work..
thanks and regards

Prashu
prashobvee@gmail.com


August 27, 2008 at 4:16 PM


Hi friend,

i am sending code.

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.JFrame;


public class ImageDisplayTest {
public static void main(String[] args) {
ImagePanel panel = new ImagePanel(new ImageIcon("/home/vinod/amarexamples/cat.gif").getImage());
JFrame frame = new JFrame();
frame.getContentPane().add(panel);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(300,400);
frame.setVisible(true);
}
}

class ImagePanel extends JPanel {

private Image img;
public ImagePanel(String img) {
this(new ImageIcon(img).getImage());
}
public ImagePanel(Image img) {
this.img = img;

}

public void paintComponent(Graphics g) {
g.drawImage(img, 0, 0, null);
}

}

------------------------------------

Read for more information,

http://www.roseindia.net/java/


Thanks.


Related Tutorials/Questions & Answers:
 

 

 

DMCA.com