AP Computer Science


Teacher

Marcus Calhoun-Lopez

Resources

Software Requirements

Example Code

import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.Timer;

public class Main extends JPanel implements ActionListener, MouseListener {

	public static void main(String[] args) {
		JFrame frame = new JFrame();
		frame.add(new Main());
		frame.setBounds(100, 100, 400, 200);
		frame.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
		frame.setVisible(true);
	}

	Timer timer;

	public Main() {
		addMouseListener(this);

		timer = new Timer(0, this);
		timer.setInitialDelay(0);
		timer.setDelay(50);
		timer.start();
	}

	public void paintComponent(Graphics g) {
		super.paintComponent(g);
	}

	public void actionPerformed(ActionEvent e) {
		repaint();
	}

	public void mouseClicked(MouseEvent e) {
	}

	public void mouseEntered(MouseEvent e) {
	}

	public void mouseExited(MouseEvent e) {
	}

	public void mousePressed(MouseEvent e) {
	}

	public void mouseReleased(MouseEvent e) {

	}
}