resources_for_dotclicker
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
resources_for_dotclicker [2022/05/09 15:39] – created frchris | resources_for_dotclicker [2022/05/09 15:42] (current) – frchris | ||
---|---|---|---|
Line 1: | Line 1: | ||
**Dot Clicker** | **Dot Clicker** | ||
- | Here is a dot that has a "is hit" method | + | Here is a dot that has a "is hit" method. If you want an image instead, take a look at this [[https:// |
< | < | ||
import java.awt.Graphics; | import java.awt.Graphics; | ||
Line 46: | Line 46: | ||
< | < | ||
+ | import java.awt.Color; | ||
+ | import java.awt.Font; | ||
import java.awt.Graphics; | import java.awt.Graphics; | ||
- | import java.awt.Color; | + | import java.awt.event.MouseEvent; |
- | public class Dot | + | import java.awt.event.MouseListener; |
+ | import java.util.ArrayList; | ||
+ | import javax.swing.JFrame; | ||
+ | import javax.swing.JPanel; | ||
+ | import javax.swing.Timer; | ||
+ | import java.awt.event.ActionEvent; | ||
+ | import java.awt.event.ActionListener; | ||
+ | public class DotClicker extends JPanel implements MouseListener, | ||
{ | { | ||
- | private int x,y,size; | + | |
- | | + | public static int HEIGHT=600; |
- | * Constructor for objects of class Dot | + | private Font titleFont, regularFont; |
- | */ | + | |
- | public | + | |
+ | | ||
+ | public | ||
{ | { | ||
- | | + | |
- | | + | regularFont = new Font(" |
- | | + | spawn = new Timer(1000,this); |
+ | | ||
+ | dots = new ArrayList< | ||
+ | dots.add(new Dot()); | ||
+ | | ||
+ | expire.start(); | ||
} | } | ||
- | public | + | public |
- | { | + | DotClicker app= new DotClicker(); |
- | | + | JFrame window = new JFrame(" |
- | | + | window.setSize(WIDTH, HEIGHT); |
- | | + | |
+ | | ||
+ | | ||
+ | | ||
} | } | ||
- | public void draw(Graphics g){ | + | public void paintComponent(Graphics g){ |
+ | super.paintComponent(g); | ||
+ | g.setColor(Color.WHITE); | ||
+ | g.fillRect(0, | ||
+ | g.setColor(Color.BLUE); | ||
+ | g.setFont(titleFont); | ||
+ | g.drawString(" | ||
g.setColor(Color.BLACK); | g.setColor(Color.BLACK); | ||
- | g.fillOval(x,y,size,size); | + | g.setFont(regularFont); |
- | } | + | g.drawString(" |
+ | g.drawString(" | ||
+ | //Draw objects | ||
+ | for(Dot d:dots) | ||
+ | | ||
+ | } | ||
+ | |||
/** | /** | ||
- | | + | |
*/ | */ | ||
- | public | + | public |
- | { | + | |
- | | + | public void mouseReleased(MouseEvent e) { |
- | | + | |
- | | + | y=e.getY(); |
+ | | ||
+ | { | ||
+ | if (dots.get(i).isHit(x, | ||
+ | { | ||
+ | hits++; | ||
+ | dots.remove(i); | ||
+ | repaint(); | ||
+ | } | ||
+ | | ||
+ | repaint(); | ||
} | } | ||
+ | public void mouseEntered(MouseEvent e) {} | ||
+ | public void mouseExited(MouseEvent e) { } | ||
+ | public void actionPerformed(ActionEvent e) { | ||
+ | if (e.getSource()==spawn){ | ||
+ | dots.add( new Dot() ); | ||
+ | }else if (dots.size()> | ||
+ | | ||
+ | | ||
+ | } | ||
+ | | ||
+ | } | ||
} | } | ||
- | |||
</ | </ |
resources_for_dotclicker.1652125175.txt.gz · Last modified: 2022/05/09 15:39 by frchris