This really depends on where your java code is located! There are several tools that allow you to create a URL object of a local file path, and these can be fed into ImageIcon creation!
If the image is in the same directory (folder) as you java code, then the following should work to ensure the file is referenced even on other machines:
URL cardgameCanvas = new File("cardgameTableCanvas.jpg").toURI().toURL();
JLabel panel = new JLabel(new ImageIcon(cardgameCanvas));
(For java 7+: Paths.get("cardgameTableCanvas.jpg").toUri().toURL()
)
This should allow you to reference the image by first creating a URL object that links to it, and passing that URL object to the new ImageIcon object!
Hope this helps!
Additional Source
Edit
You can also just do
JLabel panel = new JLabel(new ImageIcon("cardgameTableCanvas.jpg"));
;)
Edit 2
Your main would look something like this (if you wanted to go the "hard way"):
public static void main(String[] args){
JFrame frame = new JFrame();
URL cardgameCanvas = new File("cardgameTableCanvas.jpg").toURI().toURL();
JLabel panel = new JLabel(new ImageIcon(cardgameCanvas));
frame.setSize(WIDTH,HEIGHT);
panel.setSize(WIDTH,HEIGHT);
frame.add(panel);
frame.setTitle("Test Canvas");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
CardgameTable sampleTable = new CardgameTable();
frame.add(sampleTable);
frame.setVisible(true);
}
But since it works for you I would definetaly recommend just referencing the local document itself like this:
public static void main(String[] args){
JFrame frame = new JFrame();
JLabel panel = new JLabel(new ImageIcon("cardgameTableCanvas.jpg"));
frame.setSize(WIDTH,HEIGHT);
panel.setSize(WIDTH,HEIGHT);
frame.add(panel);
frame.setTitle("Test Canvas");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
CardgameTable sampleTable = new CardgameTable();
frame.add(sampleTable);
frame.setVisible(true);
}