各位大侠这段代码怎么解决错误:
import java.awt.Dimension;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Date;
import java.text.SimpleDateFormat;
import javax.management.timer.Timer;
import javax.swing.JPanel;
public class ChangePanel extends JPanel{
String message="00:00:00";
int x=20;
int y=20;
public ChangePanel(){
Timer timer=new Timer(1000,new TimerListener());
timer.start();
}
protected void paintComponent(Graphics g){
super.paintComponent(g);
SimpleDateFormat sdf = new SimpleDateFormat(" kk:mm:ss");
Date d = new Date(System.currentTimeMillis());
String ss = sdf.format(d);
String hour=ss.substring(1, 3);
String minute=ss.substring(4, 6);
String second=ss.substring(7, 9);
String s1=":";
String s2=s1.concat(second);
String s3=minute.concat(s2);
String s4=s1.concat(s3);
String s5=hour.concat(s4);
g.drawString(s5, 20, 20);
}
class TimerListener implements ActionListener{
@Override
public void actionPerformed(ActionEvent e) {
repaint();
}
}
}
求技术分 |
|