Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/335.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
数组/方法/Java帮助_Java - Fatal编程技术网

数组/方法/Java帮助

数组/方法/Java帮助,java,Java,我有两个.java,一个叫GUI.java,另一个叫CustomPanel.java 在GUI.java中按下按钮后,它会执行一些操作: if (e.getSource() == displayButton) { //pageviews1 = Integer.parseInt(myText1.getText()); CustomPanel cp = new CustomPanel(); Graphics g

我有两个.java,一个叫GUI.java,另一个叫CustomPanel.java

在GUI.java中按下按钮后,它会执行一些操作:

if (e.getSource() == displayButton)
        {
            //pageviews1 = Integer.parseInt(myText1.getText());
            CustomPanel cp = new CustomPanel();
            Graphics g = loginMainPanel.getGraphics();

            int pos = 0;
            while (pos <= 9)
            {
            if (values[pos] > biggestvalue)
            {
            biggestvalue = values[pos];
            }
            pos = pos + 1;
            }

            cp.test(g, values[0], values2[0], "1", biggestvalue);
            cp.test(g, values[1], values2[1], "2", biggestvalue);
            cp.test(g, values[2], values2[2], "3", biggestvalue);
            cp.test(g, values[3], values2[3], "4", biggestvalue);
            cp.test(g, values[4], values2[4], "5", biggestvalue);
            cp.test(g, values[5], values2[5], "6", biggestvalue);
            cp.test(g, values[6], values2[6], "7", biggestvalue);
            cp.test(g, values[7], values2[7], "8", biggestvalue);
            cp.test(g, values[8], values2[8], "9", biggestvalue);
            cp.test(g, values[9], values2[9], "10", biggestvalue);
            //System.out.println("Added Data: " + values2[count2]);
            //count2++;
            graphlink.setEnabled(true);
        }
然后,一旦在GUI.java中按下另一个按钮,就会发生其他事情:

    CustomPanel cp = new CustomPanel();
    cp.tooltip(x,y);
此cp.tooltip仅为:

public void tooltip(int x, int y)
{   
System.out.println(critxvalues[0] + ":" + crityvalues[0]);
}
我希望打印出的值与之前打印出数组[0]时的值相同,但它不是cp.tooltip只打印出0:0,而cp.test打印出(示例)200:200,那么为什么:

critxvalues[0] = calc;
crityvalues[0] = desty;
(在cp.test中)是否不保存值

critxvalue/crityvalue在CustomPanel.java的顶部初始化

int [] critxvalues = new int[100];
    int [] crityvalues = new int[100];
请帮忙


谢谢。

虽然我不能肯定没有看到所有的代码,但似乎
critx | yvalue
不是静态的,所以当您创建
CustomPanel
的新实例时,它们被初始化并包含
0
s。您还可以在
GUI.java
中的actionlistener中初始化
CustomPanal
实例。原因是每次使用时都会创建
CustomPanel
的新实例,这不会保存任何状态,除非
crit*值
s不是静态的。

虽然我不能肯定没有看到所有的代码,但似乎
critx | yvalue
不是静态的,因此,当您创建
CustomPanel
的新实例时,它们将被初始化并包含
0
s。您还可以在
GUI.java
中的actionlistener中初始化
CustomPanal
实例。因此,原因是每次使用时都会创建
CustomPanel
的新实例,这不会保存任何状态,除非
crit*values
s不是静态的。

我相信这种情况会发生,因为这些是您指定的值。您多次调用cp.test()。每次发送数组value和value2的值时。不幸的是,您没有写在何处以及如何启动这些数组


再次检查2 System.out.println()打印的内容。更改其中一个的格式,否则无法区分来自两个不同位置的输出。为了获得更好的结果,请使用调试器

我认为这是因为这些都是您指定的值。您多次调用cp.test()。每次发送数组value和value2的值时。不幸的是,您没有写在何处以及如何启动这些数组


再次检查2 System.out.println()打印的内容。更改其中一个的格式,否则无法区分来自两个不同位置的输出。为了获得更好的结果,请使用调试器

对不起,如果这是一个太多/太少的信息,我已经试图让它清楚/考虑,我只需要我的数组值保存在其他方法/按钮点击的东西:p:(对不起,如果这是一个太多/太少的信息,我试图让它清楚/考虑,我只需要我的数组值保存在其他方法/按钮点击的东西:p:(
int [] critxvalues = new int[100];
    int [] crityvalues = new int[100];