Например, если я создаю массив объектов и предоставляю данные ...
короткая версия проблемы.array [0] .init ("ce", 2) array [1] .init ("nh", 2)
Вывод ... из массива [0] будет таким же, как массив [1]Зачем?в чем дело?Мне нужны .. не такие же результаты
Вот код:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
import java.lang.Math;
public class Gra_ulamki {
/**
* @param args the command line arguments
*/
public static ulamek[] tab_ulamkow;
public static void main(String[] args)
{
tab_ulamkow = new ulamek[30];
tab_ulamkow[0] = new ulamek();
tab_ulamkow[0].init("dd", 5);
tab_ulamkow[1] = new ulamek();
tab_ulamkow[1].init("dde", 8);
System.out.println("poz x --" + tab_ulamkow[0].x + "-- y poz " + tab_ulamkow[0].y);
System.out.println("poz x --" + tab_ulamkow[1].x + "-- y poz " + tab_ulamkow[1].y);
// TODO code application logic here
//new GUI();
//new GUI();
}
}
class ulamek
{
public static String ch_v;
public static int x = 0, y = -5, y_max = 325;
public void init(String a, int number)
{
this.ch_v = a;
// przypisanie x
this.x = number;
}
public void move()
{
// restart pozycji w osi y
if(this.y < y_max)
{
this.y += +1;
}
else
{
this.y = -5;
}
}
}
Спасибо за помощь