Opening up a URL page from a Java Dialog

Does anyone know how to open up another URL page from within a Java Dialog component.  I have a login dialog, and when the user clicks on the submit button, it is supposed to open up a new HTML page.  How can I do this.  Some source code would be very beneficial.  Thanks.
Bryan051997Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

vmanochaCommented:
use the following piece of code:(assume applet is your Applet object and urlStr contains the complete url-as a string of the new page that you want to display)applet.getAppletContext().showDocument(new URL(urlStr)) ;
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Bryan051997Author Commented:
that's correct. what you will need to do is, when you createthe dialog, you pass it a parameter which is your applet object. you can do this in the dialog's constructor. you can store this applet object as a member variable in the dialog class. when you invoke getAppletContex (), you can then do that using this applet object.
0
vmanochaCommented:
This is the code I have now:

import java.awt.*;
import java.net.URL;
import java.net.MalformedURLException;
import java.applet.*;
import symantec.itools.multimedia.ImageViewer;

public class TestDialog extends Dialog
{
    static Author author;
    static Author author2;
    static Author author3;
   
    String l_userid, l_pass;
   
    String FilePath = "file:///C|/VisualCafePro/Bnp/";
   
      public TestDialog(Frame parent, boolean modal, Applet applet) {

          super(parent, modal);

            //{{INIT_CONTROLS
            setLayout(null);
            addNotify();
            resize(insets().left + insets().right + 300,insets().top + insets().bottom + 271);
            setBackground(new Color(255));
            label2 = new java.awt.Label("Password:",Label.RIGHT);
            label2.reshape(insets().left + 9,insets().top + 205,79,24);
            label2.setFont(new Font("Helvetica", Font.BOLD, 13));
            label2.setForeground(new Color(16777215));
            add(label2);
            label1 = new java.awt.Label("User ID:",Label.RIGHT);
            label1.reshape(insets().left + 25,insets().top + 174,63,24);
            label1.setFont(new Font("Helvetica", Font.BOLD, 13));
            label1.setForeground(new Color(16777215));
            add(label1);
            userid = new java.awt.TextField();
            userid.reshape(insets().left + 98,insets().top + 175,144,26);
            userid.setFont(new Font("Dialog", Font.PLAIN, 13));
            userid.setBackground(new Color(16777215));
            add(userid);
            pass = new java.awt.TextField();
            pass.reshape(insets().left + 98,insets().top + 205,144,26);
            pass.setFont(new Font("Dialog", Font.PLAIN, 13));
            pass.setBackground(new Color(16777215));
            add(pass);
            quit = new java.awt.Button("Reset");
            quit.reshape(insets().left + 175,insets().top + 242,77,23);
            quit.setFont(new Font("Helvetica", Font.PLAIN, 12));
            add(quit);
            submit = new java.awt.Button("Submit");
            submit.reshape(insets().left + 91,insets().top + 242,77,23);
            submit.setFont(new Font("Helvetica", Font.PLAIN, 12));
            add(submit);
            imageViewer1 = new symantec.itools.multimedia.ImageViewer();
            imageViewer1.reshape(insets().left + 9,insets().top + 8,283,141);
            add(imageViewer1);
            try {
                  imageViewer1.setURL(new java.net.URL("file:/C:/VisualCafePro/BNP/Object.jpg"));
            } catch (java.net.MalformedURLException error) {
            }
            setTitle("Object Works Login");
            //}}
            userid.requestFocus();
            center(this ,300 ,350 , true);
      }

      public TestDialog(Frame parent, String title, boolean modal, Applet applet) {
          this(parent, modal, applet);
          setTitle(title);
      }
      
      public String openURL(String url)
    {
        URL theURL = null;
        try { theURL = new URL(url); }
        catch ( MalformedURLException e)
        {
            System.out.println("Bad URL: " + theURL);
        }
        applet.getAppletContext().showDocument(theURL);
        return url;
    }

    // This method displays the dialog component in the center of the browser.
    public static void center(Window w, int width, int height, boolean bSetVisible)
    {
        int xloc = 0;
        int yloc = 0;

        Toolkit tk;
        Dimension screenSize;

        if ((tk = w.getToolkit())!=null)
        {
        screenSize = tk.getScreenSize();

        if (width > screenSize.width)
        width = screenSize.width;
        xloc = (screenSize.width - width) / 2;

        if (height > screenSize.height)
        height = screenSize.height;
        yloc = (screenSize.height - height) / 2;
        }

        w.reshape(xloc, yloc, width, height);

        if (bSetVisible)
        w.show(true);
    }
   
    // Handles the events of key presses for the textfields and buttons.
    public boolean keyDown(Event event, int key)
    {
        // Sets tab order between fields and buttons.
        if((event.target == userid)&&(key == 9))    //Tab key press
        {
            pass.requestFocus();
        }
        if((event.target== pass)&&(key == 9))   //Tab key press
        {
            submit.requestFocus();
        }
        if((event.target== submit)&&(key == 9))    //Tab key press
        {
            quit.requestFocus();
        }
        if((event.target== quit)&&(key == 9))    //Tab key press
        {
            userid.requestFocus();
        }
        if((event.target== submit)&&(key == '\n'))    //Tab key press
        {
            Submit_Clicked(event);
        }
        if((event.target== quit)&&(key == '\n'))    //Tab key press
        {
            Quit_Clicked(event);
        }
        return false;
    }
   
    void Submit_Clicked(Event event)
    {
        if (userid.getText().length() <= 0 || pass.getText().length() <=0 )
        {
        }
        else
        {
            author = new Author("bgenti", "bgenti", "Bryan", "Gentile", "bgentile@bdsinc.com", "", "",
                              "", "", "", "", "", "", "", "");
                              
              author2 = new Author("kpetti", "kpetti", "Kevin", "Pettine", "kpettine@bdsinc.com", "", "",
                              "", "", "", "", "", "", "", "");
                              
              author3 = new Author("tclot", "tclot", "Tim", "Clotworthy", "tclot@bdsinc.com", "", "",
                              "", "", "", "", "", "", "", "");
                              
          l_userid = userid.getText();
        l_pass = pass.getText();
       
            if (((l_userid.equals(author.UserId) && l_pass.equals(author.Password))) || ((l_userid.equals(author2.UserId) && l_pass.equals(author2.Password)))
                || ((l_userid.equals(author3.UserId) && l_pass.equals(author3.Password))))
            {
                //openURL(FilePath + "BNPFrame.html");
                hide();
            }
            else
            {
                userid.setText("Logon Failed!");
                pass.setText("Try again SUCKER!!!!");
                userid.requestFocus();
            }
        }      
    }
   
    // Clears the textfields when the resetButton is clicked
    void Quit_Clicked(Event event)
    {
        userid.setText("");
        pass.setText("");
        userid.requestFocus();
    }

      public boolean handleEvent(Event event)
      {
          if(event.id == Event.WINDOW_DESTROY) {
              hide();
              return true;
          }
          
          if(event.target == quit && event.id == Event.ACTION_EVENT)
          {
              Quit_Clicked(event);
              return true;
          }
          
          if(event.target == submit && event.id == Event.ACTION_EVENT)
          {
              Submit_Clicked(event);
              return true;
          }
      return super.handleEvent(event);
      }

      //{{DECLARE_CONTROLS
      java.awt.Label label2;
      java.awt.Label label1;
      java.awt.TextField userid;
      java.awt.TextField pass;
      java.awt.Button quit;
      java.awt.Button submit;
      symantec.itools.multimedia.ImageViewer imageViewer1;
      //}}
}

In my applet when I call the dialog I have:

TestDialog dlg = new TestDialog((Frame)c, true, this);

I am having trouble compiling the dialog.  It says that the applet is undefined.  What else do I need to do?
0
Bryan051997Author Commented:
I figured it out.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.