1 2 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
| public class FenetreResultat extends JFrame {
//Maxi
int maxi;
int progres;
// Flux
ObjectInputStream in;
ObjectOutputStream out;
//Socket
Socket s;
// PrgressBar
JProgressBar jBar = new JProgressBar();
// Resultat
JLabel result;
//Thread barre
//Thread Threadbarre;
public FenetreResultat() {
// définir un titre
this.setTitle("Resultat");
// définir une taille
this.setSize(200, 280);
// donner un look
setDefaultLookAndFeelDecorated(true);
// définir sa position sur l'écran
this.setLocationRelativeTo(null);
// terminer le processus lorsqu'on clique sur fermer
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setContentPane(buildContentPane());
this.setVisible(true);
// Connection
int port = 18000;
String host = "localhost";
try {
// Coté client : création du socket connection
s = new Socket(host, port);
out = new ObjectOutputStream(s.getOutputStream());
out.flush();
in = new ObjectInputStream(s.getInputStream());
} catch (Exception e) {
System.out.println("Impossble de se connecter au serveur");
e.printStackTrace();
}
//Thread progress bar
Thread threadBarre = new Thread() {
public void run() {
while(progres<maxi)
{
jBar.setValue(progres);
}
}
};
threadBarre.start();
}
private JPanel buildContentPane() {
JPanel panel = new JPanel();
panel.setLayout(new FlowLayout());
panel.setBackground(Color.white);
result = new JLabel("Result not displayed");
result.setForeground(Color.blue);
panel.add(jBar);
panel.add(result);
return panel;
}
public JLabel getResultat() {
return result;
}
public JProgressBar getjBar() {
return jBar;
}
public void setMaxiBarre(int n) {
maxi = n;
jBar.setMinimum(0);
jBar.setMaximum(n);
jBar.setValue(0);
}
} |
Partager