cadillac
asked on
Using Java Frame class
I am using the java frame class to create a floating menu bar for my web site. I have 5 different HTML pages which I want to be able to open from this menu bar. I can open up one page, but if I try to open up another page I get no response. I believe it has something to do with the fact that the page that is now open is not the one that has the applet anchored to it, which in turn initialized the frame. Is this right, and if so, how can I correct this so that I can always open up a new page from the menubar? If this is not right, does anyone know what the problem is, and if so, how can I correct it?
The following is my code for this frame:
import java.awt.*;
import java.net.URL;
import java.net.MalformedURLExcep tion;
import java.applet.*;
public class OptionFrame extends Frame
{
Applet theApplet;
String path = "file:///C|/VisualCafePro/ BNP Real/";
void Browse_Action(Event event)
{
openURL(path +"html1.html");
}
void Submit_Action(Event event)
{
openURL(path +"html2.html");
}
void PMT_Action(Event event)
{
openURL(path +"html3.html");
}
void Help_Action(Event event)
{
openURL(path +"html4.html");
}
void Online_Action(Event event)
{
openURL(path +"html5.html");
}
void Close_Action(Event event)
{
this.hide();
}
public OptionFrame(Applet applet)
{
//{{INIT_CONTROLS
setLayout(null);
addNotify();
resize(insets().left + insets().right + 783,insets().top + insets().bottom + 130);
setBackground(new Color(12632256));
toolbar = new symantec.itools.awt.util.T oolBarPane l();
toolbar.setLayout(null);
toolbar.reshape(insets().l eft + 3,insets().top + 6,779,116);
add(toolbar);
toolbar.setBevelStyle(syma ntec.itool s.awt.util .ToolBarPa nel.BEVEL_ NONE);
btn1 = new symantec.itools.awt.ImageB utton();
btn1.reshape(0,0,141,84);
toolbar.add(btn1);
try {
btn1.setImageURL(new java.net.URL("file:/C:/Vis ualCafePro /BNP Real/browse.gif"));
} catch (java.net.MalformedURLExce ption error) {
}
btn2 = new symantec.itools.awt.ImageB utton();
btn2.reshape(141,0,162,84) ;
toolbar.add(btn2);
try {
btn2.setImageURL(new java.net.URL("file:/C:/Vis ualCafePro /BNP Real/submit.gif"));
} catch (java.net.MalformedURLExce ption error) {
}
btn3 = new symantec.itools.awt.ImageB utton();
btn3.reshape(303,0,140,84) ;
toolbar.add(btn3);
try {
btn3.setImageURL(new java.net.URL("file:/C:/Vis ualCafePro /BNP Real/pmt.gif"));
} catch (java.net.MalformedURLExce ption error) {
}
btn4 = new symantec.itools.awt.ImageB utton();
btn4.reshape(443,0,151,84) ;
toolbar.add(btn4);
try {
btn4.setImageURL(new java.net.URL("file:/C:/Vis ualCafePro /BNP Real/help.gif"));
} catch (java.net.MalformedURLExce ption error) {
}
btn5 = new symantec.itools.awt.ImageB utton();
btn5.reshape(594,0,160,84) ;
toolbar.add(btn5);
try {
btn5.setImageURL(new java.net.URL("file:/C:/Vis ualCafePro /BNP Real/bits.gif"));
} catch (java.net.MalformedURLExce ption error) {
}
setTitle("Object Works Menu Bar");
//}}
//{{INIT_MENUS
menuBar1 = new java.awt.MenuBar();
fileMenu = new java.awt.Menu("File");
subMenu = new java.awt.Menu("Open");
subMenu.add("Browse Components");
subMenu.add("Submitting Components");
subMenu.add("Download PMT");
subMenu.add("Help/Support" );
subMenu.add("Bits and Pieces Online");
fileMenu.add(subMenu);
fileMenu.addSeparator();
fileMenu.add("Close Menu");
menuBar1.add(fileMenu);
setMenuBar(menuBar1);
//$$ menuBar1.move(2,104);
//}}
theApplet = applet;
show();
}
public String openURL(String url)
{
URL theURL = null;
try { theURL = new URL(url); }
catch ( MalformedURLException e)
{
System.out.println("Bad URL: " + theURL);
}
theApplet.getAppletContext ().showDoc ument(theU RL);
return url;
}
public OptionFrame(String title, Applet applet) {
this(applet);
setTitle(title);
}
public synchronized void show() {
move(50, 50);
super.show();
}
public boolean handleEvent(Event event) {
if (event.id == Event.WINDOW_DESTROY) {
hide(); // hide the Frame
return true;
}
return super.handleEvent(event);
}
public boolean action(Event event, Object arg)
{
if (event.target instanceof MenuItem)
{
String label = (String) arg;
if (label.equalsIgnoreCase("B rowse Components"))
{
Browse_Action(event);
return true;
} else
if (label.equalsIgnoreCase("S ubmitting Components"))
{
Submit_Action(event);
return true;
} else
if (label.equalsIgnoreCase("D ownload PMT"))
{
PMT_Action(event);
return true;
} else
if (label.equalsIgnoreCase("H elp/Suppor t"))
{
Help_Action(event);
return true;
} else
if (label.equalsIgnoreCase("B its and Pieces Online"))
{
Online_Action(event);
return true;
} else
if (label.equalsIgnoreCase("C lose Menu"))
{
Close_Action(event);
return true;
}
}
return super.action(event, arg);
}
//{{DECLARE_CONTROLS
symantec.itools.awt.util.T oolBarPane l toolbar;
symantec.itools.awt.ImageB utton btn1;
symantec.itools.awt.ImageB utton btn2;
symantec.itools.awt.ImageB utton btn3;
symantec.itools.awt.ImageB utton btn4;
symantec.itools.awt.ImageB utton btn5;
//}}
//{{DECLARE_MENUS
java.awt.MenuBar menuBar1;
java.awt.Menu fileMenu;
java.awt.Menu subMenu;
//}}
}
The following is my code for this frame:
import java.awt.*;
import java.net.URL;
import java.net.MalformedURLExcep
import java.applet.*;
public class OptionFrame extends Frame
{
Applet theApplet;
String path = "file:///C|/VisualCafePro/
void Browse_Action(Event event)
{
openURL(path +"html1.html");
}
void Submit_Action(Event event)
{
openURL(path +"html2.html");
}
void PMT_Action(Event event)
{
openURL(path +"html3.html");
}
void Help_Action(Event event)
{
openURL(path +"html4.html");
}
void Online_Action(Event event)
{
openURL(path +"html5.html");
}
void Close_Action(Event event)
{
this.hide();
}
public OptionFrame(Applet applet)
{
//{{INIT_CONTROLS
setLayout(null);
addNotify();
resize(insets().left + insets().right + 783,insets().top + insets().bottom + 130);
setBackground(new Color(12632256));
toolbar = new symantec.itools.awt.util.T
toolbar.setLayout(null);
toolbar.reshape(insets().l
add(toolbar);
toolbar.setBevelStyle(syma
btn1 = new symantec.itools.awt.ImageB
btn1.reshape(0,0,141,84);
toolbar.add(btn1);
try {
btn1.setImageURL(new java.net.URL("file:/C:/Vis
} catch (java.net.MalformedURLExce
}
btn2 = new symantec.itools.awt.ImageB
btn2.reshape(141,0,162,84)
toolbar.add(btn2);
try {
btn2.setImageURL(new java.net.URL("file:/C:/Vis
} catch (java.net.MalformedURLExce
}
btn3 = new symantec.itools.awt.ImageB
btn3.reshape(303,0,140,84)
toolbar.add(btn3);
try {
btn3.setImageURL(new java.net.URL("file:/C:/Vis
} catch (java.net.MalformedURLExce
}
btn4 = new symantec.itools.awt.ImageB
btn4.reshape(443,0,151,84)
toolbar.add(btn4);
try {
btn4.setImageURL(new java.net.URL("file:/C:/Vis
} catch (java.net.MalformedURLExce
}
btn5 = new symantec.itools.awt.ImageB
btn5.reshape(594,0,160,84)
toolbar.add(btn5);
try {
btn5.setImageURL(new java.net.URL("file:/C:/Vis
} catch (java.net.MalformedURLExce
}
setTitle("Object Works Menu Bar");
//}}
//{{INIT_MENUS
menuBar1 = new java.awt.MenuBar();
fileMenu = new java.awt.Menu("File");
subMenu = new java.awt.Menu("Open");
subMenu.add("Browse Components");
subMenu.add("Submitting Components");
subMenu.add("Download PMT");
subMenu.add("Help/Support"
subMenu.add("Bits and Pieces Online");
fileMenu.add(subMenu);
fileMenu.addSeparator();
fileMenu.add("Close Menu");
menuBar1.add(fileMenu);
setMenuBar(menuBar1);
//$$ menuBar1.move(2,104);
//}}
theApplet = applet;
show();
}
public String openURL(String url)
{
URL theURL = null;
try { theURL = new URL(url); }
catch ( MalformedURLException e)
{
System.out.println("Bad URL: " + theURL);
}
theApplet.getAppletContext
return url;
}
public OptionFrame(String title, Applet applet) {
this(applet);
setTitle(title);
}
public synchronized void show() {
move(50, 50);
super.show();
}
public boolean handleEvent(Event event) {
if (event.id == Event.WINDOW_DESTROY) {
hide(); // hide the Frame
return true;
}
return super.handleEvent(event);
}
public boolean action(Event event, Object arg)
{
if (event.target instanceof MenuItem)
{
String label = (String) arg;
if (label.equalsIgnoreCase("B
{
Browse_Action(event);
return true;
} else
if (label.equalsIgnoreCase("S
{
Submit_Action(event);
return true;
} else
if (label.equalsIgnoreCase("D
{
PMT_Action(event);
return true;
} else
if (label.equalsIgnoreCase("H
{
Help_Action(event);
return true;
} else
if (label.equalsIgnoreCase("B
{
Online_Action(event);
return true;
} else
if (label.equalsIgnoreCase("C
{
Close_Action(event);
return true;
}
}
return super.action(event, arg);
}
//{{DECLARE_CONTROLS
symantec.itools.awt.util.T
symantec.itools.awt.ImageB
symantec.itools.awt.ImageB
symantec.itools.awt.ImageB
symantec.itools.awt.ImageB
symantec.itools.awt.ImageB
//}}
//{{DECLARE_MENUS
java.awt.MenuBar menuBar1;
java.awt.Menu fileMenu;
java.awt.Menu subMenu;
//}}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
What you actually put there doesn't matter as long as you access showDocument( URL, String) rather than showDocument( URL).
if you have a window or frame with a name already and you want the document there, then use it. Otherwise netscape will create a new browser window with the name you put in.
if you have a window or frame with a name already and you want the document there, then use it. Otherwise netscape will create a new browser window with the name you put in.
ASKER