Solved

Using Java Frame class

Posted on 1997-07-17
3
280 Views
Last Modified: 2012-05-04
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.MalformedURLException;
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.ToolBarPanel();
            toolbar.setLayout(null);
            toolbar.reshape(insets().left + 3,insets().top + 6,779,116);
            add(toolbar);
            toolbar.setBevelStyle(symantec.itools.awt.util.ToolBarPanel.BEVEL_NONE);
            btn1 = new symantec.itools.awt.ImageButton();
            btn1.reshape(0,0,141,84);
            toolbar.add(btn1);
            try {
                  btn1.setImageURL(new java.net.URL("file:/C:/VisualCafePro/BNP Real/browse.gif"));
            } catch (java.net.MalformedURLException error) {
            }
            btn2 = new symantec.itools.awt.ImageButton();
            btn2.reshape(141,0,162,84);
            toolbar.add(btn2);
            try {
                  btn2.setImageURL(new java.net.URL("file:/C:/VisualCafePro/BNP Real/submit.gif"));
            } catch (java.net.MalformedURLException error) {
            }
            btn3 = new symantec.itools.awt.ImageButton();
            btn3.reshape(303,0,140,84);
            toolbar.add(btn3);
            try {
                  btn3.setImageURL(new java.net.URL("file:/C:/VisualCafePro/BNP Real/pmt.gif"));
            } catch (java.net.MalformedURLException error) {
            }
            btn4 = new symantec.itools.awt.ImageButton();
            btn4.reshape(443,0,151,84);
            toolbar.add(btn4);
            try {
                  btn4.setImageURL(new java.net.URL("file:/C:/VisualCafePro/BNP Real/help.gif"));
            } catch (java.net.MalformedURLException error) {
            }
            btn5 = new symantec.itools.awt.ImageButton();
            btn5.reshape(594,0,160,84);
            toolbar.add(btn5);
            try {
                  btn5.setImageURL(new java.net.URL("file:/C:/VisualCafePro/BNP Real/bits.gif"));
            } catch (java.net.MalformedURLException 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().showDocument(theURL);
        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("Browse Components"))
              {
                  Browse_Action(event);
                  return true;
              } else
              if (label.equalsIgnoreCase("Submitting Components"))
              {
                  Submit_Action(event);
                  return true;
              } else
              if (label.equalsIgnoreCase("Download PMT"))
              {
                  PMT_Action(event);
                  return true;
              } else
              if (label.equalsIgnoreCase("Help/Support"))
              {
                  Help_Action(event);
                  return true;
              } else
              if (label.equalsIgnoreCase("Bits and Pieces Online"))
              {
                  Online_Action(event);
                  return true;
              } else
              if (label.equalsIgnoreCase("Close Menu"))
              {
                  Close_Action(event);
                  return true;
              }
          }
          return super.action(event, arg);
    }

      //{{DECLARE_CONTROLS
      symantec.itools.awt.util.ToolBarPanel toolbar;
      symantec.itools.awt.ImageButton btn1;
      symantec.itools.awt.ImageButton btn2;
      symantec.itools.awt.ImageButton btn3;
      symantec.itools.awt.ImageButton btn4;
      symantec.itools.awt.ImageButton btn5;
      //}}

      //{{DECLARE_MENUS
      java.awt.MenuBar menuBar1;
      java.awt.Menu fileMenu;
      java.awt.Menu subMenu;
      //}}
}
0
Comment
Question by:cadillac
  • 2
3 Comments
 

Accepted Solution

by:
acidburn earned 100 total points
ID: 1223290
change your showDocument call as below:

      theApplet.getAppletContext().showDocument(theURL, "destwindow");

The trick here is that if you name the browser window explicitly like this, it keeps the old window open (and attached to the applet) but opens a new browser window for the document.  All subsequent showDocument calls will be sent to this new window, meanwhile your applet can stay up alongside it.

0
 

Author Comment

by:cadillac
ID: 1223291
Is destwindow a target frame, what do I actually put there?
0
 

Expert Comment

by:acidburn
ID: 1223292
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.  
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Java Message handling in Service Layer 3 55
Image decoding from Camera 3 72
Spring Framework HTTPSession management 1 22
session migration servlets 2 24
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now