Topic: 没定义窗口关闭消息,窗口怎么还能关闭?

  Print this page

1.没定义窗口关闭消息,窗口怎么还能关闭? Copy to clipboard
Posted by: oflyfisho
Posted on: 2005-11-09 00:57

刚刚找到了一个程序,运行了一下,结果发现按右上角的“叉”,窗口也能关闭,我还没定义这个消息呢,怎么就能关闭呢,我刚学java不久,希望高手门指教,谢谢拉,先
import java.awt.*;
import java.applet.*;
import java.util.Date;
public class Clock extends Applet implements Runnable
{
  Thread clockThread;
  Font font;
  public void init()
  {
    font=new Font("TimesRoman",Font.BOLD,48);
    }
  public void start()
  {
    if(clockThread==null)
    {
      clockThread=new Thread(this,"Showtime");
      clockThread.start();
      }
    }
  public void run()
  {
    while(clockThread!=null)
    {
      repaint();
      try
      {
        clockThread.sleep(1000);
        }catch(InterruptedException e){}
      }
    }
  public void paint(Graphics g)
  {
    Date now=new Date();
    g.setFont(font);
    g.setColor(Color.red);
    g.drawString(now.getHours()+":"+now.getMinutes()+":"+now.getSeconds(),5,50);
    
    }
  public void stop()
  {
    clockThread.stop();
    }

}

2.Re:没定义窗口关闭消息,窗口怎么还能关闭? [Re: oflyfisho] Copy to clipboard
Posted by: lfcjecboss
Posted on: 2005-11-09 09:23

你随便运行一个带窗口的程序都可以关闭的,你没有学过其它语言吗,比如delphi
都是一样的,如果程序运行起来了,但没有关闭按钮,那怎么推出程序啊!

3.Re:没定义窗口关闭消息,窗口怎么还能关闭? [Re: oflyfisho] Copy to clipboard
Posted by: wallacer
Posted on: 2005-11-09 10:40

Applet本身已经替你处理了这些基本的事件,所以你在写Applet的时候只要init()就可以了!当然你也可以自己定义Applet的事件处理方式,你可以看Applet的文档!

4.Re:没定义窗口关闭消息,窗口怎么还能关闭? [Re: oflyfisho] Copy to clipboard
Posted by: nicholastse0303
Posted on: 2005-11-20 16:51

extends
是很有用的,同样你写个frame,extends JFrame.就可以直接关闭.

5.Re:没定义窗口关闭消息,窗口怎么还能关闭? [Re: oflyfisho] Copy to clipboard
Posted by: oflyfisho
Posted on: 2005-11-22 23:27


得到答案了,谢谢了

6.Re:没定义窗口关闭消息,窗口怎么还能关闭? [Re: oflyfisho] Copy to clipboard
Posted by: o0烟头0o
Posted on: 2005-11-26 20:49

如果不想直接关闭,要询问下是否真的关闭,点确定才能关,要重下哪个方法呢
在JDialog里


   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