Solved

Opening up a URL page from a Java Dialog

Posted on 1997-07-11
4
302 Views
Last Modified: 2010-05-18
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.
0
Comment
Question by:Bryan051997
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 1

Accepted Solution

by:
vmanocha earned 50 total points
ID: 1222953
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
 

Author Comment

by:Bryan051997
ID: 1222954
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
 
LVL 1

Expert Comment

by:vmanocha
ID: 1222955
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
 

Author Comment

by:Bryan051997
ID: 1222956
I figured it out.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

733 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