急问!怎样让JLabel里的数字不停的变化!? 实现个RUNABLE接口,用线程不停的刷新 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 package com.moment.test;import javax.swing.*;import java.awt.*;import java.awt.event.*;import java.io.InterruptedIOException;public class Lottery extends JFrame implements Runnable{ private JLabel m_l_number = new JLabel("8888"); private JButton m_b_start = new JButton("start"); Thread thread; private boolean m_flag = true; public Lottery() { GridBagLayout gbl = new GridBagLayout(); Container c = getContentPane(); c.setLayout(gbl); thread=new Thread(this); GridBagConstraints gbc = new GridBagConstraints(); gbc.gridwidth = GridBagConstraints.REMAINDER; gbc.fill = GridBagConstraints.BOTH; c.add(this.m_l_number,gbc); m_l_number.setFont(new Font("Arial",Font.BOLD,96)); gbc.fill = GridBagConstraints.NONE; c.add(this.m_b_start,gbc); m_b_start.setFont(new Font("Arial",Font.PLAIN,12)); m_b_start.addMouseListener(new MouseListener(){ public void mouseClicked(MouseEvent e) { } public void mousePressed(MouseEvent e) { } public void mouseReleased(MouseEvent e) { m_b_start.setText("stop"); thread.start(); } public void mouseEntered(MouseEvent e) { } public void mouseExited(MouseEvent e) { } }); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setTitle("Lottery"); setSize(320,320); show(); } public void refresh() { this.getRootPane().updateUI(); this.m_b_start.updateUI(); this.m_l_number.updateUI(); } public void run() { java.util.Random rand = new java.util.Random(); int number = 0; try { while (m_flag) { number = (int) (rand.nextDouble() * 1000); System.out.println(number); m_l_number.setText(String.valueOf(number)); Thread.sleep(1000); //m_flag = true; } }catch(Exception e){} } public static void main(String[] args) { Lottery l = new Lottery(); }} 只能弹出一个Frame的问题 求J2SE-Swing程序混淆打包方法,内详。。 JAVA问题 InetAddress.getAllByName 为什么不正确 java有没有计算方差和标准差的函数? 请帮看一下这个读入文件的程序哪里有错误? 谁能具体讲讲Thread类join()方法的用法吗? 用jswdk的兄弟来帮帮忙吧! 两个double型的值相乘后,有可能得到含科学记数法的的值。如5.2089032519999996E7,怎样让它不显示E7啊? 怎样显示我需要显示的面板 i want to learn Java ! 软件下载量3天突破180,散分
import java.awt.*;
import java.awt.event.*;
import java.io.InterruptedIOException;public class Lottery extends JFrame implements Runnable
{
private JLabel m_l_number = new JLabel("8888");
private JButton m_b_start = new JButton("start");
Thread thread;
private boolean m_flag = true; public Lottery()
{
GridBagLayout gbl = new GridBagLayout();
Container c = getContentPane();
c.setLayout(gbl);
thread=new Thread(this);
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridwidth = GridBagConstraints.REMAINDER; gbc.fill = GridBagConstraints.BOTH;
c.add(this.m_l_number,gbc);
m_l_number.setFont(new Font("Arial",Font.BOLD,96)); gbc.fill = GridBagConstraints.NONE;
c.add(this.m_b_start,gbc);
m_b_start.setFont(new Font("Arial",Font.PLAIN,12)); m_b_start.addMouseListener(new MouseListener(){ public void mouseClicked(MouseEvent e)
{
}
public void mousePressed(MouseEvent e)
{
}
public void mouseReleased(MouseEvent e)
{
m_b_start.setText("stop");
thread.start();
}
public void mouseEntered(MouseEvent e)
{
}
public void mouseExited(MouseEvent e)
{ }
}); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setTitle("Lottery");
setSize(320,320);
show();
} public void refresh()
{
this.getRootPane().updateUI();
this.m_b_start.updateUI();
this.m_l_number.updateUI();
} public void run()
{
java.util.Random rand = new java.util.Random();
int number = 0;
try {
while (m_flag) {
number = (int) (rand.nextDouble() * 1000);
System.out.println(number);
m_l_number.setText(String.valueOf(number));
Thread.sleep(1000);
//m_flag = true;
}
}catch(Exception e){}
} public static void main(String[] args)
{
Lottery l = new Lottery();
}
}