import java.awt.BorderLayout;
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import javax.swing.*;
public class SketchPad {
public static void main(String[] args) {
SketchPad sketchpad = new SketchPad();
sketchpad.gui();
}
public void gui() {
JFrame mainF = new JFrame();
JMenuBar menuBar = new JMenuBar();
JMenu fileMenu = new JMenu("file");
mainF.setJMenuBar(menuBar);
menuBar.add(fileMenu);
mainF.getContentPane().add(BorderLayout.CENTER, new DrawP());
mainF.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
mainF.setSize(600,500);
mainF.setVisible(true);
}
class DrawP extends JPanel implements MouseListener, MouseMotionListener {
int mouseX, mouseY;
MouseEvent mouseEvent;
public DrawP() {
addMouseListener(this);
addMouseMotionListener(this);
}
public void paintComponent(Graphics g) {
if(mouseEvent != null)
g.fillOval(mouseX, mouseY, 10, 10);
}
public void mouseClicked(MouseEvent e) {
mouseEvent=e;
mouseX = e.getX();
mouseY = e.getY();
repaint();
}
public void mouseDragged(MouseEvent e) {
mouseClicked(e);
}
public void mousePressed(MouseEvent e){}
public void mouseReleased(MouseEvent e){}
public void mouseEntered(MouseEvent e){}
public void mouseExited(MouseEvent e){}
public void mouseMoved(MouseEvent e) {}
}
}
when i click a mouse i get a picture of JMenuBar. dissapears on resize.
[img]http://img15.imageshack.us/img15/9227/34373644.jpg[/img]
am on vista x64