gpt4 book ai didi

java JApplet 声明语法错误

转载 作者:行者123 更新时间:2023-11-30 04:05:59 25 4
gpt4 key购买 nike

您能帮忙解决一下吗?我遇到 JApplet 声明错误的问题。它给出了里程表线上的错误:“这条线上有多个标记 - 标记语法错误、构造错误 - 可序列化类里程表未声明静态最终serialVersionUID字段 键入长”。谢谢

<import javax.swing.JApplet;
import javax.swing.Timer;
import java.awt.Color;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class Odometer extends JApplet implements ActionListener{

Timer timer;
public void init() {
OdometerPanel panel = new OdometerPanel();
panel.setBackground(Color.white);
setContentPane(panel);
}
public void start() {
if (timer == null) {
timer = new Timer(100, this);
timer.start();
} else {
timer.restart();
}
}
public void stop() {
if (timer != null) {
timer.stop();
timer = null;
}
}
public void actionPerformed(ActionEvent e) {
repaint();
}
}


import javax.swing.JPanel;
import java.awt.Font;
import java.awt.Graphics;
class OdometerPanel extends JPanel {
long hitCount = 239472938472L;

public void paint(Graphics myGraphics) {
myGraphics.setFont(new Font("Monospaced", Font.PLAIN, 24));
myGraphics.drawString("You are visitor number " +Long.toString(hitCount++), 50, 50);
}
}>

最佳答案

删除<从这一行<import javax.swing.JApplet;

如果 OdometerPanel不在单独的文件中,然后移至以下代码行的顶部

import javax.swing.JPanel;
import java.awt.Font;
import java.awt.Graphics;

哦,错过了这个

删除>从这一行}>

关于java JApplet 声明语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20703415/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com