Question

can you please help with this, I have a problem with declaration error for JApplet. It gives the error on the Odometer line: "Multiple markers at this line - Syntax error on token(s), misplaced construct(s) - The serializable class Odometer does not declare a static final serialVersionUID field of type long". Thanks

<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);
   }
}>
Was it helpful?

Solution

Remove < from this line <import javax.swing.JApplet;

and if OdometerPanel is not in seprate file then move to top the following lines of code

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

oh missed this one

Remove the > from this line }>

OTHER TIPS

If both classes are in the same file, put all these imports at the top op the file

import javax.swing.JPanel;
import java.awt.Font;
import java.awt.Graphics;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top