Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Variables 如何使void变量成为全局变量?_Variables_Void - Fatal编程技术网

Variables 如何使void变量成为全局变量?

Variables 如何使void变量成为全局变量?,variables,void,Variables,Void,我是一个初级程序员,我想问一下如何将void中的整数变量pontok更改为public?因此,当它在void中更改值时,整个程序都可以访问该变量。请帮帮我!谢谢大家! int pontok; public void actionPerformed(ActionEvent evt) { String cmd = evt.getActionCommand(); if (cmd == "Accept"){ acceptAnswer();

我是一个初级程序员,我想问一下如何将void中的整数变量pontok更改为public?因此,当它在void中更改值时,整个程序都可以访问该变量。请帮帮我!谢谢大家!

int pontok;
public void actionPerformed(ActionEvent evt) {
        String cmd = evt.getActionCommand();
        if (cmd == "Accept"){
            acceptAnswer();
        }
        else if (cmd == "Retry"){
            tryAgain();
        }
        else if (cmd == "Next"){
            nextTeam();
        }
        else if (cmd == "Return"){
            backToMenu();
        }
        else if (cmd == "Finish"){
            finishGame();
        }
    }


    public void acceptAnswer(){
        String team = nev.getText();
        team = team.toLowerCase();
        nev.setEditable(false);
            if (csapat[i].equals(team)){
            next.setEnabled(true);
            }
            else{retry.setEnabled(true);
            accept.setEnabled(false);
        }
        }
    public void tryAgain(){
        nev.setEditable(true);
        retry.setEnabled(false);
        accept.setEnabled(true);
        nev.setText(null);
        pontok = pontok - 10;
        points.setText("Your points:"+ pontok );

    }
    public void nextTeam(){
        nev.setEditable(true);
        next.setEnabled(false); 
        nev.setText(null);
        pontok = pontok + 100;
        points.setText("Your points:"+ pontok );
        fel.setText("Kerem a kepen lathato csapat nevet!");
        i++;
        image = new ImageIcon (getClass().getResource(csapatok[i]));
        label.setIcon(image);

你用什么语言工作?我想我理解您想要做什么,如果我的理解是正确的,那么您就不理解C/C++中“void”的含义。Void不是您想要使用的通配符,因此您不能将potnok更改为Void,并希望它不会突然被actionPerformed匹配。你能做的最好的事情就是将整数设置为一个不会出现在本例中的变量。我正在使用Java,我想在另一个程序中使用更改后的pontok值,但actionListener会更改该值,因此我希望能够以某种方式到达pontok after Action Listener。