Java 如何在netbean中将数据从一个帧传输到另一个帧
我已经在netbean中为不同的fame中的GPS编写了一些代码,下面运行方法继续更新500ms并获得新的经度和纬度值我想在另一个类fame中发送此值我该怎么做?目标变量为tlon,tlat.t getvalue方法不起作用Java 如何在netbean中将数据从一个帧传输到另一个帧,java,Java,我已经在netbean中为不同的fame中的GPS编写了一些代码,下面运行方法继续更新500ms并获得新的经度和纬度值我想在另一个类fame中发送此值我该怎么做?目标变量为tlon,tlat.t getvalue方法不起作用 public void run() { try { p1 = new communication().com(); } catch (UnsupportedCommOperationExcept
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])));
}
在target
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;
}
你的意思是从一个JFrame到另一个JFrame吗?一般来说,你不应该这样做,你可能想在一个JFrame中使用多个JPANE我也尝试过它我在目标方法的参数中解析了经度和纬度,但它需要值初始值。创建类变量来获取该参数。如果您将它们命名为与参数中相同的名称(如上面的答案所示),请确保使用此名称。设置值。否则,这些值将不会对类变量产生影响,并且参数值将在方法完成运行后立即删除。