# Using JPanels
JLabels are okay if you want to simply display images. There are lot of things you can't do with them, however. For example, you can't make the images move around, like the ghosts in a game of Pac-Man. Nor can you draw on JLabels, like in the program Paint. To do these things, you need to draw directly on a component. You could draw directly on the JFrame, however it is better practice to create a canvas to draw on. In Java, we tend to use a JPanel.
There are some things you will need to do before you can begin drawing...
### First, create a new class that extends the JPanel class...
_Note that I've included the paintComponent Method!_
```java
import java.awt.Graphics;
import javax.swing.JPanel;
public class MyPanel extends JPanel {
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawString("This is a panel",10,20);
g.fillOval(10,40,100,100);
}
}
```
### **Second, add your MyPanel class to your MyFrame**
I've included a JLabel, just for fun...
```java
import java.awt.BorderLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class MyFrame extends JFrame {
MyFrame() {
this.setSize(250,200);
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLayout(new BorderLayout());
JLabel lbl = new JLabel("Example of a Label");
this.add(lbl,BorderLayout.NORTH);
MyPanel panel = new MyPanel();
this.add(panel, BorderLayout.CENTER);
}
}
```
If you run an instance of your MyFrame, and you've done everything correctly, you should see something like this...
![[SampleJPanel.png|300]]