Laporan Tugas Uts Gui Pemrograman Jaringan: Oleh: Ahmad Habibul Ulum NIM. 1641720144 TI-3E
Laporan Tugas Uts Gui Pemrograman Jaringan: Oleh: Ahmad Habibul Ulum NIM. 1641720144 TI-3E
Laporan Tugas Uts Gui Pemrograman Jaringan: Oleh: Ahmad Habibul Ulum NIM. 1641720144 TI-3E
PEMROGRAMAN JARINGAN
Oleh :
Ahmad Habibul Ulum
NIM. 1641720144
TI-3E
2. Source Code
import java.net.*;
/**
* @author gemsc
*/
public class Tugas1GUI extends javax.swing.JFrame {
public Tugas1GUI() {
initComponents();
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBord
er(), "Your PC"));
txt_pcIp.setText("unidentified");
jButton1.setText("Refresh");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jLabel1.setText("Domain :");
btn_domain.setText("Check");
btn_domain.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btn_domainActionPerformed(evt);
}
});
txt_domain.setIconTextGap(1);
jLabel3.setText("IP :");
btn_classIp.setText("Check");
btn_classIp.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btn_classIpActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(10, 10, 10)
.addComponent(txt_domain, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addGap(59, 59, 59)
.addComponent(txt_classIp)
.addGap(0, 0, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel3)
.addGap(18, 18, Short.MAX_VALUE)
.addComponent(editText_classIp, javax.swing.GroupLayout.PREFERRED_SIZE, 134,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btn_classIp))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(edit_txt_domain)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btn_domain)))
.addContainerGap())
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jLabel2)
.addGap(116, 116, 116))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGap(19, 19, 19)
.addComponent(jLabel2)
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(edit_txt_domain, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) );
pack();
}// </editor-fold>
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
try {
InetAddress addr = InetAddress.getLocalHost();
if(addr != null){
txt_pcIp.setText(addr.getHostAddress() + "/" + addr.getHostName());
}
} catch (UnknownHostException e) {
txt_pcIp.setText(e.getMessage());
}
}
private void btn_classIpActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String alamatIP = editText_classIp.getText();
int ip=alamatIP.indexOf(".");
String d = alamatIP.substring(0,ip);
String getIP;
getIP = edit_txt_domain.getText();
try {
InetAddress address = InetAddress.getByName(getIP);
txt_domain.setText("get ip from " + address.getHostName()+ " " + address.getHostAddress());
} catch (Exception e) {
txt_domain.setText("check the domain name");
}
}
public static void main(String args[]) {
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(Tugas1GUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Tugas1GUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Tugas1GUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Tugas1GUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
}
}); }
// Variables declaration - do not modify
private javax.swing.JButton btn_classIp;
private javax.swing.JButton btn_domain;
private javax.swing.JTextField editText_classIp;
private javax.swing.JTextField edit_txt_domain;
private javax.swing.JButton jButton1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JPanel jPanel1;
private javax.swing.JLabel txt_classIp;
private javax.swing.JLabel txt_domain;
private javax.swing.JLabel txt_pcIp;
// End of variables declaration
3. Testing Aplikasi