Results 1 to 7 of 7

Thread: Urgent Java help needed, please!

  1. #1
    Kirstie Allsopp Theo's Avatar
    Join Date
    Jul 2003
    Location
    Sunny Bolton
    Posts
    2,777
    Thanks
    17
    Thanked
    23 times in 20 posts
    • Theo's system
      • Motherboard:
      • Asus P5B Wifi deluxe
      • CPU:
      • E6600 @ 3150Mhz
      • Memory:
      • 2x2GB OCZ 6400
      • Storage:
      • 1x80GB Maxtor
      • Graphics card(s):
      • 640MB 8800GT
      • Monitor(s):
      • ASUS M221u
      • Internet:
      • Be Value

    Urgent Java help needed, please!

    Urgent!
    Help!

    As part of an old assignment, I was told to discuss two uses for a layout of buttons/text areas/labels. Being the smart-arse that I am, I decided to go a little more advanced, and show off my technical know-how. I discussed a parallel LCD configuration device, and a network monitoring tool.

    Oh guess what! The next assignment is - program one of your ideas.

    I've been doing java for about a month now (2x1 hour lectures a week + basic fumbling around with JCreator). That's seriously not enough to be able to get this assignment finished for tomorrow. So I'm begging for a little help, here - just a pointer in the right direction would be massively appreciated.


    I have this:

    Code:
    import java.awt.*;
    import java.awt.event.*;
    import java.applet.*;
    import java.net.*;
    import java.io.*;
    
    public class MyIP {
      public static void main(String args[]) {
        String ip = new MyIP().myIP();
        System.out.println(ip);
      }
    
      public String myIP() {
        try {
          return InetAddress.getLocalHost().getHostAddress();
        } 
        catch (IOException e) {
          return "unknown";
        }
      }
    }
    What I need it to do, however, is to print the IP on a Label... I really have no idea how to incorporate the above into my code. Gah!

  2. #2
    Goat Boy
    Join Date
    Jul 2003
    Location
    Alexandra Park, London
    Posts
    2,428
    Thanks
    0
    Thanked
    0 times in 0 posts
    This not help?

    http://java.sun.com/docs/books/tutor...nts/label.html

    What sort of app is it? Application? Applet? Why not get a web server to print out the IP?
    "All our beliefs are being challenged now, and rightfully so, they're stupid." - Bill Hicks

  3. #3
    Kirstie Allsopp Theo's Avatar
    Join Date
    Jul 2003
    Location
    Sunny Bolton
    Posts
    2,777
    Thanks
    17
    Thanked
    23 times in 20 posts
    • Theo's system
      • Motherboard:
      • Asus P5B Wifi deluxe
      • CPU:
      • E6600 @ 3150Mhz
      • Memory:
      • 2x2GB OCZ 6400
      • Storage:
      • 1x80GB Maxtor
      • Graphics card(s):
      • 640MB 8800GT
      • Monitor(s):
      • ASUS M221u
      • Internet:
      • Be Value
    It's an Applet, chap.

    Basically, the user opens the applet on their machine and they're presented with their ip address in label form.

    Code:
    import java.awt.*;
    import java.applet.*;
    import java.net.*;
    import java.io.*;
    
    public class MyIP extends Applet {
      static String ip;
      Label l1;
      public static void main(String args[]) {
        ip = new MyIP().myIP();
        System.out.println(ip);
      }
    
      public String myIP() {
        try {
          return InetAddress.getLocalHost().getHostAddress();
        } 
        catch (IOException e) {
          return "unknown";
        }
      }
      public void init() {
      	l1 = new Label();
      	add (l1);
      	l1.setText(ip);
      }
    }
    I've tried that - it compiles, but nothing is displayed in the applet.

  4. #4
    Smoke Me A Kipper! Slick's Avatar
    Join Date
    Jul 2003
    Location
    Edinburgh
    Posts
    1,064
    Thanks
    2
    Thanked
    0 times in 0 posts
    whats with the
    ip = new MyIP().myIP();

    shouldn't it just be something like
    String ip = new String(myIP());

    and why have you made ip static?
    Last edited by Slick; 03-05-2004 at 10:23 PM.

  5. #5
    DsW
    DsW is offline
    Senior Member
    Join Date
    Aug 2003
    Location
    Glasgow
    Posts
    292
    Thanks
    0
    Thanked
    0 times in 0 posts
    Quote Originally Posted by Theo
    Basically, the user opens the applet on their machine and they're presented with their ip address in label form.

    Ok - Applets do not need a main() method. The init() method is run on an applet on its first invocation - you can do the label setup here.
    Keep it simple.

    Basically, all you need to do is implement an init() method that

    1. creates a label
    2. set the label text to that of the IP address
    3. add the label

    Thats it.

    e.g.

    Code:
    	public void init()
    	{
    		JLabel label = new JLabel();
    		
    		try {
    			  label.setText(InetAddress.getLocalHost().getHostAddress());
    			} 
    			catch (IOException e) {
    			}
    			
    		add(label);
    	}

    cheers,
    dave

  6. #6
    Kirstie Allsopp Theo's Avatar
    Join Date
    Jul 2003
    Location
    Sunny Bolton
    Posts
    2,777
    Thanks
    17
    Thanked
    23 times in 20 posts
    • Theo's system
      • Motherboard:
      • Asus P5B Wifi deluxe
      • CPU:
      • E6600 @ 3150Mhz
      • Memory:
      • 2x2GB OCZ 6400
      • Storage:
      • 1x80GB Maxtor
      • Graphics card(s):
      • 640MB 8800GT
      • Monitor(s):
      • ASUS M221u
      • Internet:
      • Be Value
    Quote Originally Posted by Slick
    whats with the
    ip = new MyIP().myIP();

    shouldn't it just be something like
    String ip = new String(myIP());

    and why have you made ip static?
    Because I'm a newbie who knows not what he's doing

    wilkied, you've saved my life. Thanks chap... all I've got to do now is event handlers for 6 buttons, 3 text areas, and 2 checkboxes :|

  7. #7
    Kirstie Allsopp Theo's Avatar
    Join Date
    Jul 2003
    Location
    Sunny Bolton
    Posts
    2,777
    Thanks
    17
    Thanked
    23 times in 20 posts
    • Theo's system
      • Motherboard:
      • Asus P5B Wifi deluxe
      • CPU:
      • E6600 @ 3150Mhz
      • Memory:
      • 2x2GB OCZ 6400
      • Storage:
      • 1x80GB Maxtor
      • Graphics card(s):
      • 640MB 8800GT
      • Monitor(s):
      • ASUS M221u
      • Internet:
      • Be Value
    I'd just like to say thanks to all of you, actually - for reading and pointing me in the general direction. Much appreciated.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Urgent Help Needed Guys
    By Howard in forum PC Hardware and Components
    Replies: 20
    Last Post: 29-02-2004, 08:57 PM
  2. urgent help needed. who's knows the K7N2 mobo??
    By silent in forum PC Hardware and Components
    Replies: 11
    Last Post: 19-12-2003, 08:49 PM
  3. URGENT help needed please guys!
    By steve threlfall in forum Software
    Replies: 9
    Last Post: 15-10-2003, 01:54 PM
  4. Radeon 8500 linux driver install problems
    By Dorza in forum Software
    Replies: 0
    Last Post: 22-09-2003, 12:00 PM
  5. URGENT help needed
    By Howard in forum General Discussion
    Replies: 5
    Last Post: 18-08-2003, 09:50 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •