0% found this document useful (0 votes)
4 views2 pages

JPRPRJCT

The document is a Java program that creates a graphical user interface (GUI) for an IP Finder tool. Users can enter a domain name to retrieve its IP address, clear the input, or copy the IP address to the clipboard. The program includes error handling for invalid domain names and updates the GUI components accordingly.

Uploaded by

victimnil12
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

JPRPRJCT

The document is a Java program that creates a graphical user interface (GUI) for an IP Finder tool. Users can enter a domain name to retrieve its IP address, clear the input, or copy the IP address to the clipboard. The program includes error handling for invalid domain names and updates the GUI components accordingly.

Uploaded by

victimnil12
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

import java.awt.

*;
import java.awt.event.*;
import javax.swing.*;
import java.net.*;

public class IPFinder extends JFrame implements ActionListener {


JTextField textField;
JLabel heading, label;
JButton findButton, clearButton, copyButton;
JTextArea resultArea;

IPFinder() {

super("IP Finder - Java GUI");


setSize(500, 300);
setLayout(null);
getContentPane().setBackground(new Color(34, 40, 49));

heading = new JLabel("IP Finder Tool");


heading.setBounds(150, 20, 300, 30);
heading.setForeground(Color.CYAN);
heading.setFont(new Font("Arial", Font.BOLD, 24));

label = new JLabel("Enter Domain Name:");


label.setBounds(50, 70, 200, 20);
label.setForeground(Color.WHITE);

textField = new JTextField();


textField.setBounds(200, 70, 200, 25);
textField.setBackground(new Color(57, 62, 70));
textField.setForeground(Color.WHITE);
textField.setCaretColor(Color.CYAN);

findButton = new JButton("Find IP");


findButton.setBounds(200, 110, 100, 30);
findButton.setBackground(new Color(0, 173, 181));
findButton.setForeground(Color.WHITE);

clearButton = new JButton("Clear");


clearButton.setBounds(310, 110, 90, 30);
clearButton.setBackground(new Color(240, 84, 84));
clearButton.setForeground(Color.WHITE);

copyButton = new JButton("Copy IP");


copyButton.setBounds(310, 200, 90, 30);
copyButton.setBackground(new Color(45, 181, 94));
copyButton.setForeground(Color.WHITE);
copyButton.setEnabled(false);

resultArea = new JTextArea();


resultArea.setBounds(50, 160, 350, 30);
resultArea.setBackground(new Color(57, 62, 70));
resultArea.setForeground(Color.WHITE);
resultArea.setEditable(false);
findButton.addActionListener(this);
clearButton.addActionListener(this);
copyButton.addActionListener(this);

add(heading);
add(label);
add(textField);
add(findButton);
add(clearButton);
add(copyButton);
add(resultArea);

setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);
}

public void actionPerformed(ActionEvent e) {


if (e.getSource() == findButton) {
try {
String domain = textField.getText();
InetAddress ip = InetAddress.getByName(domain);
resultArea.setText("IP Address: " + ip.getHostAddress());
copyButton.setEnabled(true);
} catch (Exception ex) {
resultArea.setText("Invalid Domain Name!");
copyButton.setEnabled(false);
}
} else if (e.getSource() == clearButton) {
textField.setText("");
resultArea.setText("");
copyButton.setEnabled(false);
} else if (e.getSource() == copyButton) {
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new
java.awt.datatransfer.StringSelection(resultArea.getText()), null);
JOptionPane.showMessageDialog(this, "IP Copied to Clipboard!");
}
}

public static void main(String[] args) {


new IPFinder();
}
}

You might also like