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
| package rmi;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.math.BigDecimal;
import java.util.Date;
import javax.swing.*;
public class UserInterfaceResultat {
Date fin;
public UserInterfaceResultat(BigDecimal result, int nbClients, Date tps_iniServeur, Date tps_iniPremierClient, Long tps_totalCalculClients){
// 1. Mise en forme du Temps de calcul
fin = new Date();
String tps_serveur = calculTemps(tps_iniServeur);
String tps_premierClient = calculTemps(tps_iniPremierClient);
String tps_calculClients = calculTemps(tps_totalCalculClients);
// conteneur
JFrame frame = new JFrame();
Container panel = frame.getContentPane();
JPanel pane = new JPanel();
panel.add(new JScrollPane(pane));
// contenant : label/bouttons
JLabel label_1 = new JLabel(" PI = " + result);
JLabel label_2 = new JLabel(" Temps total depuis la création du serveur = "+tps_serveur);
JLabel label_3 = new JLabel(" Temps total depuis la connexion du premier client = "+tps_premierClient);
JLabel label_4 = new JLabel(" Temps de calcul des clients (cumulés)(tps que côté client)(significatif que s'il n'y a qu'un client de lancé sur une machine car sinon les threads attendent les autres thread et ce temps est pris en compte dans le temps de calcul) = ");
JLabel label_5 = new JLabel(tps_calculClients);
JLabel label_6 = new JLabel(" Nombre de client connecté avant la fin du calcul = " + nbClients);
JButton quitter = new JButton("Quitter");
pane.add(label_1);
pane.add(label_2);
pane.add(label_3);
pane.add(label_4);
pane.add(label_5);
pane.add(label_6);
pane.add(quitter);
// Gestion des événements
ActionListener listener_1 = new ActionListener(){
public void actionPerformed(ActionEvent event) {
System.exit(0);
}};
quitter.addActionListener(listener_1);
// Affichage de la fenêtre
pane.setLayout(new GridLayout(7,1));
frame.setTitle ("SERVEUR : Résultat du calcul de PI ");
frame.setSize (1000, 200);
frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
frame.setVisible (true);
}
private String calculTemps(Date deb) {
Long temps = fin.getTime()-deb.getTime();
Long ms = temps % 1000;
Long sTotal = temps / 1000;
Long min = sTotal / 60;
Long s = sTotal % 60;
return " " + min + "min " + s + "s " + ms + "ms";
}
private String calculTemps(Long temps) {
Long ms = temps % 1000;
Long sTotal = temps / 1000;
Long min = sTotal / 60;
Long s = sTotal % 60;
return " " + min + "min " + s + "s " + ms + "ms";
}
} |
Partager