ok I messed up on the copy paste from one blog to this one the code is
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Lab35C {
JFrame frame;
JButton green;
JButton red;
Dot dot;
public static void main(String[] args) {
Lab35C me = new Lab35C();
me.go();
}
public void go() {
frame = new JFrame("Watch the dot");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(300, 300);
green = new JButton("Green dot");
green.addActionListener(this);
frame.getContentPane().add(green, BorderLayout.NORTH);
red = new JButton("Red dot");
red.addActionListener(this);
frame.getContentPane().add(red, BorderLayout.SOUTH);
dot = new Dot();
frame.getContentPane().add(dot);
frame.setVisible(true);
while (true) {
dot.repaint();
try {
Thread.sleep(50);
}
catch (Exception err) {}
}
}
class Dot extends JPanel {
Color color = Color.blue;
public void paintComponent(Graphics g) {
int height = this.getHeight();
int width = this.getWidth();
g.setColor(Color.white);
g.fillRect(0, 0, width, height);
g.setColor(color);
int randomX = (int) (Math.random() * width);
int randomY = (int) (Math.random() * height);
g.fillOval(randomX, randomY, 30, 30);
}
public void changeColor(Color nColor) {
color = nColor;
}
}
class GreenListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
dot.changeColor(Color.green);
}
}
class RedListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
dot.changeColor(Color.red);
}
}
}
The compile errors I'm getting are
Lab35C.java:22: addActionListener(java.awt.event.ActionListener) in javax.swing.AbstractButton cannot be applied to (Lab35C)
green.addActionListener(this);
^
Lab35C.java:27: addActionListener(java.awt.event.ActionListener) in javax.swing.AbstractButton cannot be applied to (Lab35C)
red.addActionListener(this);
^
2 errors
Thanks for the help, you guys are on this quick