tomcatexpert
发贴: 52
积分: 2
|
于 2006-04-11 12:32
在Constructor里创造新OBJECT,会重复不断的产生Object,直到Memory 用完..
binghuo007 wrote: 请帮忙看一下该怎么修改才能运行,多谢了
import javax.swing.*; import java.util.GregorianCalendar; import java.awt.Font; /** * * @author FC */ public class MyThread extends JFrame implements Runnable{ JPanel panel; JLabel label; GregorianCalendar cld; Font font; String date; String time; /** Creates a new instance of MyThread */ public MyThread() { panel=new JPanel(); label=new JLabel(); cld=new GregorianCalendar(); font=new Font("隶书", Font.ITALIC, 30); getContentPane().add(panel); panel.add(label); label.setFont(font);
MyThread th=new MyThread(); // 问题在这行
Thread td=new Thread(th); td.start(); } void inita(){ date=cld.get(cld.YEAR)+"-"+(cld.get(cld.MONTH)+1)+"-"+cld.get(cld.DATE); time=cld.get(cld.HOUR)+":"+cld.get(cld.MINUTE)+":"+cld.get(cld.SECOND); label.setText("日期:" +date+ "时间:"+time); setVisible(true); setSize(400,400); setDefaultCloseOperation(3); } public void run(){ while(true){ inita(); try{ Thread.sleep(100); } catch(Exception e){ System.out.println; } } } public static void main(String args[]){ MyThread ab=new MyThread(); } }
|