小弟刚刚接触JAVA,请大哥大姐们多多指教,昨天老师让我们做个模拟抽奖的界面,要求号码不停的跳动,说用swing下的Timer,具体也没说怎么用,那位哥哥指点一下,最好给个类子,谢谢了!
解决方案 »
- 有个java的问题向大家请教,请看文章内容
- 怎么监视数据库的连接阿
- java 字符串传唤成字节数组
- 正式表达式的问题?
- 一个关于文件IO的问题,有兴趣的过来看看!
- JB7做出来的本地可执行文件竟然要依靠jb路径下的jre/hotspot/*???
- 我的目的是,能实现点增加按钮,使得逐行(以行为单位)动态的增加窗体<input type=text ><input type=radio><input type=checkbox>三个
- (已搜贴)用JCreator调试第一个java程序出错:javac: invalid flag: G:\JavaTest\Welcome1.Java???
- applet大问题,急
- 怎样在网页上调用客户机本地可执行文件?
- 遇一烦题,帮忙
- 小弟实在是找不出问题出在哪里。。。
//存在一个LABEL
JLabel ex;
//定义一个子类
new time().start();
}
//子类
class time extends Thread{
public void run(){
while(true){
ex.setText(显示内容);
Thread.sleep(100); //每秒变化10次
}
}
}
import java.awt.event.*;class TimerTest
{
JFrame mainFrame;
JPanel mainPanel;
JLabel label;
Timer timer;
static int count = 0;
public TimerTest() {
mainFrame = new JFrame ( );
mainPanel = new JPanel ();
label = new JLabel ("this is the 0th time the timer executes");
timer = new Timer( 1000, new ActionListener(){
public void actionPerformed( ActionEvent e){
label.setText( String.format("this is the " + count +"th time the timer executes"));
count++;
}
});
timer.setInitialDelay(1000);
timer.start();
mainPanel.add(label);
mainFrame.getContentPane().add( mainPanel );
mainFrame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
mainFrame.setSize(300,100);
mainFrame.setLocationRelativeTo(null);
mainFrame.setVisible( true );
}
public static void main(String[] args)
{
SwingUtilities.invokeLater( new Runnable(){
public void run(){
new TimerTest();
}
});
}
}