mardi 24 février 2015

How to send content of a variable from one form to another form using java

This is part of the code for the "draw" class.


The program here is counting the number of ellipses that are being drawn and save the number in an array namely "count" and then it retrieves the size of the array and print it. I would liked to send the content of the variable "sizes" which is from the "DrawForm" to another form namely "AttributeForm".


I've done some search and i found out that i should be using getters and setters but don't know how to link it to my attribute form.



public class DrawForm extends JFrame {
private int c;

public int getC() {
return c;
}
public void setC(int c) {
this.c= this.c;
}

//lots of codes not related.

if (currentAction == 3) {
aShape = drawEllipse(drawStart.x, drawStart.y,
e.getX(), e.getY());
shapes.add(aShape);
shapeStroke.add(strokeColor);
drawStart = null;
drawEnd = null;
repaint();
counts = counts+1;
count.add(counts);
int sizes = count.size();
System.out.println(sizes);
new AttributeForm().setVisible(true);
}}


Here is my AttributeForm:



public class AttributeForm {
public static void main (String args[]){

//if sizes is >1
System.out.println("Greater than one");

//else

System.out.println("Less than one");

}
}


Can you please help me to achieve this?


Aucun commentaire:

Enregistrer un commentaire