ServerURL question

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
xenia27Asked:
Who is Participating?
 
objectsCommented:
not really, not sure whats causing the flashing.
May be something else in your code.
0
 
xenia27Author Commented:
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
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
objectsCommented:
probably :)

i'd suggest instead using a CardLayout.
0
 
xenia27Author Commented:
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
 
objectsCommented:
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
 
xenia27Author Commented:
mMmm...now I cannot see the pages...@@
cl.show(MainCard, "first") --> means go to FirstPanel, right???
0
 
objectsCommented:
> 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
 
xenia27Author Commented:
I guess I do...
Here is what I do..
getContentPane().add(MainPanel);
getContentPane().add(FirstPanel);
getContentPane().add(SecondPanel);
0
 
objectsCommented:
> getContentPane().add(FirstPanel);
> getContentPane().add(SecondPanel);

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

0
 
rama_krishna580Connect With a Mentor Commented:
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
 
xenia27Author Commented:
>> 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
 
objectsCommented:
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
 
objectsCommented:
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
 
objectsCommented:
MainCard = new JPanel(new CardLayout());
MainCard.add(MainPanel, "main");
MainCard.add(FirstPanel, "first");
MainCard.add(SecondPanel, "second");

getContentPane().add(MainCard);
0
 
xenia27Author Commented:
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
 
objectsCommented:
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
 
xenia27Author Commented:
I do have buttons and some other images in those three panels...
0
 
objectsCommented:
can u post your init() method assuming that is where you setup your applet.
0
 
xenia27Author Commented:
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
 
objectsCommented:
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
 
xenia27Author Commented:
Great!  I finally see what happened....^^...now I'm going to try the real IP.
0
All Courses

From novice to tech pro — start learning today.