Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to avoid opening of more windows for each click

Status
Not open for further replies.

2br

Programmer
Apr 21, 2002
6
IN
Dear All,

Whenever i click on the applet button/menu item, a new window is opening. How to avoid this...

i.e. the button(help)
When i clcik on the "Help" button/menu an HTML file in a new browser window should open. Ok.

My Problem is....
If i click again on the button/menu-"Help" another new browser window is opening. i.e, 100 new windows for 100 clicks

1)I need only Only one window even if i click more on the menu or button.

2)If the window is already open it should popup for the next click on the menu or button item.

the code used.

public class getHelp extends Applet implements ActionListener {
String msg = " ";
Button help;

public void init() {

help = new Button("Help");
add(help);
help.addActionListener(this);
}

public void actionPerformed(ActionEvent ae)
{
String str = ae.getActionCommand();

if(str.equals("Help"))
{
AppletContext ac = getAppletContext();
URL url = this.getCodeBase();
try{
ac.showDocument(new URL(url+ "SessionRecording.htm"), "_blank");

}catch(MalformedURLException e)
{
showStatus("URl not found");
}
}
}
}

where i have to modify

Please get me a solution in java

Regards
NewComer
(thanks in advance)
 
well this line of code is your problem:

ac.showDocument(new URL(url+ "SessionRecording.htm"), "_blank");

by using "_blank" it will allways open in a new window. If you want to open in the same window use "_self", if to want to open in an already opened window, just use the name of that window instead of "_blank".

So if your help window is called "helpWindow" you should use ac.showDocument(new URL(url+ "SessionRecording.htm"), "helpWindow");

this would throw an exception if helpWindow doesn't exist in that case just catch it and use "_blank" to create a new one.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top