Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder DELOCH's Avatar
    Join Date
    Apr 2006
    Location
    Canada
    Posts
    537
    Thanks
    4
    Thanked 2 Times in 2 Posts

    Simple Image Problem

    PHP Code:
    import javax.swing.*;
    import java.awt.*;

    public class 
    ImageDraw extends JFrame
    {
        public 
    ImageDraw()
        {
            
    super("");
            
    setSize(300300);
            
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            
    setVisible(true);
        }
        public static 
    void main(String[] args){new ImageDraw();}
    }
    class 
    ImagePanel extends JPanel
    {
        public 
    void paintComponent(Graphics g)
        {
            
    super.paintComponent(g);
            
    Image im = new ImageIcon("image.jpg").getImage();
            
    g.drawImage(im00null);
        }

    the code above id a dumb code for placing an "image.jpg" onto the program...

    somewhy it doesn't work...

    I also tried using Toolkit.getDefaultToolkit().getImage() but it doesn't work(although when i checked it's getWidth, getHeight methods, they returned -1...<<error).

    thanks ahead of time... images are a big part of making... anything
    i know i can use bufferedimage but that's longer code...

  • #2
    New Coder
    Join Date
    Jun 2005
    Posts
    32
    Thanks
    0
    Thanked 2 Times in 2 Posts
    I don't see you actually instantiating an ImagePanel anywhere and putting it in the frame. Try adding something like:

    super("");
    setSize(300, 300);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    --> setContentPane( new ImagePanel() );
    setVisible(true);


  •  

    Posting Permissions

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