public class Odczyt {
Punkt[][][] linie = new Punkt[24][10][9];
public void Odczytaj() throws FileNotFoundException {
File file = new File("Izolinie");
Scanner in = new Scanner(file);
String zdanie = null;
String[] splitedZdanie = null;
String[] splitedPunkt = null;
while (in.hasNextLine()){
zdanie = in.nextLine();
for(int i=0; i<24; i++){
if (zdanie.equals(Integer.toString(i))){
for(int j=0;j<10;j++){
zdanie = in.nextLine();
splitedZdanie = zdanie.split(";");
for(int k=0; k <9; k++){
splitedPunkt = splitedZdanie[k].split(",");
linie[i][j][k] = new Punkt(Integer.parseInt(splitedPunkt[0]), Integer.parseInt(splitedPunkt[1]));
}
}
}
}
}
}
}
protected void RysujLinie(Graphics2D g2d) {
int x_1;
int y_1;
int x_2;
int y_2;
for(int i=0; i<24; i++)
{
if(i==godzina)
{
for(int j = 0; j< odczyt.linie[i].length; j++)
{
System.out.println("WW");
for(int k = 0; k< odczyt.linie[i][j].length - 1 ; k++)
{
x_1 = odczyt.linie[i][j][k].x;
y_1 = odczyt.linie[i][j][k].y;
x_2 = odczyt.linie[i][j][k+1].x;
y_2 = odczyt.linie[i][j][k+1].y;
System.out.println( x_1 + "," + y_1 + " -> " + x_2 +","+y_2);
g2d.drawLine(x_1, y_1, x_2, y_2);
}
}
}
}
}
}
zmieniłem na:
public class Linia {
List<Punkt> lista = new ArrayList<Punkt>();
}
public class Odczyt {
Linia[][] linie = new Linia[24][10];
public void Odczytaj() throws FileNotFoundException {
File file = new File("Izolinie");
Scanner in = new Scanner(file);
String zdanie = null;
String[] splitedZdanie = null;
String[] splitedPunkt = null;
for(int i=0; i<linie.length; i++){
for(int j=0; j<linie[i].length; j++){
linie[i][j] = new Linia();
}
}
while (in.hasNextLine()){
zdanie = in.nextLine();
for(int i=0; i<24; i++){
if (zdanie.equals(Integer.toString(i))){
for(int j=0;j<10;j++){
zdanie = in.nextLine();
splitedZdanie = zdanie.split(";");
for(int k=0; k <9; k++){
splitedPunkt = splitedZdanie[k].split(",");
linie[i][j].lista.add(new Punkt(Integer.parseInt(splitedPunkt[0]), Integer.parseInt(splitedPunkt[1])));
}
}
}
}
}
}
}
protected void RysujLinie(Graphics2D g2d) {
int x_1;
int y_1;
int x_2;
int y_2;
for(int i=0; i<24; i++)
{
if(i==godzina)
{
for(int j = 0; j< odczyt.linie[i].length; j++)
{
System.out.println("WW");
for(int k = 0; k< odczyt.linie[i][j].lista.size() - 1 ; k++)
{
x_1 = odczyt.linie[i][j].lista.get(k).x;
y_1 = odczyt.linie[i][j].lista.get(k).x;
x_2 = odczyt.linie[i][j].lista.get(k+1).x;
y_2 = odczyt.linie[i][j].lista.get(k+1).y;
System.out.println( x_1 + "," + y_1 + " -> " + x_2 +","+y_2);
g2d.drawLine(x_1, y_1, x_2, y_2);
}
}
}
}
}
Co zrobiłem źle, że linie rysowane są w inaczej ?