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 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 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
| public class Accueil extends javax.swing.JFrame implements Runnable {
public String tutu;
public String NewsMsg;
Thread t;
BufferedReader _monbuf;
int ClinetPortNumber;
JLabel lbli = new JLabel();
//String[] toto = new String[WIDTH];
/**
* Creates new form Accueil
*/
public Accueil() {
this.add(lbli);
initComponents();
}
@SuppressWarnings("unchecked")
private void exitMenuItemActionPerformed(java.awt.event.ActionEvent evt) {
System.exit(0);
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Accueil().setVisible(true);
updateBouton();
}
});
}
public void ecrire(String txt){
jTextArea1.setText(txt);
}
public static void updateBouton(){
//On crée un Worker générique, cette fois
SwingWorker sw = new SwingWorker<String, String>(){
protected String doInBackground() throws Exception {
String nees = null;
Accueil _accueil = new Accueil();
while(true)
{
String NewsMsg = null;
try
{
_accueil.jTextArea1.setText(nees);
try (DatagramSocket ClientSoc = new DatagramSocket(6020)) {
byte Receivebuff[]=new byte[1024];
DatagramPacket dp=new DatagramPacket(Receivebuff,Receivebuff.length);
ClientSoc.receive(dp);
NewsMsg = new String(dp.getData(),0,dp.getLength());
BufferedReader entree = new BufferedReader(new StringReader(NewsMsg));
ClientSoc.close();
Thread.sleep(50);
if (NewsMsg.charAt(0) == "!".charAt(0)){
Scanner sc = new Scanner(NewsMsg);
sc.findInLine("!AIVDM,1,1,,A,(.*),\\d\\*\\w{2}");
MatchResult result = sc.match();
sc.close();
String msg = result.group(1);
// System.out.print(msg);
if (MessageAIS.getMsgType(msg) == 1){
MessagePOS ms= new MessagePOS(msg);
nees = ms.toString();
}
else if (MessageAIS.getMsgType(msg) == 5){
MessageSTATIC ms= new MessageSTATIC(msg);
//System.out.println(ms);
nees = ms.toString();
}
}
}
}
catch(Exception ex)
{
ex.printStackTrace();
}
return nees;
}
}
public void done(){
Accueil _accueil = new Accueil();
if(SwingUtilities.isEventDispatchThread())
// System.out.println("Dans l'EDT ! ");
try {
_accueil.lbli.setText(get());
// _accueil.jTextArea1.setText(_accueil.tutu);
} catch (InterruptedException ex) {
Logger.getLogger(Accueil.class.getName()).log(Level.SEVERE, null, ex);
} catch (ExecutionException ex) {
Logger.getLogger(Accueil.class.getName()).log(Level.SEVERE, null, ex);
}
try {
_accueil.ecrire(get());
System.out.print(get());
updateBouton();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
}
//La méthode gérant les résultats intermédiaires
public void process(List<String> list){
for(String str : list)
System.out.println("je suis ici : process");
}
};
//On écoute le changement de valeur pour la propriété
sw.addPropertyChangeListener(new PropertyChangeListener(){
//Méthode de l'interface
public void propertyChange(PropertyChangeEvent event) {
//On vérifie tout de même le nom de la propriété
if("progress".equals(event.getPropertyName())){
if(SwingUtilities.isEventDispatchThread())
System.out.println("Je suis ici : propertyChange");
}
}
});
//On lance le SwingWorker
sw.execute();
}
// Variables declaration - do not modify
private javax.swing.JMenuItem aboutMenuItem;
private javax.swing.JMenuItem contentsMenuItem;
private javax.swing.JMenuItem copyMenuItem;
private javax.swing.JMenuItem cutMenuItem;
private javax.swing.JMenuItem deleteMenuItem;
private javax.swing.JMenu editMenu;
private javax.swing.JMenuItem exitMenuItem;
private javax.swing.JMenu fileMenu;
private javax.swing.JMenu helpMenu;
private javax.swing.JButton jButton1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTextArea jTextArea1;
private eu.hansolo.steelseries.extras.Led led1;
private javax.swing.JMenuBar menuBar;
private javax.swing.JMenuItem openMenuItem;
private javax.swing.JMenuItem pasteMenuItem;
private javax.swing.JMenuItem saveAsMenuItem;
private javax.swing.JMenuItem saveMenuItem;
// End of variables declaration
@Override
public void run() {
// throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
} |
Partager