java如何发送和重新发送fxml对象
在我的例子中,我想将Pane对象从controller类转移到另一个名为Wykres的类,然后向其中添加子对象,例如Circle的对象,但是当我试图通过单击按钮生成圆时,没有圆,有人能帮我吗?谢谢
public class Controller {
@FXML
public Label label_x_waga;
@FXML
Label label_y_waga;
@FXML
Pane root_pane;
@FXML
Button button_add;
private static Pane panee;
private SiecNeuronowa siecNeuronowa;
public void initialize(){
siecNeuronowa = new SiecNeuronowa();
panee=root_pane;
}
public static Pane getPane(){
return panee;
}
@FXML
public void button_add_action(){
root_pane = Wykres.getPane_root();
for(int i=0;i<300;i++)
siecNeuronowa.dodajPunkt();
}
}
还有Wykres班
public class Wykres {
private int xWartosc, yWartosc;
private String kolor;
private static Pane pane_root;
public void rysujPunkt(Pane root, int x, int y, String color){
x+=180;
y+=180;
xWartosc = x;
yWartosc = y;
this.kolor = color;
if(color.equals("NIEBIESKI")){
root.getChildren().add(new Circle(x, y, 5, Color.BLUE));
}
else if(color.equals("CZERWONY")){
root.getChildren().add(new Circle(x, y, 5, Color.RED));
}
pane_root = root;
}
public static Pane getPane_root(){return pane_root;}
}
rysujPunkt()方法在此处调用:
public class SiecNeuronowa {
private Perceptron perceptron1;
private Wykres wykres1;
public SiecNeuronowa(){
wykres1 = new Wykres();
perceptron1 = new Perceptron(){
@Override
public double finalizuj_dane(double potencjalMembranowy){
if(potencjalMembranowy>0)
return 1;
else
if(potencjalMembranowy<0)
return -1;
else
return 0;
}
};
perceptron1.dodajWejscia(2);
Random random = new Random();
double rand_x = random.nextDouble();
double rand_y = random.nextDouble();
perceptron1.setWagaWejsciowa(0, rand_x);
perceptron1.setWagaWejsciowa(1, rand_y);
}
public void dodajPunkt(){
Random random = new Random();
int x = random.nextInt()*150;
int y = random.nextInt()*150;
perceptron1.setDaneWejsciowe(0, x);
perceptron1.setDaneWejsciowe(1, y);
int wynik = (int)perceptron1.getWyjscie();
if(wynik == 1)
wykres1.rysujPunkt(Controller.getPane(), x, y, "Niebieski");
else
if(wynik == -1)
wykres1.rysujPunkt(Controller.getPane(), x, y, "Czerwony");
}
}
共 (0) 个答案