Can it be done? I tried doing this, but it gives a compilation error:
Timer t = new Timer(1000,new ActionListener() {
public void actionPerformed(ActionEvent event) {
}
});
Here's the entire code for reference
Full Code:
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Timer;
import javax.swing.JComponent;
import javax.swing.JFrame;
public class Scratch {
public static void main(String[] args) {
JFrame frame = new JFrame("Moving Rectangle");
frame.setSize(1000,700);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(new JComponent() {
public void paintComponent(Graphics g) {
Graphics2D g2 = (Graphics2D) g;
}
});
Timer t = new Timer(1000,new ActionListener() {
public void actionPerformed(ActionEvent event) {
}
});
}
}
I need to type something as my question is mostly code.
It says that the constructor is undefined- makes no sense to me because I copied and pasted the code and it compiled fine. Post a proper SSCCE that demonstrates the problem. You muse have other problems, maybe a missing import statement. So basically create a main() method and add the code to the method and get to compile.