简体   繁体   中英

how to get integer value from textfield and retrieve the value to another class in java

How to get integer value from textfield and retrieve the value to another class in java ??

I know how to get but if i used in another class he get me 0 value,,,

"this is in the GUI" x1,x2,y1,y2 predefined

private void X2_accesActionPerformed(java.awt.event.ActionEvent evt){              
     x2=(int)(Double.parseDouble(X2_acces.getText())); 
}

I want to draw line the user inter 2 point (x1,y1) and (x2,y2) after that move the value to class draw line

"this is in class drawLine"

Next_frame nf=new Next_frame();
Point2D.Double p2=new Point2D.Double(nf.x2,nf.y2);

The following statement is quite ambigous.

x2=(int)(Double.parseDouble(X2_acces.getText())); 

You are parsing the value as Double and casting it down to int . This is enough:

x2 = Integer.parseInt(x2_acces.getTest());

Now, when passing this value to another class, you have to make sure, that the method to which you are passing to accept the data type you are about to send.

For example:

For a class like this:

class DummyClass {
   public DummyClass(int X) {
      //Here note that 'x' is asking for a integer so you have to provide it with integer
   }
}

Then you have use them in the following order:

x2 = Integer.parseInt(x2_acces.getTest());
DummyClass c = new DummyClass(x2);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM