Sunday, April 14, 2024
HomeSoftware EngineeringHow one can Create a Java GUI App that exhibits the Logged-in...

How one can Create a Java GUI App that exhibits the Logged-in Person and Hostname


Create a brand new file known as Utility.java and paste the next:

import javax.swing.*;
import java.internet.InetAddress;
import java.internet.UnknownHostException;

public class Utility {
    public static void predominant(String...args) throws UnknownHostException {
        JFrame body = new JFrame("Pattern App");
        body.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        body.setSize(300,300);

        String person = System.getProperty("person.title");
        String host = InetAddress.getLocalHost().getHostName();

        JTextArea txt = new JTextArea();
        txt.setText(
                "n" +
                "  Person: "+person+"n" +
                "  Host: "+host+"n"
        );
        body.getContentPane().add(txt);

        body.setVisible(true);
    }
}

Now open the terminal/command-line and kind:

java Utility.java

It will present a GUI utility that can have a textarea with two traces of textual content:

  1. Your logged-in username
  2. The machine’s hostname
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments