伊莉討論區

標題: [原創] Spot(點) And ClickMe(點我) [打印本頁]

作者: 天晴    時間: 2005-10-16 11:49 PM     標題: [原創] Spot(點) And ClickMe(點我)

演示: http://www.eyny.com/java/demo/ClickMe/ClickMe.html

Source Code

Spot.java
  1. public class Spot {
  2.     public int size;
  3.     public int x, y;

  4.     public Spot(int intSize) {
  5.         size = intSize;
  6.         x = -1;
  7.         y = -1;
  8.     }
  9. }
複製代碼


ClickMe.java
  1. import java.applet.Applet;
  2. import java.awt.*;
  3. import java.awt.event.*;

  4. public class ClickMe extends Applet implements MouseListener {
  5.     private Spot spot = null;
  6.     private static final int RADIUS = 7;

  7.     public void init() {
  8. addMouseListener(this);
  9.     }

  10.     public void paint(Graphics g) {
  11. //draw a black border and a white background
  12.         g.setColor(Color.white);
  13. g.fillRect(0, 0, getSize().width - 1, getSize().height - 1);
  14.         g.setColor(Color.black);
  15. g.drawRect(0, 0, getSize().width - 1, getSize().height - 1);

  16. //draw the spot
  17.         g.setColor(Color.red);
  18. if (spot != null) {
  19.      g.fillOval(spot.x - RADIUS, spot.y - RADIUS, RADIUS * 2, RADIUS * 2);
  20.         }
  21.     }
  22.     public void mousePressed(MouseEvent event) {
  23.         if (spot == null) {
  24.             spot = new Spot(RADIUS);
  25.         }
  26. spot.x = event.getX();
  27. spot.y = event.getY();
  28. repaint();
  29.     }
  30.     public void mouseClicked(MouseEvent event) {}
  31.     public void mouseReleased(MouseEvent event) {}
  32.     public void mouseEntered(MouseEvent event) {}
  33.     public void mouseExited(MouseEvent event) {}
  34. }
複製代碼

作者: 天晴    時間: 2005-10-16 11:52 PM

Source Code
作者: 素娜    時間: 2005-10-17 12:24 AM

提示: 作者被禁止或刪除 內容自動屏蔽
作者: 天晴    時間: 2005-10-17 12:24 AM

Originally posted by 素娜 at 2005-10-17 12:24 AM:
How to make .java to .class ?


使用Compiler!




歡迎光臨 伊莉討論區 (https://db03.eyny.com/) Powered by Discuz!