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!
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.
The applet basically displays the users network ip address when the applet is opened.. I'm so bad at this I've never used Swing, but I'd be very grateful to have a look at what you've got, chap. Thank you :>
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