Java 如何使用.setVisible()方法?

Java 如何使用.setVisible()方法?,java,javafx,file-io,binaryfiles,Java,Javafx,File Io,Binaryfiles,我的程序应该在按下按钮(rbutton1)时使图像可见,我应该使用setVisible(true),但是我在使rbutton1的事件处理程序工作时遇到了问题 方法publicstaticarraylistread(stringfilename)读取二进制文件 package项目4; 导入java.io.FileInputStream; 导入java.io.FileOutputStream; 导入java.io.IOException; 导入java.io.ObjectInputStream; 导

我的程序应该在按下按钮(
rbutton1
)时使图像可见,我应该使用
setVisible(true)
,但是我在使
rbutton1
的事件处理程序工作时遇到了问题

方法
publicstaticarraylistread(stringfilename)
读取二进制文件

package项目4;
导入java.io.FileInputStream;
导入java.io.FileOutputStream;
导入java.io.IOException;
导入java.io.ObjectInputStream;
导入java.io.ObjectOutputStream;
导入java.util.ArrayList;
导入javafx.application.application;
导入javafx.collections.ObservableList;
导入javafx.event.ActionEvent;
导入javafx.event.EventHandler;
导入javafx.geometry.Insets;
导入javafx.geometry.Pos;
导入javafx.scene.scene;
导入javafx.scene.control.Button;
导入javafx.scene.control.CheckBox;
导入javafx.scene.control.ComboBox;
导入javafx.scene.control.Label;
导入javafx.scene.control.ListView;
导入javafx.scene.control.RadioButton;
导入javafx.scene.control.SelectionMode;
导入javafx.scene.control.ToggleGroup;
导入javafx.scene.layout.GridPane;
导入javafx.scene.layout.Pane;
导入javafx.scene.text.text;
导入javafx.stage.stage;
导入javafx.util.Duration;
公共类Project4扩展了应用程序{
主体b;
头1,头2;
hat1,hat2;
武器w1、w2、w3;
伴生c1、c2、c3;
@凌驾
公共无效开始(阶段primaryStage){
//获取对象
ArrayList片段=读取(“片段.dat”);
//父窗格,仅一行,
//包含左栏中用于图像的窗格,右栏中用于控件的网格窗格
GridPane root=新的GridPane();
//图像窗格
窗格奶奶=新窗格();
root.add(granny,0,0);
//加载图像
用于(件号p:件号){
//只有身体开始可见
if(主体的p实例){
granny.getChildren().add((Body)p.image);
b=(体)p;
}//其他所有内容都添加到正确的位置,但都不可见
else if(头的p实例){
granny.getChildren().add((Head)p.image);
if(head1==null){
头1=(头)p;
}否则{
头2=(头)p;
}
}else if(帽子的p实例){
granny.getChildren().add(((Hat)p.image);
if(hat1==null){
hat1=(Hat)p;
}否则{
hat2=(Hat)p;
}
}else if(武器的p实例){
granny.getChildren().add(((武器)p.image);
如果(w1==null){
w1=(武器)p;
}else if(w2==null){
w2=(武器)p;
}否则{
w3=(武器)p;
}
}else if(伙伴的p实例){
granny.getChildren().add(((Companion)p.image);
if(c1==null){
c1=(伴生)p;
}else if(c2==null){
c2=(伴生)p;
}否则{
c3=(伴生)p;
}
}
}
//控制窗格
GridPane控件=新建GridPane();
控件。设置对齐(位置顶部\中间);
控件。设置填充(新的插图(10,10,10,10));
对照组:setHgap(15);
对照组:setVgap(15);
标签海岬标签=新标签(“选择头部:”);
RadioButton RBbutton1=新的RadioButton(“带蜜蜂的Esme”);
复选框check1=新复选框(“面向另一个方向”);
RadioButton rbutton2=新的RadioButton(“Esme正常”);
复选框check2=新复选框(“面向另一个方向”);
标签hatLabel=新标签(“选择帽子:”);
RadioButton RBbutton3=新的RadioButton(“声名狼藉的帽子”);
RadioButton RBbutton4=新的RadioButton(“带别针的帽子”);
RadioButton RBbutton5=新的RadioButton(“无帽子”);
标签武器标签=新标签(“武器:”);
ComboBoxcbox=newcombobox();
cbox.getItems().addAll(
“扫帚”,
“镰刀”,
“棍子”
);
标签公司标签=新标签(“伙伴:”);
ListView clv=新建ListView();
clv.getItems().addAll(“老鼠之死”、“加斯珀”、“行李”);
clv.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
clv.setPrefSize(2,90);
按钮导出按钮=新按钮(“导出字符”);
Label exportFileName=新标签(“export.oscar.dat”);
ToggleGroup=新的ToggleGroup();
rbutton1.setToggleGroup(组);
rbutton2.setToggleGroup(组);
ToggleGroup group2=新的ToggleGroup();
rbutton3.setToggleGroup(组2);
rbutton4.setToggleGroup(组2);
rbutton5.setToggleGroup(组2);
控件。添加(海岬标,1,5);
控件。添加(rbutton1、2、6);
控件。添加(选中1、3、6);
添加(rbutton2,2,7);
控件。添加(选中2、3、7);
控件。添加(hatLabel,1,8);
添加(rbutton3,2,9);
添加(rbutton4,2,10);
添加(rbutton5,2,11);
添加(武器标签,1,13);
添加(cbox,2,14);
添加(公司标签,1,15);
添加(clv,2,16);
控件。添加(exportButton,2,17);
添加(exportFileName,3,17);
rbutton1.setOnAction(新的EventHandler(){
@凌驾
公共无效句柄(ActionEvent事件){
}
});
添加(对照组,1,0);
场景=新场景(根,900700);
初级阶段。场景(场景);
primaryStage.show();
}
公共静态void main(字符串[]args){
group1.selectedToggleProperty().addListener(new ChangeListener<Toggle>(){
   @Override
   public void changed(ObservableValue<? extends Toggle> ov, Toggle t, Toggle t1)
       {
       // Do what you want inside

   });