Click to See Complete Forum and Search --> : Creating graphics in application (not applet).
Jan Meeuwesen
February 23rd, 2000, 07:55 AM
Hi there,
It's probably a 'not so smart' question, but I was wondering if you could post a piece (or complete example) of code, on showing a graphic in a window. I've did it before in applets and had no problems. But now I'm creating a stand-alone program, I can't figure it out. There must be some difference, but I can't find any documentation on this in my books.
Thanx,
Jan Meeuwesen.
Rajesh Ajmera
February 23rd, 2000, 09:04 AM
Hi
U can try this -
import java.awt.*;
import java.awt.event.*;
public class graphTest extends Frame
{
public graphTest()
{
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
public static void main(String[] arg)
{
graphTest gt = new graphTest();
gt.setSize(200,200);
gt.setVisible(true);
}
public void paint(Graphics g)
{
g.drawString("Rajesh Ajmera",30,50);
}
}
Rajesh Ajmera
Jan Meeuwesen
February 23rd, 2000, 09:13 AM
Hi there,
Thank you very much for your reply but... (Oh no here it comes :---)... I guess you didn't understand the question the way I ment it. I was did not mean A 'graphic string', but an Image like test.gif.
I'm very sorry for this inconvenience.
Thanx again,
Jan Meeuwesen.
March 1st, 2000, 01:02 PM
Under g.drawString("Rajesh Ajmera",30,50); in the previous code add this:
g.drawImage(Toolkit.getDefaultToolkit().getImage("images/led_ron.gif"),30,60,this);
where the 'gif' image is your image...
hope this helps...
DHunter21
March 2nd, 2000, 10:41 AM
Jan,
There are two methods I can think of. If you are using JFrame, you either want to create a layeredPane and overwrite the public void paint(Graphics g){} method, to paint the image onto the LayeredPane, then you can call frame.setLayeredPane(backgroundPane). Another way would be to create a JPanel, and overwrite the public void paint(Graphics g) method, and set that to the content pane. I think the layeredpane workes the best.
Dustin
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.