CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Nov 1999
    Location
    Tilburg-Breda, Noord-Brabant, The Netherlands
    Posts
    135

    Creating graphics in application (not applet).

    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.


  2. #2
    Join Date
    Oct 1999
    Posts
    6

    Re: Creating graphics in application (not applet).

    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


  3. #3
    Join Date
    Nov 1999
    Location
    Tilburg-Breda, Noord-Brabant, The Netherlands
    Posts
    135

    Re: Creating graphics in application (not applet).

    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.


  4. #4
    Guest

    Re: Creating graphics in application (not applet).

    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...


  5. #5
    Join Date
    Aug 1999
    Location
    San Diego
    Posts
    155

    Re: Creating graphics in application (not applet).

    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


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured