j**a 找不到符号

时间:2014.06.16 发布人:yunmenshanx

j**a 找不到符号

已解决问题

谷歌yunmenshanx用户在2014.06.16提交了关于“雪中悍行j**a 找不到符号”的提问,欢迎大家涌跃发表自己的观点。目前共有1个回答,最后更新于2024-11-14T12:48:52。packagech11;
importj**ax.swing.*;
importj**a.awt.*;
importj**a.util.*;

classRefreshTimeThreadextendsThread
{
privateCalendartargetTime;
publicRefreshTimeThread(CalendartargetTime)
{
this.targetTime=targetTime;
}

publicvoidrun()
{
while(true)
{
CalendartodayTime=newGregorianCalendar();
longseconds=(targetTime.getTimeInMillis()-

todayTime.getTimeInMillis())/1000;
if(seconds<=0)
{
label.setText("时间到了!");
bre**;
}
intday=(int)(seconds/(24*60*60));
inthour=(int)(seconds/(60*60)%24);
intmin=(int)(seconds/60%60);
intsec=(int)(seconds%60);
Stringstr=day+"天"+hour+"时"+min+"分"+sec+"秒";
label.setText(str);
try
{
Thread.sleep(1000);
}
catch(InterruptedExceptione)
{
e.printStackTrace();
}
}
}
}

publicclassTimeFrame
{
privateJFramejf;
privateJLabellabel1;
privateJLabellabel;

publicTimeFrame()
{
jf=newJFrame("Time");
label1=newJLabel("距考研还有:");
label=newJLabel("");
jf.add(label1,BorderLayout.NORTh**);
jf.add(label,***.CENTER);
Threadt=newRefreshTimeThread(newGregorianCalendar

(2011,Calendar.JA**ARY,1,0,0,0));
t.start();
}

publicvoidshowMe()
{
jf.setBounds(200,200,300,150);
jf.setVisible(true);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLO**);
}

publicstaticvoidmain(String[]args)
{
newTimeFrame().showMe();
}
}



系统提示ch11\***.j**a:22:找不到符号
符号:变量label
位置:类ch11.RefreshTimeThread
label.setText("时间到了!");
^
ch11\***.j**a:30:找不到符号
符号:变量label
位置:类ch11.RefreshTimeThread
label.setText(str);
^
2错误希望大家能够帮助她。

详细问题描述及疑问:packagech11;
importj**ax.swing.*;
importj**a.awt.*;
importj**a.util.*;

classRefreshTimeThreadextendsThread
{
privateCalendartargetTime;
publicRefreshTimeThread(CalendartargetTime)
{
this.targetTime=targetTime;
}

publicvoidrun()
{
while(true)
{
CalendartodayTime=newGregorianCalendar();
longseconds=(targetTime.getTimeInMillis()-

todayTime.getTimeInMillis())/1000;
if(seconds<=0)
{
label.setText("时间到了!");
bre**;
}
intday=(int)(seconds/(24*60*60));
inthour=(int)(seconds/(60*60)%24);
intmin=(int)(seconds/60%60);
intsec=(int)(seconds%60);
Stringstr=day+"天"+hour+"时"+min+"分"+sec+"秒";
label.setText(str);
try
{
Thread.sleep(1000);
}
catch(InterruptedExceptione)
{
e.printStackTrace();
}
}
}
}

publicclassTimeFrame
{
privateJFramejf;
privateJLabellabel1;
privateJLabellabel;

publicTimeFrame()
{
jf=newJFrame("Time");
label1=newJLabel("距考研还有:");
label=newJLabel("");
jf.add(label1,BorderLayout.NORTh**);
jf.add(label,***.CENTER);
Threadt=newRefreshTimeThread(newGregorianCalendar

(2011,Calendar.JA**ARY,1,0,0,0));
t.start();
}

publicvoidshowMe()
{
jf.setBounds(200,200,300,150);
jf.setVisible(true);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLO**);
}

publicstaticvoidmain(String[]args)
{
newTimeFrame().showMe();
}
}



系统提示ch11\***.j**a:22:找不到符号
符号:变量label
位置:类ch11.RefreshTimeThread
label.setText("时间到了!");
^
ch11\***.j**a:30:找不到符号
符号:变量label
位置:类ch11.RefreshTimeThread
label.setText(str);
^
2错误期待您的答案,希望你能感受到,我最真诚的谢意 !

希望以下的回答,能够帮助你。

第1个回答

用户名:we7qqq  

在不同类中,不能直接调用其它类的私有变量,
你把TimeFrame中的label1改为publicstaticLablelabel,
然后在Refres来自hTimeThread类中直接用类名调用TimeFram载创认编e.label
以下代码测试通过问答:


importj**ax.swing.*;
importj**a.awt.*;
importj**a.util.*;

classRefreshTimeThreadextendsThread
{
private快损极根银含介生CalendartargetTime;
publicRefreshTimeThread(CalendartargetTime)
{
this.targetTime=氧少剂久targetTime;
}

publicvoidrun()
{
while(true)
{
CalendartodayTime=newGregorianC落营队互白初越余艺买alendar();
longseconds=(targetTime.getTimeI绝离笔封红nMillis()-todayTime.getTimeInMillis())/1000;
if(seconds<=0)
{
TimeFrame.label.setT该需ext("时间到了!");
鲁半演特快啊波bre**;
}
intday=(int)(seconds/(24*好清沙旧60*60));
inthour=(int在六帮汽水任)(seconds/(6记息检再少0*60)%24);
intmin=(int)(seconds/60%60);
intsec=(int)(seconds%60);
Stringstr=day+"天"+hour+"时"+min+"分"+sec+"秒";
TimeFrame.label.setText(str);//用类名直接调用
try
{
Thread.sleep(1000);
}
catch(InterruptedExceptione)
{
e.printStackTrace();
}
有围}
}
}

publicclassTimeFrame
{
privateJFr施春曾采amejf;
privateJLabellabel1;
publicstaticJL销胞执降好致血abellabel;//改变label的访问权限

publicTimeFr风果都安杀群怎刘冲示烧ame()
{
jf=newJFrame("Time");
label刚鸡动死果声达1=newJLabel("距考研还有:");
label=newJLabe事章夜数直斤急粒l("");
jf.add(label1,Border社除Layout.NORTh**);
晶美雨呢审众战jf.add(label,***.CENTER);
Threadt=newRefreshTimeThread(newGregorianCalendar(2011,Calendar.JA**ARY,1,0,0,0));
t.start();
}

publicvoidshowMe()
{
jf.setBounds(200,200,300,150);
jf.setVisible(true);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLO**);
}

publicstaticvoidmain(String[]args)
{
newTimeFrame().showMe();
}
}