I know that it might be a basic question but the codes that i got for this question does not work on my arraylist. May be someone could help me solve this.I would like to access the arraylist "Connection" of class Testing1.Java and use it in another class named SQL.Java. My array "Connection" is an object of another array "NamedShape".
Here are my 2 arrayslist:
ArrayList<NamedShape> shapes = new ArrayList<NamedShape>();
ArrayList<Connection> con = new ArrayList<Connection>();
public class Connection {
private NamedShape namedShape1;
private NamedShape namedShape2;
public Connection(NamedShape namedShape1, NamedShape namedShape2) {
this.namedShape1 = namedShape1;
this.namedShape2 = namedShape2;
}
public NamedShape getNamedShape1() {
return namedShape1;
}
public NamedShape getNamedShape2() {
return namedShape2;
}
public void setNamedShape1() {
this.namedShape1 = namedShape1;
}
public void setNamedShape2() {
this.namedShape2 = namedShape2;
}
}
public class NamedShape {
private String name;
private Shape shape;
public NamedShape(String name, Shape shape) {
this.name = name;
this.shape = shape;
}
public String getName() {
return name;
}
public Shape getShape() {
return shape;
}
}
I've put a getConnection Method inside my Testing1.Java. Data are inserted correctly inside the Arraylist Connection(I've not put the codes to add the data but data are inserted correctly, that's not the problem)
public ArrayList<Connection> getConnection() {
return con;
}
Here is my Trial SQL.Java but it does not recognize the getConnection() method here:
import java.util.ArrayList;
public class SQL {
private Testing1 sql;
public SQL(){
sql = new Testing1();
ArrayList<Connection> con = sql.getConnection()
}
public static void main(String args[]){
new Test();
}
}
Can someone please help me out with this?
Edited
I've read and followed what you said and now i have this, but i dont know how the main should be. So i have called my class Testing1.java to ERDBUILDER.java. My ERDBUILDER class allows me to draw shapes and after some processing the shape is stored to an arraylist Connection. Then i have my class SQL.java where i want to use that arraylist Connection by calling the class SQL.java from the ERDBUILDER.java but i dont want java to open another ERDBUILDER.java. I've put new SQL(); in the main but it's opening another ERDBUILDER.java and that's not want i want. can you please suggest something? I might be a basic question but i still can't find a way.
package project;
import java.awt.Shape;
import java.util.ArrayList;
import project.ERDBUILDER.DrawingBoard.Attribute;
import project.ERDBUILDER.DrawingBoard.Connection;
import project.ERDBUILDER.DrawingBoard.NamedShape;
public class SQL {
private ERDBUILDER sql;
public SQL(){
sql = new ERDBUILDER();
ArrayList<Connection> con = sql.getDrawingBoard().getConnection();
for (int a = 0; a < con.size(); a++) {
NamedShape f = con.get(a).getNamedShape1();
Attribute g = con.get(a).getNamedShape2();
String i = f.getName();
String j = g.getName();
Shape y = f.getShape();
Shape y1 = g.getShape();
}
}
public static void main(String args[]){
}
}
SQL.javaand such.Testing1classshapesandcon, but these are ArrayLists of the relevant objects, rather than arrays. To avoid confusion (both for yourself and others) it may be worth correcting this.