the Graphics below has content, but why can"t I draw a graph?
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Point;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;
import java.awt.image.BufferedImage;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class DrawPanel extends JFrame{
public static void main(String[] args) {
new DrawPanel();
}
public DrawPanel() {
setTitle("");
setSize(600,600);
setResizable(true);
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
createDP();
}
private JPanel panel;
private Point prevPoint;
private Color color;
private int Thickness=10;
private void createDP(){
JPanel tools=new JPanel();
Container cont=getContentPane();
cont.setLayout(null);
panel=new JPanel();
panel.setBackground(Color.BLUE);
panel.setBounds(10, 100, 400, 400);
//
final Graphics2D g=(Graphics2D)createImage(300,300).getGraphics();
//
// BufferedImage buffImg=new BufferedImage(300,300,BufferedImage.TYPE_INT_ARGB);
// final Graphics2D g=(Graphics2D)buffImg.createGraphics();
panel.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
prevPoint=e.getPoint();
g.setColor(Color.RED);
g.fillOval(prevPoint.x, prevPoint.y, Thickness, Thickness);
}
});
panel.addMouseMotionListener(new MouseMotionAdapter() {
@Override
public void mouseDragged(MouseEvent e){
}
});
cont.add(tools,BorderLayout.NORTH);
cont.add(panel);
}
}