So I am trying to make a copy of a game (http://www.aimbooster.com/) for a final project in a class, but I cannot think for the life of me how I make the targets. I have tried a paint component but there is no way to click a paint component. Does anyone have some ideas? Here is my code
package Final_Project;
import javax.swing.JFrame;
public class AimFrame
{
public static void main(String[] args)
{
{
JFrame frame = new JFrame("Aim Booster");
frame.setDefaultCloseOperation(3);
frame.getContentPane().add (new AimPanel(600,600));
frame.pack();
frame.setVisible(true);
}
}
}
And the main code is
package Final_Project;
import java.awt.*;
import java.awt.event.*;
import java.util.ArrayList;
import javax.swing.*;
public class AimPanel extends JPanel
{
private int width, height;
private int px, py, pw, ph;
private Timer circletimer;
private Timer targettimer;
private ArrayList<Point> circles;
private ArrayList<Point> targets;
public AimPanel(int width, int height)
{
this.width = width;
this.height = height;
this.setPreferredSize(new Dimension(width, height));
this.setBackground(Color.gray);
px = 0;
py = 0;
pw = ph = 50;
this.addMouseListener(new ClickListener());
circles = new ArrayList<Point>();
circletimer = new Timer (3000,new circlelistener());
targettimer = new Timer (5000, new circlelistener());
targets = new ArrayList<Point>();
}
public void paintComponent(Graphics g)
{
super.paintComponent(g);
g.setColor(Color.black);
for(int i = 0; i < circles.size(); i++)
{
g.fillOval(circles.get(i).x, circles.get(i).y - 10, 10, 10);
}
super.paintComponent(g);
g.setColor(Color.orange);
for(int i = 0; i < targets.size(); i++)
{
g.fillRect(targets.get(i).x, targets.get(i).y -50, 50, 50);
}
}
private class ClickListener implements MouseListener
{
@Override
public void mouseClicked(MouseEvent e)
{
}
@Override
public void mousePressed(MouseEvent e)
{
System.out.println("Clicked");
//add points to circle list
circles.add(new Point(e.getX(), e.getY()));
circletimer.start();
repaint();
}
@Override
public void mouseReleased(MouseEvent e)
{
}
@Override
public void mouseEntered(MouseEvent e)
{
}
@Override
public void mouseExited(MouseEvent e)
{
}
}
private class circlelistener implements ActionListener
{
@Override
public void actionPerformed(ActionEvent e)
{
if (circles.size()>0)
circles.remove(0);
repaint();
}
}
}