2013-04-21 78 views
0

我在netbean下面的runbean方法中为不同名字的GPS编写了一些cods继续更新500ms并获得经度和纬度的新值我想在另一个类中发送这个值名望如何做我吗?目标变量是tlon和tlat.t getvalue方法不起作用。如何在netbean中将数据一帧传输到另一个

public void run() { 
      try { 
       p1 = new communication().com(); 
      } catch (UnsupportedCommOperationException ex) { 
       Logger.getLogger(vpsmain.class.getName()).log(Level.SEVERE, null, ex); 
      } catch (IOException ex) { 
       Logger.getLogger(vpsmain.class.getName()).log(Level.SEVERE, null, ex); 
      } catch (TooManyListenersException ex) { 
       Logger.getLogger(vpsmain.class.getName()).log(Level.SEVERE, null, ex); 
      } 


        if(p1.substring(0, 1).equals("$")) 
        { 
        s=p1.split("\\$",0); 
         a1=s[1].split("\\*", 0); 
         t=a1[0].split(",",0); 
      if((a1[0].substring(2, 5).equalsIgnoreCase("GGA"))) 
      { 



    tlon.setText(t[4].substring(0, 3).concat(" ").concat(t[4].substring(4)).concat("'").concat(" ").concat(t[5])); 




      double y1=Double.parseDouble(t[2])*180/Math.PI; 


    tlat.setText(t[2].substring(0, 2).concat(" ").concat(t[2].substring(3).concat("'").concat(" ").concat(t[3]))); 

} 
+0

你的意思是从一个JFrame的另一个? – 2013-04-21 15:26:52

+0

是的,我的意思是只有 – 2013-04-21 15:48:40

+0

一般来说,你不应该这样做,你可能想要在一个JFrame中使用多个JPanes – 2013-04-21 16:24:08

回答

0

创建目标JFrame的公共方法(一些参数),并调用具有相关参数确定方法。并创建类变量来获取这些值。
在式2

public void setData(Lan lan,Lon lon){ // you can use any data type for these values as you need 
    // there should be lan & lon defined in the class definition too. 
    this.lan = lan; 
    this.lon = lon; 
} 
+0

我也尝试它,我在目标方法中解析我的经度和纬度,但它取值初始值。 – 2013-04-21 16:06:54

+0

创建类变量来获取该参数。如果您将它们命名为与参数相同(如上面的答案),请确保使用它。设定值。否则,这些值不会影响类变量,参数值将在方法结束运行后立即被擦除。 – 2013-04-21 16:18:07

相关问题