Problème d'affichage au chargement
Bonsoir,
J'utilise ce code pour traiter des trames !AIVDM.
Code:
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
| /*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package ais;
import static java.awt.image.ImageObserver.WIDTH;
import java.io.BufferedReader;
import java.io.StringReader;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
/**
*
* @author Seb et Lae
*/
public class Accueil extends javax.swing.JFrame implements Runnable {
public String NewsMsg;
Thread t=null;
BufferedReader _monbuf;
int ClinetPortNumber;
/**
* Creates new form Accueil
*/
public Accueil() {
initComponents();
NewsMsg = null;
//super("News Client");
}
public void Setup(int ClientPort)
{
ClinetPortNumber=ClientPort;//ClientPort;
t=new Thread(this);
t.start();
}
@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[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* 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(Accueil.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Accueil.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Accueil.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Accueil.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
final Accueil ob = new Accueil();
ob.Setup(6020);
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Accueil().setVisible(true);
while(true)
{
try
{
try (DatagramSocket ClientSoc = new DatagramSocket(6020)) {
byte Receivebuff[]=new byte[1024];
DatagramPacket dp=new DatagramPacket(Receivebuff,Receivebuff.length);
ClientSoc.receive(dp);
ob.NewsMsg = new String(dp.getData(),0,dp.getLength());
BufferedReader entree = new BufferedReader(new StringReader(ob.NewsMsg));
ClientSoc.close();
Thread.sleep(50);
AcqAIS miact = new AcqAIS(ob.NewsMsg, null);
ob.jTextArea1.setText(miact.resultat);
}
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
}
});
}
// 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.
}
} |
Sur ma fenetre principale il devrais il y avoir un jtextarea , et un jbutton etc.
Au lancement ma fenetre s'ouvre mais sans jtextarea ni jbutton ni rien.
Par contre le traitement fonctionne.
De
Citation:
!AIVDM,1,1,,A,13npVB002V06TVhM5Ej0lPU`0<0g,0*13
j'obtiens bien
Citation:
1MessagePOS
Repeat indicator 0
MMSI: 233009000
Nav Status: 0
ROT: 0.17856115333363184
SOG: 5.9
Pos Accuracy: 0
Longitude : 1.4910133333333333
Latitude : 51.04416833333333
COG: 0.0
True heading: 62
TimeStamp: 12
SM: 0
Spare: 0
RAIM: 0
Comm state: 2244
Sync State: 0
Slot Time Out: 0
Sub Message: 2244
voici ma mon autre class
Code:
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
| import java.util.*;
import java.io.*;
import java.util.regex.*;
public class AcqAIS extends Thread{
private Thread _t;
private LinkedList<MessageAIS> _dest;
//private BufferedReader _br;
private String _br;
public String resultat;
public AcqAIS(String br,LinkedList<MessageAIS> dest){
_dest=dest;
_br=br;
_t = new Thread(this);
_t.start();
}
public void run(){
try{
//while(_br.ready()){
String s = _br;//.readLine();
if (s.charAt(0) == "!".charAt(0)){
Scanner sc = new Scanner(s);
sc.findInLine("!AIVDM,1,1,,A,(.*),\\d\\*\\w{2}");
MatchResult result = sc.match();
sc.close();
String msg = result.group(1);
// System.out.print(MessageAIS.getMsgType(msg));
if (MessageAIS.getMsgType(msg) == 1){
MessagePOS ms= new MessagePOS(msg);
resultat = ms.toString();
System.out.println(resultat);
}
else if (MessageAIS.getMsgType(msg) == 5){
MessageSTATIC ms= new MessageSTATIC(msg);
//System.out.println(ms);
}
}
//}
}
catch(Exception e){System.out.println(e );}
}
public static void main (String[] args){
try{
String mbr = args[0];
//BufferedReader mbr = new BufferedReader(new FileReader(args[0]));
LinkedList<MessageAIS> liste = new LinkedList<MessageAIS>();
AcqAIS myAcqAIS= new AcqAIS(mbr,liste);
}
catch(Exception e){System.out.println(e );}
}
} |
D'autre part quand je fais ceci (class Accueil) :
Code:
System.out.println(miact.resultat);
j'ai nullnullnull etc.
alors que (Class AcqAIS)
Code:
System.out.println(resultat);
donne un resultat.