solution for mouseapplet

solution for mouseapplet - pt.y page.fillOval(pt.x-2 pt.y-2...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
import javax.swing.*; import java.awt.*; import java.awt.event.*; public class MouseApplet extends JApplet { public void init() { getContentPane().add(new PointPanel()); setSize(250,150); } } class PointPanel extends JPanel { private Point pt; public PointPanel() { setBackground(Color.yellow); addMouseListener(new PointListener()); } public void paintComponent(Graphics page) { super.paintComponent(page); if (pt != null) //if pt is null, nothing can be drawn. { page.setColor(Color.magenta); page.drawString("("+ pt.x + "," + pt.y + ")", pt.x,
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: pt.y); page.fillOval(pt.x-2, pt.y-2, 4, 4); } } private class PointListener implements MouseListener { public void mousePressed(MouseEvent event) { pt = event.getPoint(); repaint(); } public void mouseReleased(MouseEvent event) {} public void mouseClicked(MouseEvent event) {} public void mouseEntered(MouseEvent event) {} public void mouseExited(MouseEvent event) {} } //end of PointListener } //end of PointPanel...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online