Solved

ServerURL question

Posted on 2004-04-25
22
229 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
Comment Utility
not really, not sure whats causing the flashing.
May be something else in your code.
0
 

Author Comment

by:xenia27
Comment Utility
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
Comment Utility
probably :)

i'd suggest instead using a CardLayout.
0
 
LVL 92

Accepted Solution

by:
objects earned 400 total points
Comment Utility
0
 

Author Comment

by:xenia27
Comment Utility
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
Comment Utility
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
Comment Utility
mMmm...now I cannot see the pages...@@
cl.show(MainCard, "first") --> means go to FirstPanel, right???
0
 
LVL 92

Expert Comment

by:objects
Comment Utility
> 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
Comment Utility
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
Comment Utility
> 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
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:xenia27
Comment Utility
>> 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
I do have buttons and some other images in those three panels...
0
 
LVL 92

Expert Comment

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

Author Comment

by:xenia27
Comment Utility
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
Comment Utility
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
Comment Utility
Great!  I finally see what happened....^^...now I'm going to try the real IP.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
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 “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

728 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

9 Experts available now in Live!

Get 1:1 Help Now