| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 
 |  
 
   1.
      package projet1;
   2.
 
   3.
      import java.awt.BorderLayout;
   4.
      import java.awt.Color;
   5.
      import java.awt.Container;
   6.
      import java.awt.event.ActionEvent;
   7.
      import java.awt.event.ActionListener;
   8.
      import java.io.IOException;
   9.
      import java.io.RandomAccessFile;
  10.
 
  11.
      import javax.swing.BorderFactory;
  12.
      import javax.swing.Box;
  13.
      import javax.swing.JButton;
  14.
      import javax.swing.JFrame;
  15.
      import javax.swing.JPanel;
  16.
      import javax.swing.JTextArea;
  17.
      import javax.swing.border.BevelBorder;
  18.
      import javax.swing.border.CompoundBorder;
  19.
      import javax.swing.border.EtchedBorder;
  20.
      import javax.swing.border.TitledBorder;
  21.
 
  22.
      public class Affichage extends JFrame {
  23.     
  24.
          static JFrame mainFrame = new JFrame("Réccupération de données" );
  25.
          JTextArea textField = new JTextArea();
  26.
          String myFile = "hostname.txt";
  27.
          String fichierContenu= "";
  28.     
  29.
          public Affichage() {
  30.         
  31.
              mainFrame.setSize(800, 600);
  32.         
  33.
              //centerPanel
  34.
              Box left = Box.createVerticalBox();
  35.
              JPanel leftPanel = new JPanel(new BorderLayout());
  36.
              leftPanel.setBorder(new TitledBorder(
  37.
                                          new EtchedBorder(),
  38.
                                          "SNEC-IN" ));
  39.
              leftPanel.setBackground(Color.YELLOW);
  40.
              leftPanel.add(left, BorderLayout.CENTER);
  41.
              textField.setBackground(Color.YELLOW);
  42.
              leftPanel.add(textField);
  43.         
  44.
              //Mise en forme des cadres
  45.
              Box top = Box.createHorizontalBox();
  46.
              top.add(leftPanel);
  47.         
  48.
              JPanel headerPanel = new JPanel();
  49.
              headerPanel.setBackground(Color.WHITE);
  50.         
  51.
              Container content = mainFrame.getContentPane();
  52.
              content.setLayout(new BorderLayout());
  53.
              content.add(headerPanel, BorderLayout.NORTH);
  54.
              content.add(top, BorderLayout.CENTER);
  55.         
  56.
              try    {
  57.
                  RandomAccessFile raf = new RandomAccessFile(myFile, "r" );
  58.
                  String line;
  59.
                  while ( (line = raf.readLine()) != null )    {
  60.
                      fichierContenu += line;
  61.
                  }
  62.
                  textField.setText(fichierContenu);
  63.
              }
  64.
              catch (IOException e)    {
  65.
                  System.out.println("erreur dans: " + e);
  66.
              }
  67.         
  68.
              mainFrame.setVisible(true);
  69.
          }
  70.
      } | 
Partager