Solved

ServerURL question

Posted on 2004-04-25
22
234 Views
Last Modified: 2010-03-31
Hi,

I have this problem....When I try to enter a LAN IP address and it can run and work perfectly...but when I use a real IP address, it took so long to connect, which is expected, and the web page was kinda flashing...which is NOT expected.  This is my codes:
        ServerURL = getDocumentBase();
        ServAddr = new String(ServerURL.getHost());
        Socket ServSk = new Socket(ServAddr, ConPort);

Is there anything I need to be careful about when I try to connect to an IP address???



Xenia
0
Comment
Question by:xenia27
  • 12
  • 9
22 Comments
 
LVL 92

Expert Comment

by:objects
ID: 10914823
not really, not sure whats causing the flashing.
May be something else in your code.
0
 

Author Comment

by:xenia27
ID: 10914832
I got three pages...MainPanel, FirstPanel, and SecondPanel...when I try to switch to Page 1...I do this...

MainPanel.setVisible(false);
FirstPanel.setVisible(true);
SecondPanel.setVisible(false);

Will this cause the flashing problem???
0
 
LVL 92

Expert Comment

by:objects
ID: 10914842
probably :)

i'd suggest instead using a CardLayout.
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 92

Accepted Solution

by:
objects earned 400 total points
ID: 10914845
0
 

Author Comment

by:xenia27
ID: 10914866
So I should use CardLayout.  Then this is what I will do...

JPanel MainCard = new JPanel(new CardLayout());
MainCard.add(MainPanel);
MainCard.add(FirstPanel);
MainCard.add(SecondPanel);


And how can I switch pages???
0
 
LVL 92

Expert Comment

by:objects
ID: 10914878
JPanel MainCard = new JPanel(new CardLayout());
MainCard.add(MainPanel, "main");
MainCard.add(FirstPanel, "first");
MainCard.add(SecondPanel, "second");


> And how can I switch pages???

CardLayout cl = (CardLayout) MainCard.getLayout();
cl.show(MainCard, "first");
0
 

Author Comment

by:xenia27
ID: 10914909
mMmm...now I cannot see the pages...@@
cl.show(MainCard, "first") --> means go to FirstPanel, right???
0
 
LVL 92

Expert Comment

by:objects
ID: 10914919
> now I cannot see the pages...@@

problem may be elsewhere
do u add MainPanel to your applet

> cl.show(MainCard, "first") --> means go to FirstPanel, right???

yes
0
 

Author Comment

by:xenia27
ID: 10914932
I guess I do...
Here is what I do..
getContentPane().add(MainPanel);
getContentPane().add(FirstPanel);
getContentPane().add(SecondPanel);
0
 
LVL 92

Expert Comment

by:objects
ID: 10914938
> getContentPane().add(FirstPanel);
> getContentPane().add(SecondPanel);

remove those two lines, those panels are added to MainPanel.

0
 
LVL 23

Assisted Solution

by:rama_krishna580
rama_krishna580 earned 100 total points
ID: 10914940
try this code..

import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.net.*;


/**
 * Nog is an applet that is the entry point for NOG'2000.
 *
 * @author Raimo Niskanen (e95_ran@e.kth.se)
 * @version 1.2, 03/23/1999
 */
public class Nog extends Applet implements ActionListener {

    private Button     button;
    private Label      label;
    private CardLayout cardLayout;
    private Container  thisContainer;
    private Frame      nogFrame;

    /**
     * Version and copywright info.
     *
     * @author Raimo Niskanen (e95_ran@e.kth.se)
     *
     * @return version and copywright info
     */
    public String getAppletInfo () {
      return "Nog v1.2 (c) Raimo Niskanen";
    }

    /**
     * Creates the AWT components in this applet.
     *
     * @author Raimo Niskanen (e95_ran@e.kth.se)
     */
    public void init () {
      System.out.println ("Server URL: " + getCodeBase ());
      if (button == null) {
          button = new Button ("Enter NOG'2000");
          button.setActionCommand ("Enter");
          button.addActionListener (this);
          label = new Label ("NOG'2000 running", Label.CENTER);
          cardLayout = new CardLayout ();
          thisContainer = this;
          setLayout (cardLayout);
          add ("button", button);
          add ("label", label);
      }
      cardLayout.show (thisContainer, "button");
      doLayout ();
    }

    /**
     * Destroys the AWT components in this applet.
     *
     * @author Raimo Niskanen (e95_ran@e.kth.se)
     */
    public void destroy () {
      if (button != null) {
          button     = null;
          label      = null;
          cardLayout = null;
      }
      if (nogFrame != null) {
          nogFrame.dispose ();
          nogFrame = null;
      }
    }

    /**
     * Receives an <code>ActionEvent </code> from the button
     * on this applet. Launches a <code>Client </code>, and
     * replaces the button with a label indicating that the
     * applet is busy. When the <code>Client </code> window is
     * closed, the button is shown again.
     *
     * @author Raimo Niskanen (e95_ran@e.kth.se)
     *
     * @see Client
     */
    public void actionPerformed (ActionEvent e) {
      if (e.getID () == ActionEvent.ACTION_PERFORMED) {
          if (e.getActionCommand () == "Enter") {
            if (nogFrame == null) {
                nogFrame = new Client (getCodeBase ());
                nogFrame.addWindowListener
                  (new WindowAdapter () {
                      public void windowClosed (WindowEvent e) {
                        nogFrame = null;
                        if (button != null)
                            cardLayout.show (thisContainer,
                                         "button");
                      }
                  });
            }
            cardLayout.show (thisContainer, "label");
          }
      }
    }

    /**
     * This main method launches a <code>Client </code> without
     * bothering about any applet.
     *
     * @author Raimo Niskanen (e95_ran@e.kth.se)
     *
     * @param args an array of strings, one string for each parameter. <BR>
     *        arg[0]: the URL of the server
     *
     * @see nog.Client
     */
    public static void main (String args[]) {
      URL    serverURL = null;
      Frame  frame;
      final Thread thread = Thread.currentThread ();

      try {
          serverURL = new URL (args[0]);
          serverURL = new URL ("http",
                         serverURL.getHost (),
                         serverURL.getPort (),
                         "/");
      }
      catch (MalformedURLException e) {
          System.err.println ("arg[0]: " + e);
          System.exit (1);
      }
      catch (ArrayIndexOutOfBoundsException e) {
          System.err.println ("arg[0] is missing");
          System.exit (1);
      }
      System.out.println ("Using server " + serverURL);
      frame = new Client (serverURL);

      frame.addWindowListener
          (new WindowAdapter () {
            public void windowClosed (WindowEvent e) {
                thread.interrupt ();}
          });
      try {
          thread.join ();
      } catch (InterruptedException e) {
      } finally {
          System.exit (0);
      }
    } // void main ()


} // class Nog


best of luck..

R.K
0
 

Author Comment

by:xenia27
ID: 10914961
>> getContentPane().add(FirstPanel);
>> getContentPane().add(SecondPanel);

>remove those two lines, those panels are added to MainPanel.  
 Why those panels are added to MainPanel???  Confused...@@
0
 
LVL 92

Expert Comment

by:objects
ID: 10914988
Actually all three of those lines should be removed. You have added those panels to MainCard.
You need to add MainCard to your content pane.
0
 
LVL 92

Expert Comment

by:objects
ID: 10914990
a component can only be added to one container, if you add it to another then it is removed from whatever it has already been added to.
0
 
LVL 92

Expert Comment

by:objects
ID: 10915030
MainCard = new JPanel(new CardLayout());
MainCard.add(MainPanel, "main");
MainCard.add(FirstPanel, "first");
MainCard.add(SecondPanel, "second");

getContentPane().add(MainCard);
0
 

Author Comment

by:xenia27
ID: 10915041
OK...this is what I do now...

JPanel MainCard = new JPanel(new CardLayout());
JPanel MainPanel = new JPanel();
JPanel FirstPanel = new JPanel();
JPanel SecondPanel = new JPanel();

MainCard.add(MainPanel, "main");
MainCard.add(FirstPanel, "first");
MainCard.add(SecondPanel, "second");

getContentPane().add(MainCard);

CardLayout cl = (CardLayout) MainCard.getLayout();

Still I cannot see the pages...@@...Any idea?
0
 
LVL 92

Expert Comment

by:objects
ID: 10915066
what pages do you expect to see. do u add other content to those three panels?
sorry its a bit hard to help when only seeing snippets of your code.
0
 

Author Comment

by:xenia27
ID: 10915073
I do have buttons and some other images in those three panels...
0
 
LVL 92

Expert Comment

by:objects
ID: 10915080
can u post your init() method assuming that is where you setup your applet.
0
 

Author Comment

by:xenia27
ID: 10915101
public void init()
 {
    ImageIcon   bg1Icon;
    Dimension   d = getSize();

    MainPanel = new JPanel();
    Page1Panel = new JPanel();
    Page2Panel = new JPanel();

    SetCurrentPage(0);
    setSize(775,450);
      
    blackline = BorderFactory.createLineBorder(Color.black);
    raisedetched = BorderFactory.createEtchedBorder(Color.white, Color.white);
    loweredetched = BorderFactory.createEtchedBorder(Color.white, Color.white);
    raisedbevel = BorderFactory.createRaisedBevelBorder();
    loweredbevel = BorderFactory.createLoweredBevelBorder();
    empty = BorderFactory.createEmptyBorder();
      
    getContentPane().setLayout(null);
   
    LoadImage();
    bg1 = getImage(getDocumentBase(), "Image/base00.gif");
    bg1Icon = new ImageIcon(bg1);
    MainPanel.setIcon(bg1Icon);

     // here I init all the variables
   
    try
    {
        ServerURL = getDocumentBase();
        ServAddr = new String(ServerURL.getHost());
        GetDataThread = new GetData(ServAddr, 10, this);
    }
    catch(Exception e)
    {
    }
   
    MainPanel.setBounds(0,0,d.width,d.height);
    Page1Panel.setBounds(0,0,d.width,d.height);
    Page2Panel.setBounds(0, 0, d.width, d.height);

    MainCard.add(MainPanel, "main");
    MainCard.add(Page1Panel, "Page1");
    MainCard.add(Page2Panel, "Page2");

    MCards = (CardLayout)MainCard.getLayout();
   
    getContentPane().add(MainCard);
   
    MCards.show(MainCard, "main");
 }
0
 
LVL 92

Expert Comment

by:objects
ID: 10915111
you never set the size of MainCard.

>    MainPanel.setBounds(0,0,d.width,d.height);
>    Page1Panel.setBounds(0,0,d.width,d.height);
>    Page2Panel.setBounds(0, 0, d.width, d.height);

these lines have no effect as you are using a layout manager.
0
 

Author Comment

by:xenia27
ID: 10915127
Great!  I finally see what happened....^^...now I'm going to try the real IP.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
servlet doXXX methods 3 62
why cannot we forward request once the response is committed 2 46
oracle 11g 23 107
javap not working 8 59
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

828 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