java编译时提示错误:找不到符号

2024-12-18 11:14:27
推荐回答(2个)
回答1:

public class clock
{
public static void main(String args[])
{
ClockView cv = new ClockView();
cv.setVisible(true);//这里setVisible错了
try {
for (;;) {
cv.refreshTimeDisply();//这里refreshTimeDisply错了
Thread.sleep(500);
}
} catch (Exception e)
{
System.out.println("Error:" + e);
}
}
}
class ClockView extends javax.swing.JFrame
{
private javax.swing.JLabel tLabel = new javax.swing.JLabel();
ClockView()
{
this
.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
this.setSize(95, 45);
this.getContentPane().add(tLabel);
this.refreshTimeDisply(); //这个单词错了
}
protected String getDigitsAsString(int i)
{
String str = Integer.toString(i);
if (i < 10)
str = "0" + str;
return str;
}
public void refreshTimeDisply() {
Timestamp t = new Timestamp();
t.fillTimes();
String display = getDigitsAsString(t.hrs) + ":"
+ getDigitsAsString(t.mins) + ":"
+ getDigitsAsString(t.secs); // 这个getDigitsAsString写错了
tLabel.setText(" " + display);
tLabel.repaint();
}
}
class Timestamp
{
int hrs, mins, secs;
void fillTimes() {
java.util.Calendar now ; //这个Calendar 错了
now = java.util.Calendar.getInstance() ;
hrs = now.get(java.util.Calendar.HOUR_OF_DAY);
mins = now.get(java.util.Calendar.MINUTE);
secs = now.get(java.util.Calendar.SECOND);
}
}

主要就是几个方法的单词写错了

回答2:

public class clock
{
public static void main(String args[])
{
ClockView cv = new ClockView();
cv.setVisible(true); //大小写
try
{
for (;;)
{
cv.refreshTimeDisply(); //单词拼错,下同
Thread.sleep(500);
}
} catch (Exception e)
{
System.out.println("Error:" + e);
}
}
}
class ClockView extends javax.swing.JFrame
{
private javax.swing.JLabel tLabel = new javax.swing.JLabel();
ClockView()
{
this.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
this.setSize(95, 45);
this.getContentPane().add(tLabel);
this.refreshTimeDisply();
}
protected String getDigitsAsString(int i)
{
String str = Integer.toString(i);
if (i < 10)
str = "0" + str;
return str;
}
public void refreshTimeDisply() {
Timestamp t = new Timestamp();
t.fillTimes();
String display = getDigitsAsString(t.hrs) + ":" //单词拼错
+ getDigitsAsString(t.mins) + ":" + getDigitsAsString(t.secs);
tLabel.setText(" " + display);
tLabel.repaint();
}
}
class Timestamp
{
int hrs, mins, secs;
void fillTimes() {
java.util.Calendar now; //Calendar拼错
now = java.util.Calendar.getInstance();
hrs = now.get(java.util.Calendar.HOUR_OF_DAY);
mins = now.get(java.util.Calendar.MINUTE);
secs = now.get(java.util.Calendar.SECOND);
}
}