有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java在ArrayList中使用引用来调用方法,并更改被引用对象的当前状态?

也许这是不可能的,但我想做的是同时使用ArrayList动态引用GUI中多个元素的可见性。这些对象是通过另一种方法自己创建的

两者都是旧屏幕。setVisible(假) 和oldScreen<;1>;。setVisible(假) 语句会导致错误。我有预感我的想法不会那么成功

这就是我所拥有的,我有什么方法可以做到这一点吗

private void initScreens() {
// I create some ArrayLists as "screensets" of sorts and put some GUI elements in there
    ArrayList startScreen = new ArrayList();
    ArrayList lostScreen = new ArrayList();
    ArrayList playScreen = new ArrayList();
    startScreen.add(startB);
    startScreen.add(exitB);

    lostScreen.add(yl1);
    lostScreen.add(yl2);
    lostScreen.add(yl3);
    lostScreen.add(yl4);
    lostScreen.add(yl5);


}
private void changeScreen(ArrayList oldScreen,ArrayList newScreen) {
// now i try to create a handy method to handle the length of the arrays itself, so if
i need to make changes to screens I just add them to there array. They are then easily
displayed, and hidden when told.

    int os = oldScreen.size();
    int ns = newScreen.size();

    for (int i = os; i > 0; i--){
        oldScreen<i>.setVisible(false);
        oldScreen<1>.setVisible(false);
    }

共 (1) 个答案

  1. # 1 楼答案

    这是无效的语法

    你在试着写作

    oldScreen.get(i)
    

    还应该使用泛型(ArrayList<Screen>)来避免强制转换