1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Development Urgent Java help needed, please!

Discussion in 'Software' started by Theo, 3 May 2004.

  1. Theo

    Theo What's a Dremel?

    Joined:
    12 Jun 2003
    Posts:
    466
    Likes Received:
    0
    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. DeX

    DeX Mube Codder

    Joined:
    22 Jul 2002
    Posts:
    4,152
    Likes Received:
    3
    Are you using Swing or what? Out first lecture on Swing was how to make two buttons that would change the colour and text of a label. To set the text of a label you simply have to use the setText method. However to display the label and a form and everything, you would need to import the swing package and create a JFrame. If you want I can give you the code to the button/label example.
     
  3. Theo

    Theo What's a Dremel?

    Joined:
    12 Jun 2003
    Posts:
    466
    Likes Received:
    0
    The applet basically displays the users network ip address when the applet is opened.. I'm so bad at this :D

    I've never used Swing, but I'd be very grateful to have a look at what you've got, chap. Thank you :>
     
  4. JuMpErFLY

    JuMpErFLY Minimodder

    Joined:
    13 Mar 2003
    Posts:
    882
    Likes Received:
    1
    If I understand what you want to do correctly then it is very simple. Read up on the basics of swing (will take < 30 mins) and just use
    Code:
    getContentPane().add(new JLabel(ip));
    
    to the code in the correct place, obviously you need afew more lines of code.. which you will learn if you read up on swing, I can't be bothered spitting out a load of code, I'm busy ;)
     
  5. Theo

    Theo What's a Dremel?

    Joined:
    12 Jun 2003
    Posts:
    466
    Likes Received:
    0
    Got it sorted without using Swing, thanks anyway chaps, much appreciated :)
     

Share This Page