Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3439808
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:21:21+00:00 2026-05-18T08:21:21+00:00

I have two .java’s one called GUI.java, another called CustomPanel.java Once a button is

  • 0

I have two .java’s one called GUI.java, another called CustomPanel.java

Once a button is pressed in GUI.java, it does some stuff:

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);
        }

You don’t really need to know what except cp.test;
(It does alot but i’ve condensed it to fit my problem)

public void test(Graphics g, int pageviews2, String date2, String extcount5, int maxint)
{
...
critxvalues[0] = calc;
crityvalues[0] = desty;
System.out.println(critxvalues[0] + ":" + crityvalues[0]);
}

Then once another button is pressed in GUI.java something else happens:

    CustomPanel cp = new CustomPanel();
    cp.tooltip(x,y);

This cp.tooltip is simply:

public void tooltip(int x, int y)
{   
System.out.println(critxvalues[0] + ":" + crityvalues[0]);
}

Which I hoped would print out the same values as when the array[0] is printed out before, but it doesn’t cp.tooltip only prints out 0:0, while cp.test prints out (example) 200:200, so why is the:

critxvalues[0] = calc;
crityvalues[0] = desty;

(in cp.test) not saving the values?

The critxvalue/crityvalue is initalised at the top of CustomPanel.java…

int [] critxvalues = new int[100];
    int [] crityvalues = new int[100];

Please help,

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T08:21:22+00:00Added an answer on May 18, 2026 at 8:21 am

    Though I’m cannot be sure without seeing all the code, but it seems, that critx|yvalues are not static, so when you create a new instance of CustomPanel, they are initialized and contain 0s. You initialize a CustomPanal instance in the actionlistener in GUI.java as well. So the reason is you create new instances of CustomPanel every time you use it, and this will not save any state unless crit*valuess are not static.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two Java classes: B, which extends another class A, as follows :
Hypothetically, you have two products, one written in Java, the other in C#. You
I have some Java code that uses curly braces in two ways // Curly
I have two java classes. One is NewFrame.java where the forms(buttons, textfields) are located.
I have two versions of Java setup for development. One is 1.5 and the
i have two programs one in directory /home/redhat/Documents/java1/j1 Demo1.java package j1; public class Demo1
I have a simple question (working with Java). I have two classes, one represents
I have two applications written in Java that communicate with each other using XML
I am trying to compare two decimal values in Java script. I have two
I have two identical tables and need to copy rows from table to another.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.