The Artima Developer Community
Sponsored Link

Java Answers Forum
a simple problem with GUI

1 reply on 1 page. Most recent reply: Nov 26, 2004 5:37 AM by Matthias Neumair

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
karim

Posts: 5
Nickname: apahliani
Registered: Nov, 2004

a simple problem with GUI Posted: Nov 26, 2004 2:47 AM
Reply to this message Reply
Advertisement
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);
}
}


Matthias Neumair

Posts: 660
Nickname: neumi
Registered: Sep, 2003

Re: a simple problem with GUI Posted: Nov 26, 2004 5:37 AM
Reply to this message Reply
I think your problem ist that the System calls the paint() method wich empties the window since you did not override it.

Example:

import javax.swing.*;
import java.awt.*;
 
public class ShowImage extends JFrame {
 
  public static void main(String[ ] args) {
    ShowImage si=new ShowImage();
    si.setSize(770, 420);
    si.show();
  }
 
  public void paint (Graphics g) {
    //Graphics g=si.getGraphics();
    Image im;
    Toolkit T=si.getToolkit();
    im=T.getImage("Jumbo.jpg");
    g.drawImage(im, 50,50, this);
  }
}



This certainly will not solve all of your problems, but it is a start.

Flat View: This topic has 1 reply on 1 page
Topic: ADT Graph help Previous Topic   Next Topic Topic: how to pass the SOAPMessage as argument  to the server interface class

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use