Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Java SE 综合讨论区 » Java与OOP初步  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 Re:求助(怎么修改才能运行 不能最大化) [Re:binghuo007]
tomcatexpert





发贴: 52
积分: 2
于 2006-04-11 12:32 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
在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.printlnEnvelope;
}
}
}
public static void main(String args[]){
MyThread ab=new MyThread();
}
}


EvilEvil




话题树型展开
人气 标题 作者 字数 发贴时间
6260 求助(怎么修改才能运行 不能最大化) binghuo007 1447 2006-03-18 18:55
5265 Re:求助(怎么修改才能运行 不能最大化) tomcatexpert 1566 2006-04-11 12:32

flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923