import java.awt.event.ActionListener; import java.io.BufferedReader; import java.io.DataInputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.Reader; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.JOptionPane; import tracert.Tracert; //import java.nio.charset.Charset; import javax.swing.ButtonGroup; import javax.swing.table.DefaultTableModel; import java.awt.event.*; import java.awt.*; import javax.swing.*; /** * * @author USER */ public class window_swing_1 extends javax.swing.JFrame implements ActionListener { /** Creates new form window_swing */ public window_swing_1() { initComponents(); jRadioButton1.setSelected(true); initradiobutton(); } public void initradiobutton(){ buttonGroup.add(jRadioButton1); buttonGroup.add(jRadioButton2); jRadioButton1.addActionListener(this); jRadioButton2.addActionListener(this); } @SuppressWarnings("unchecked") // private void initComponents() { buttonGroup = new javax.swing.ButtonGroup(); jScrollPane1 = new javax.swing.JScrollPane(); jTable1 = new javax.swing.JTable(); jPanel1 = new javax.swing.JPanel(); jTextField1 = new javax.swing.JTextField(); jLabel1 = new javax.swing.JLabel(); jButton1 = new javax.swing.JButton(); jSpinner1 = new javax.swing.JSpinner(); jRadioButton1 = new javax.swing.JRadioButton(); jRadioButton2 = new javax.swing.JRadioButton(); jLabel2 = new javax.swing.JLabel(); jTextField2 = new javax.swing.JTextField(); jLabel3 = new javax.swing.JLabel(); jScrollPane2 = new javax.swing.JScrollPane(); jTextArea1 = new javax.swing.JTextArea(); button_fermer = new javax.swing.JButton(); jButton3 = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setTitle("Trace route"); setBackground(java.awt.Color.lightGray); jTable1.setBorder(javax.swing.BorderFactory.createEtchedBorder()); jTable1.setModel(new javax.swing.table.DefaultTableModel( new Object [][] { {null, null, null, null, null, null, null} }, new String [] { "saut", "min", "moyenne", "max", "noeud", "adresse IP", "taux de perte" } )); jScrollPane1.setViewportView(jTable1); jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder()); jLabel1.setFont(new java.awt.Font("Arial", 0, 12)); jLabel1.setText("Adresse/Domaine:"); jButton1.setBackground(java.awt.Color.lightGray); jButton1.setText("tracert"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } }); jSpinner1.setValue(30); jRadioButton1.setText("résolution d'adresses vers les noms d'hôte"); jRadioButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jRadioButton1ActionPerformed(evt); } }); jRadioButton2.setText("attendre pendant"); jRadioButton2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jRadioButton2ActionPerformed(evt); } }); jLabel2.setText("max des sauts"); jLabel3.setText("(ms)"); javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup() .addGap(19, 19, 19) .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 135, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18) .addComponent(jButton1) .addGap(18, 18, 18) .addComponent(jLabel2) .addGap(16, 16, 16) .addComponent(jSpinner1, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 50, Short.MAX_VALUE) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jRadioButton1) .addGroup(jPanel1Layout.createSequentialGroup() .addComponent(jRadioButton2) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jLabel3))) .addGap(75, 75, 75)) ); jPanel1Layout.setVerticalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addComponent(jRadioButton1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, 35, Short.MAX_VALUE) .addComponent(jRadioButton2) .addComponent(jSpinner1, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)) .addContainerGap()) ); jTextArea1.setColumns(20); jTextArea1.setRows(5); jScrollPane2.setViewportView(jTextArea1); button_fermer.setText("fermer"); button_fermer.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { button_fermerActionPerformed(evt); } }); jButton3.setText("copier"); jButton3.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton3ActionPerformed(evt); } }); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18) .addComponent(button_fermer) .addGap(128, 128, 128)) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addContainerGap(121, Short.MAX_VALUE)))) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(37, 37, 37) .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(30, 30, 30) .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18) .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 184, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(35, 35, 35) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(button_fermer, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)) .addContainerGap(57, Short.MAX_VALUE)) ); pack(); }// private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: if(evt.getSource()==jButton1) { if(jTextField1.getText().compareToIgnoreCase("")!=0){ try { start(jTextField1.getText()); } catch (IOException ex) { Logger.getLogger(window_swing.class.getName()).log(Level.SEVERE, null, ex); } } else { JOptionPane.showMessageDialog(this, "Vous devez taper une adresse ip VALIDE!", "Erreur d'execution", JOptionPane.WARNING_MESSAGE); } } } public void actionPerformed(ActionEvent evt) { if(evt.getSource().equals(jRadioButton1)) { //jButton1ActionPerformed(evt); radiobuttonchoix1(jTextField1.getText()); } else if (evt.getSource().equals(jRadioButton2)) { //jButton1ActionPerformed(evt); radiobuttonchoix2((jTextField1.getText())); } } private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: } private void button_fermerActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: System.exit(0); } private void jRadioButton1ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: choix=true; } private void jRadioButton2ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: choix=false; } public void start(String TextTape) throws IOException{ try{ String cmd = "tracert "+TextTape; Process p = Runtime.getRuntime().exec(cmd); InputStream in = p.getInputStream(); StringBuilder build = new StringBuilder(); Reader reader = new InputStreamReader(in); char[] buffer = new char[512]; int nbRead = reader.read(buffer); while(nbRead > 0) { build.append(buffer, 0, nbRead); nbRead = reader.read(buffer); } String response = build.toString(); jTextArea1.setText("debut de la localisation:"); jTextArea1.setText(response); }catch(Exception e){ jTextArea1.append(e.toString()); } } public void radiobuttonchoix1(String targetIP) { if(choix){ try{ String cmd = "tracert -d "+targetIP; Process p = Runtime.getRuntime().exec(cmd); InputStream in = p.getInputStream(); StringBuilder build = new StringBuilder(); Reader reader = new InputStreamReader(in); char[] buffer = new char[512]; int nbRead = reader.read(buffer); while(nbRead > 0) { build.append(buffer, 0, nbRead); nbRead = reader.read(buffer); } String response = build.toString(); //jTextArea1.setText("debut de la localisation:"); jTextArea1.setText(response); }catch(Exception e){ jTextArea1.append(e.toString()); } } } public void radiobuttonchoix2(String targetIP) { try{ String cmd = "tracert -w 20"+targetIP; Process p = Runtime.getRuntime().exec(cmd); InputStream in = p.getInputStream(); StringBuilder build = new StringBuilder(); Reader reader = new InputStreamReader(in); char[] buffer = new char[512]; int nbRead = reader.read(buffer); while(nbRead > 0) { build.append(buffer, 0, nbRead); nbRead = reader.read(buffer); } String response = build.toString(); //jTextArea1.setText("debut de la localisation:"); jTextArea1.setText(response); }catch(Exception e){ jTextArea1.append(e.toString()); } } /** * @param args the command line arguments */ public static void main(String args[]) { /* Set the Nimbus look and feel */ // /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html */ 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(window_swing.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(window_swing.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(window_swing.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(window_swing.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } // Tracert t=new Tracert(); /* Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new window_swing().setVisible(true); } }); } private boolean choix=true; // Variables declaration - do not modify private javax.swing.ButtonGroup buttonGroup; private javax.swing.JButton button_fermer; private javax.swing.JButton jButton1; private javax.swing.JButton jButton3; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JPanel jPanel1; private javax.swing.JRadioButton jRadioButton1; private javax.swing.JRadioButton jRadioButton2; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JScrollPane jScrollPane2; private javax.swing.JSpinner jSpinner1; private javax.swing.JTable jTable1; private javax.swing.JTextArea jTextArea1; private javax.swing.JTextField jTextField1; private javax.swing.JTextField jTextField2;