The Artima Developer Community
Sponsored Link

Java Answers Forum
problem with setVisible(false);

2 replies on 1 page. Most recent reply: May 3, 2003 7:19 AM by Dougie Murray

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 2 replies on 1 page
Dougie Murray

Posts: 2
Nickname: dougiem
Registered: May, 2003

problem with setVisible(false); Posted: May 3, 2003 3:12 AM
Reply to this message Reply
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);} 		
}


Singh M.

Posts: 154
Nickname: ms
Registered: Mar, 2002

Re: problem with setVisible(false); Posted: May 3, 2003 3:33 AM
Reply to this message Reply
change this line in your init method from

PopFrame popup = new PopFrame(im);

to

popup = new PopFrame(im);

Dougie Murray

Posts: 2
Nickname: dougiem
Registered: May, 2003

Re: problem with setVisible(false); Posted: May 3, 2003 7:19 AM
Reply to this message Reply
That was perfect - Thanks, dougiem

Flat View: This topic has 2 replies on 1 page
Topic: voice chat Previous Topic   Next Topic Topic: Writing to a file.

Sponsored Links



Google
  Web Artima.com   

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