I'm new to swing, and was curious if anyone could point me in the right direction here. Cannot figure out how to make this repaint crap work, or if I'm supposed to be using repaint(), or what, to make this image get drawn to the background of my window. Here is my code that I have so far. It is drawing nothing at this point:
i
mport java.io.*;
import java.util.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
/**
*
* @author
* @version September 8, 2005, 11:54 PM
*/
class MyPanel extends JPanel
{
String imageFilePath = "C:/MyDocuments/MemoryGame/woodTable.gif";
ImageIcon icon;
Image img;
public MyPanel()
{
icon = new ImageIcon(imageFilePath);
img = icon.getImage();
}
public void paint(Graphics g)
{
super.paint(g);
g.drawImage(img, 300, 200, this);
}
}
And Then My JFrame class
import java.io.*;
import java.util.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
/**
*
* @author
* @version September 8, 2005, 10:40 PM
*/
public class memGame extends JFrame
{
/** Creates a new instance of memGame */
public memGame()
{
super("Mario Memory Game");
Container win = getContentPane();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(640,480);
MyPanel mp = new MyPanel();
mp.repaint();
win.add(mp);
JMenuBar menuBar = new JMenuBar();
JMenu gMenu = new JMenu("Game");
JMenu gMenu2 = new JMenu("Extra");
JMenuItem newG = new JMenuItem("New Game");
JMenuItem quit = new JMenuItem("Quit Game");
JMenuItem help = new JMenuItem("Help");
JMenuItem about = new JMenuItem("About");
gMenu.add(newG);
gMenu.add(quit);
gMenu2.add(help);
gMenu2.add(about);
menuBar.add(gMenu);
menuBar.add(gMenu2);
setJMenuBar(menuBar);
}
public void ActionPerformed(ActionEvent e)
{
}
}
An lastly i have my main method which just calls an instance of my JFrame class, and then setVisibile(true)
If Anyone could tell me why it wont write the image, and how to remedy it, I would much appreciate. Thanks