Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
import java.awt.Container; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Point; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.awt.geom.Rectangle2D; import java.awt.geom.RectangularShape; import javax.swing.JFrame; import javax.swing.JPanel; class Targets{ int x; int y; RectangularShape shape; Targets next; Targets(){ next = null; } Targets(int x, int y){ next = null; shape = new Rectangle2D.Double(x, y, 30.0,30.0); } } public class step09Sample { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub JFrame frame = new MyDrawFrame(); frame.setVisible(true); } } class MyDrawFrame extends JFrame{ // private static final long serialVersionUID = 1L; private DrawPanel panel; MyDrawFrame(){ setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setTitle("test"); setSize(300, 300); Container contentPane = getContentPane(); panel = new DrawPanel(); contentPane.add(panel,"Center"); } } class DrawPanel extends JPanel implements MouseListener{ private Rectangle2D box; Targets first,current,last; DrawPanel(){ addMouseListener(this); first = null; current = last = null; } public void paintComponent(Graphics g){ super.paintComponent(g); Graphics2D g2 = (Graphics2D)g; Targets cur; cur = first; while(cur != null){ g2.draw(cur.shape); cur = cur.next; } } public void mouseClicked(MouseEvent e){ Point p = e.getPoint(); boolean isHit = false; if(first == null){ first = new Targets(p.x,p.y); last = first; } else { current = new Targets(p.x, p.y); last.next = current; last = current; } repaint(); return; } public void mouseReleased(MouseEvent e){} public void mouseEntered(MouseEvent e){} public void mouseExited(MouseEvent e){} public void mousePressed(MouseEvent e){} }