-
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);
}
}
-
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
Forum Rules
|
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
|
Bookmarks