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
相关文档:
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
......
13.2.1 网络编程步骤
按照前面的基础知识介绍,无论使用TCP方式还是UDP方式进行网络通讯,网络编程都是由客户端和服务器端组成。当然,B/S结构的编程中只需要实现服务器端即可。所以,下面介绍网络编程的步骤时,均以C/S结构为基础进行介绍。
......
这不是什么教材,笔者有时会在论坛上瞧瞧,看到不少初学者问到很多问题,这些问题是java程序员应该懂得的,而一般书上不会讲到或者一笔带过的知识。因此斗胆涂鸦一篇文章,把想说的在这里一口气说完。这也是本人第一次写技术性的文章,文笔不畅之外,还请各位见谅。
首先讲清楚类和对象的区别。
类是广泛的概念,表示一个 ......
1.编程界最著名的一句话“Hello world!”,任何一个程序员起步时必遇的语句
public class HelloWorld {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.print("Hello World!");
......