DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2004
    Posts
    7

    simple GUI problem

    I´ve 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

Bookmarks

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


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links