易截截图软件、单文件、免安装、纯绿色、仅160KB

java 窗口关闭的六种方法

1.使用JFrame的enableEvents和processWindowEvent
//Frame1.java
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Frame1 extends JFrame {
  public Frame1() {
    enableEvents(AWTEvent.WINDOW_EVENT_MASK);
    this.setSize(new Dimension(400, 300));
    this.setTitle("Frame1");
  }
  protected void processWindowEvent(WindowEvent e) {
    super.processWindowEvent(e);
    if (e.getID() == WindowEvent.WINDOW_CLOSING) {
      System.exit(0);
    }
  }
}
2.直接实现WindowListener接口
//Frame1.java
import java.awt.*;
import java.awt.event.*;
public class Frame1 extends Frame implements WindowListener {
  public Frame1() {
    this.setSize(new Dimension(400, 300));
    this.setTitle("Frame1");
    this.addWindowListener(this);
  }
  public void windowClosing(WindowEvent windowEvent) {
    System.exit(0);
  }
  public void windowOpened(WindowEvent windowEvent) {  }
  public void windowClosed(WindowEvent windowEvent) {  }
  public void windowIconified(WindowEvent windowEvent) {  }
  public void windowDeiconified(WindowEvent windowEvent) {  }
  public void windowActivated(WindowEvent windowEvent) {  }
  public void windowDeactivated(WindowEvent windowEvent) {  }
}
3.直接继承窗体适配器WindowAdapter
//Frame1.java
import java.awt.*;
import java.awt.event.*;
public class Frame1 extends  WindowAdapter {
  public Frame1() {
    Frame f=new Frame();
    f.setSize(new Dimension(400, 300));
    f.setTitle("Frame1");
    f.addWindowListener(this);
    f.setVisible(true);
  }
  public static void main(St


相关文档:

Java Network Game Programming

game
server responsibility:
Initialize
the server socke;

Wait
for a client to connect;

Accept
the client connection;

Create
a daemon thread to support the clien;

Go
back to step 2.

game daemon responsibility:
Accept
client player connection;

Pair ......

Java编程那些事儿102——网络编程技术1

13.2.1 网络编程步骤
         按照前面的基础知识介绍,无论使用TCP方式还是UDP方式进行网络通讯,网络编程都是由客户端和服务器端组成。当然,B/S结构的编程中只需要实现服务器端即可。所以,下面介绍网络编程的步骤时,均以C/S结构为基础进行介绍。
     ......

java类、抽象类、接口、继承和对象解析(转)

这不是什么教材,笔者有时会在论坛上瞧瞧,看到不少初学者问到很多问题,这些问题是java程序员应该懂得的,而一般书上不会讲到或者一笔带过的知识。因此斗胆涂鸦一篇文章,把想说的在这里一口气说完。这也是本人第一次写技术性的文章,文笔不畅之外,还请各位见谅。
首先讲清楚类和对象的区别。
类是广泛的概念,表示一个 ......

基础 JAVA程序


1.编程界最著名的一句话“Hello world!”,任何一个程序员起步时必遇的语句
public class HelloWorld {

public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.print("Hello World!");
......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号