I am doing some test code for an inventory system (I plan to work on a game later on) using Javax components. I was making a class called 'Cursor' which extends 'ItemStack' so that you can "pick up" items you click on in an inventory screen. The problem I'm having is that I use a static variable 'cur' as to hold the instance of this class, but every time I try to compile, I get the following error:
.\john\window\component\ItemSlotPanel.java:13: error: cannot find symbol
itemStack.swapWith(Cursor.cur);
^
symbol: variable cur
location: class Cursor
.\john\window\component\ItemSlotPanel.java:25: error: package itemstack.item doe
s not exist
g.drawImage(itemstack.item.icon.getScaledInstance(this.getWidth(),this.get
Height(),Image.SCALE_SMOOTH),0,0,null);
^
.\john\window\component\InfiniteItemSlotPanel.java:15: error: cannot find symbol
if (Cursor.cur.isEmpty()) {
^
symbol: variable cur
location: class Cursor
.\john\window\component\InfiniteItemSlotPanel.java:16: error: cannot find symbol
this.itemStack.copyTo(Cursor.cur);
^
symbol: variable cur
location: class Cursor
.\john\window\component\InfiniteItemSlotPanel.java:17: error: cannot find symbol
} else if (Cursor.cur.item.id == this.itemStack.item.id) {
^
symbol: variable cur
location: class Cursor
.\john\window\component\InfiniteItemSlotPanel.java:18: error: cannot find symbol
Cursor.cur.count += this.itemStack.count;
^
symbol: variable cur
location: class Cursor
6 errors
which implies that the variable doesn't exist
I have attempted to find similar problems on this site (as well as through Google), but most of what I have found is irrelevant. On StackOverflow, I found questions like What is reflection and why is it useful?, Bytecode features not avaliable in the Java language, and Benefits of prototypal inheritance over classical.
The class in question:
package john;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import john.item.*;
import john.window.*;
import john.window.component.*;
public class Cursor extends ItemStack implements MouseListener,MouseMotionListener {
public static Cursor cur = new Cursor();
public Cursor() {
super(null);
}
public static Cursor getCursor() {
return cur;
}
public void mouseClicked(MouseEvent e) {
Object source = e.getSource();
if (source instanceof InfiniteItemSlotPanel) {
((InfiniteItemSlotPanel) source).mouseClicked(e);
} else if (source instanceof ItemSlotPanel) {
((ItemSlotPanel) source).mouseClicked(e);
}
}
public void mouseEntered(MouseEvent e) {
}
public void mouseExited(MouseEvent e) {
}
public void mousePressed(MouseEvent e) {
}
public void mouseReleased(MouseEvent e) {
}
public void mouseDragged(MouseEvent e) {
}
public void mouseMoved(MouseEvent e) {
}
public Cursor addListenerTo(Component x) {
x.addMouseListener(this);
x.addMouseMotionListener(this);
return this;
}
}
ItemStack.java:
package john.item;
public class ItemStack {
public Item item;
public int count;
public ItemStack(Item item) {
this(item,1);
}
public ItemStack(Item item,int count) {
this.item = item;
this.count = count;
}
public boolean isEmpty() {
return this.item == null && this.count == 0;
}
public void check() {
if (this.count < 0) {this.count = 0;this.item = null;}
if (this.item == null && this.count > 0) this.count = 0;
if (this.count == 0 && this.item != null) this.item = null;
}
public void dispose() {
this.item = null;
this.count = 0;
}
public boolean canInsert(ItemStack stack) {
return this.item.id == stack.item.id;
}
public void insert(ItemStack stack) {
if (!canInsert(stack)) return;
this.count += stack.count;
}
public void insertInto(ItemStack dest) {
dest.insert(this);
}
public void copyTo(ItemStack dest) {
dest.item = this.item;
dest.count = this.count;
}
}
If you need more code than this, don't hesitate to ask, I'll do my best to condense it, but it currently consists of 14 interlocking classes, so I don't know how well that will go.
I am not sure how well this question will be received, but I don't know where else to go. I apologise if I am wasting time, but I tried to make the question fit StackOverflow's guidelines. Any reply is appreciated (even negative ones). I just really need to figure out why this is happening. The last time I had a problem similar to this one, I had to delete and rewrite everything, so any information would be great! Also, sorry for my poor english (I am american born-and-raised, but I don't write this kind of thing very often anymore).