import java.awt.*;
import javax.swing.*;
public class cycle extends JFrame implements ActionListener{
JButton button;
public static void main(String[] args){
cycle cycle1=new cycle();
cycle1.go();
}
public cycle(){
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(400,400);
setVisible(true);
}
public void go(){
button = new JButton("click me");
button.addActionListener(this);
getContentPane().add(button);
}
public void actionPerformed(ActionEvent event) {
repaint();
}
public void paint(Graphics g){
Image image = new ImageIcon("picture1.jpg").getImage();
g.drawImage(image,3,4,this);
int red = (int)(Math.random()*255);
int green = (int)(Math.random()*255);
int blue = (int)(Math.random()*255);
Color randomColor = new Color(red,green,blue);
g.setColor(randomColor);
g.fillOval(70,70,100,100);
}
public void paintComponent(Graphics g){
int red = (int)(Math.random()*255);
int green = (int)(Math.random()*255);
int blue = (int)(Math.random()*255);
Color randomColor = new Color(red,green,blue);
g.setColor(randomColor);
g.fillOval(70,70,100,100);
}
}
cycle.java:20: 错误: 找不到符号
public void actionPerformed(ActionEvent event) {
^
符号: 类 ActionEvent
位置: 类 cycle
cycle.java:3: 错误: cycle不是抽象的, 并且未覆盖ActionListener中的抽象方法actionPerformed()
public class cycle extends JFrame implements ActionListener{
^
cycle.java:16: 错误: 不兼容的类型: cycle无法转换为ActionListener
button.addActionListener(this);
^
注: 某些消息已经过简化; 请使用 -Xdiags:verbose 重新编译以获得完整输出
3 个错误
问题出在哪里啊
换成如下 应该是导错包或者没导包
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class Cycle extends JFrame implements ActionListener {
JButton button;
public static void main(String[] args) {
Cycle cycle1 = new Cycle();
cycle1.go();
}
public Cycle() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(400, 400);
setVisible(true);
}
public void go() {
button = new JButton("click me");
button.addActionListener(this);
getContentPane().add(button);
}
public void actionPerformed(ActionEvent event) {
repaint();
}
public void paint(Graphics g) {
Image image = new ImageIcon("picture1.jpg").getImage();
g.drawImage(image, 3, 4, this);
int red = (int) (Math.random() * 255);
int green = (int) (Math.random() * 255);
int blue = (int) (Math.random() * 255);
Color randomColor = new Color(red, green, blue);
g.setColor(randomColor);
g.fillOval(70, 70, 100, 100);
}
public void paintComponent(Graphics g) {
int red = (int) (Math.random() * 255);
int green = (int) (Math.random() * 255);
int blue = (int) (Math.random() * 255);
Color randomColor = new Color(red, green, blue);
g.setColor(randomColor);
g.fillOval(70, 70, 100, 100);
}
}
接口的方法就一个
public void actionPerformed(ActionEvent event) {
repaint();
}
已经实现了,他说我没实现,而且这里还说找不到符号,不明白
.