problem with setVisible(false);
Posted: May 3, 2003 3:12 AM
Advertisement
I am Trying a popup frame with an image. The basic code worked and I was trying to expand it to use WindowListener to close the frame. I can setVisible(true) in the int() but throws up a NullPointerException when I use setVisible(false) in the WindowClosingEvent. I can't see where i'm going wrong.import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.awt.image.*;
import java.applet.Applet;
public class testpop extends Applet implements WindowListener
{
public void init()
{
Image im=getImage(getCodeBase(),"map.gif" );
PopFrame popup = new PopFrame(im);
popup.addWindowListener(this );
popup.setSize(243,131);
popup.setVisible(true );//******THIS WORKS*******
}
public PopFrame popup;
public void windowDeactivated(WindowEvent e) { }
public void windowClosed(WindowEvent e) { }
public void windowDeiconified(WindowEvent e) { }
public void windowOpened(WindowEvent e) { }
public void windowIconified(WindowEvent e) { }
public void windowActivated(WindowEvent e) { }
public void windowClosing(WindowEvent e)
{
popup.setVisible(false );//*********THIS DOSN'T********
} // java.lang.NullPointerException
}
class PopFrame extends Frame
{
Image img;
public PopFrame(Image im){
img = im;}
public void paint(Graphics g){
g.drawImage(img,3,22,this );}
}