Solved

Opening up a URL page from a Java Dialog

Posted on 1997-07-11
4
287 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
  • 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

ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
stackato and cloud 4 87
reverse digits of a number using for loop 5 46
hibernate example issues from command prompt 10 42
CSV file parsing thru Java 13 31
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
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 learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

825 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