I am coding one applet that will show the number of mouse clicks on a button, and another that will show the coordinates of a mouse click and change the background color to a random color.
In both cases, I encountered the "is not abstract and does not override abstract method" error in BlueJ, and I need help understanding what I am doing wrong. I'm very new to this, so any tips/proofreadings are welcome as well :)
here's the first applet:
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Option1 extends Frame implements ActionListener {
public void main (String[] args) {
int click = 0;
JFrame base = new JFrame ("Button Click Counter");
base.getContentPane().setLayout(null);
base.setSize(500,500);
base.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JButton button = new JButton("Click Me!");
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed (ActionEvent e) {
click++; }
});
JTextField count = new JTextField(click);
this.add(button);
this.add(count);
}}
and the coordinates one:
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.util.Random;
public class Option2 extends Frame implements MouseListener {
double x;
double y;
public void init() {
addMouseListener(this);
JFrame base = new JFrame("Mouse Coordinates");
base.getContentPane().setLayout(null);
base.setSize(500,500);
base.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JTextField answer = new JTextField(x + "," + y);
}
public void mouseClicked( MouseEvent e ) {
x = e.getX();
y = e.getY();
this.setBackground(new Color((int)(Math.random() * 0x1000000)));
}}
Thanks in advance!