Note that there are some explanatory texts on larger screens.

plurals
  1. POJava instance field value only changed in method
    primarykey
    data
    text
    <p>I made the variables for borderX1-Y2 at the top but I didn't assign them til the paint method. I checked the values inside the method and they are correct, but when I checked them in another method they are 0. How do I get them to keep their values?</p> <pre><code>public void paint(Graphics g) { borderX1 = 20; borderY1 = 20; borderX2 = getWidth(); borderY2 = getHeight(); g.setColor(Color.white); g.fillRect(0, 0, borderX2, borderY2); g.setColor(Color.blue); g.drawRect(borderX1, borderY1, borderX2 - 40, borderY2 - 40); } </code></pre> <p>heres everything else (I cut the unnecessary bits)</p> <pre><code>public class ShapePanel extends JPanel { private int borderX1; private int borderY1; private int borderX2; private int borderY2; public ShapePanel(){} public void paint(Graphics g) { borderX1 = 20; borderY1 = 20; borderX2 = getWidth(); borderY2 = getHeight(); g.setColor(Color.white); g.fillRect(0, 0, borderX2, borderY2); g.setColor(Color.blue); g.drawRect(borderX1, borderY1, borderX2 - 40, borderY2 - 40); } public int getX1() {return borderX1;} public int getY1() {return borderY1;} public int getX2() {return borderX2;} public int getY2() {return borderY2;} } </code></pre> <p>My error is in my returns, they return a value of 0 for all of them</p> <p>I can initialize the variables like this</p> <pre><code>private int borderX1 = 20; private int borderY1 = 20; private int borderX2 = 762; private int borderY2 = 533; </code></pre> <p>but I want the values of X2 and Y2 to change based on the window size</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload