Viewing image on Personal Profile
I tring to do this since yesterday and i ve got no idea what is wrong. This is teh code:
<code>
import java.awt.*;
import java.awt.event.*;
public class proba extends Frame {
private Image image;
public proba(String fileName) {
Toolkit toolkit = Toolkit.getDefaultToolkit();
image = toolkit.getImage(fileName);
MediaTracker mediaTracker = new MediaTracker(this);
mediaTracker.addImage(image, 0);
try
{
mediaTracker.waitForID(0);
}
catch (InterruptedException ie)
{
System.err.println(ie);
System.exit(1);
}
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
setSize(image.getWidth(null), image.getHeight(null));
setTitle(fileName);
show();
}
public void paint(Graphics graphics) {
graphics.drawImage(image, 0, 0, null);
}
public static void main(String[] args) {
new proba("res/scott.jpg");
}
}
</code>
Perhaps this is the answer
Tried everything You have described, and still no results. Everytime i execute an emulator of S80 i do not get the desired picture on my canvas.
Perhaps it is the fault of the environment so i would like You to execute my simple class in Your IDE. Could You do that ??
Or perhaps You send me some similar example to execute.Very simple ofcourse.
Thanx in advance.
no can do my canvas has the right size
check the code:
import java.awt.*;
import java.awt.event.*;
public class proba extends Frame {
private Image image;
public proba() {
this.setLayout(new GridLayout(3, 1));
Toolkit tk = Toolkit.getDefaultToolkit();
Image im = tk.createImage("reklama.gif");
MediaTracker tracker = new MediaTracker(this);
tracker.addImage(im, 1);
try {
tracker.waitForID(1);
} catch (Exception e) {
e.printStackTrace();
}
CommercialCanvas cv = new CommercialCanvas(im);
cv.setSize(new Dimension(im.getWidth(null),im.getHeight(null)));
cv.setVisible(true);
add(cv);
cv.repaint();
pack();
show();
setVisible(true);
}
public static void main(String[] args) {
System.out.println("IDZIEMY");
new proba();
}
}
class CommercialCanvas extends Canvas {
private Image image;
public CommercialCanvas(Image image) {
this.image = image;
}
public void paint(Graphics g) {
g.drawImage(
image,
10,10,image.getWidth(this),image.getHeight(this),
this);
}
}
please try to run the code on Your emulator od S80 perhaps somethings is wrong with mine.