simple GUI problem


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: simple GUI problem

  1. #1
    Join Date
    Nov 2004
    Posts
    7

    simple GUI problem

    Ive written the following class ShowImage to put image on the screen but what I got was a blank window.Why could not I see the image on the screen?



    import javax.swing.*;
    import java.awt.*;


    public class ShowImage extends JFrame {

    public static void main(String[ ] args) {*

    ShowImage si=new ShowImage();
    Graphics g=si.getGraphics();
    Image im;
    Toolkit T=si.getToolkit();
    im=T.getImage("Jumbo.jpg");
    g.drawImage(im, 50,50,si);
    }
    public ShowIm(){
    this.setSize(770, 420);
    this.setVisible(true);
    }
    }

  2. #2
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    1,560
    You've not extended the JFrame class properly, you must override its paint(Graphics g) method. Drawing an image one time doesn't make it stick

    public static void main(String[ ] args) {*

    ShowImage si=new ShowImage();
    Image im;
    Toolkit T=si.getToolkit();
    im=T.getImage("Jumbo.jpg");
    }
    public ShowIm(){
    this.setSize(770, 420);
    this.setVisible(true);
    }
    public void paint (Graphics g) {
    g.drawImage(im, 0,0,this);
    }
    }
    eschew obfuscation

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center