Variable losing stored value
In the code below, XPos keeps changing values without any action take on
it by my code.
public class JTwinPreviewButtons {
static PreviewPanel previewPanel;
static EditorPanel editorPanel;
ArrayList<JTwinPreviewButtons> subButtons = new
ArrayList<JTwinPreviewButtons>();
private static int overallYPos = 0;
Item item;
JButton plusButton;
JButton itemButton;
private boolean isPlus;
private boolean shown;
private int YPos;
private int XPos;
public JTwinPreviewButtons(Item someItem, int itemNum) {
plusButton = new JButton("-");
itemButton = new JButton(someItem.getName());
item = someItem;
isPlus = false;
shown = true;
System.out.println("Item Number: "+itemNum);
XPos = (itemNum * 15) + 25;
System.out.println(XPos); //XPos == 70
if (previewPanel!=null) {
if (itemNum == 0) {
previewPanel.addTopButton(this);
}
previewPanel.refresh(); //printed inside here XPos == 25
System.out.println(XPos); //XPos == 70
}
plusButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (isPlus) {
for (JTwinPreviewButtons subs : subButtons) {
subs.setSubShown(true);
}
plusButton.setText("-");
isPlus = false;
previewPanel.refresh();
} else {
for (JTwinPreviewButtons subs : subButtons) {
subs.setSubShown(false);
}
plusButton.setText("+");
isPlus = true;
previewPanel.refresh();
}
}
});
itemButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
}
});
//here XPos == 70
//after initialization method XPos == 25
}
}
So, it would seem that XPos only retains its value for the duration of the
initialization method. There are NO other places where XPos's value is
set. What really confuses me about this is no matter what I set XPos to in
the initialization it ALWAYS reverts to 25 yet I have scoured all of my
code for any other spot where I mistakenly did "XPos = 25" and it simply
does not exist in my code... What else could be at work here?
No comments:
Post a Comment