Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

ServerURL question

Posted on 2004-04-25
22
Medium Priority
?
243 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
[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
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 92

Accepted Solution

by:
objects earned 1600 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 400 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
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…
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 …
Suggested Courses

704 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