欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

窗體關(guān)閉代碼java 永遠關(guān)不掉的窗口代碼

JAVA如何用按鈕關(guān)閉窗體

很久沒有用過界面編程了,就當復(fù)習(xí)一下了,哈哈

成都創(chuàng)新互聯(lián)公司專業(yè)為企業(yè)提供沙依巴克網(wǎng)站建設(shè)、沙依巴克做網(wǎng)站、沙依巴克網(wǎng)站設(shè)計、沙依巴克網(wǎng)站制作等企業(yè)網(wǎng)站建設(shè)、網(wǎng)頁設(shè)計與制作、沙依巴克企業(yè)網(wǎng)站模板建站服務(wù),十余年沙依巴克做網(wǎng)站經(jīng)驗,不只是建網(wǎng)站,更提供有價值的思路和整體網(wǎng)絡(luò)服務(wù)。

如一樓所說的,給按鈕加一個監(jiān)聽器ActionListener,寫一個實現(xiàn)方法

actionPerformed.此時當按鈕點擊時會調(diào)用actionPerformed方法,代碼如下:

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

public class Close extends JFrame implements ActionListener{

JButton close;

public Close(){

close = new JButton("close");//增加一個按鈕

add(close);

close.addActionListener(this);//給按鈕增加一個監(jiān)聽器

setLayout(new FlowLayout());

setSize(200,100);

setVisible(true);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

//捕捉到按鈕點擊時的事件處理方法

//按鈕點擊時一定會自動執(zhí)行actionPerformed(ActionEvent e)方法

public void actionPerformed(ActionEvent e){

//關(guān)閉整個應(yīng)用程序.如果只是是想關(guān)閉當前窗口,可以用

//dispose();

System.exit(0);

}

public static void main(String[] args){

new Close();

}

}

java中關(guān)閉當前窗口用什么代碼

你用的 swing 嗎?加上 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

或者加上窗口事件監(jiān)聽器:

addWindowListener(new WindowAdapter() {

public void windowClosing (WindowEvent we) {

dispose();

}

});

java關(guān)閉窗體的六種方法

前段時間集中精力寫了兩篇論文 很久沒寫博文了 現(xiàn)在繼續(xù)了

使用JFrame的enableEvents和processWindowEvent

//Frame java

import java awt *;

import java awt event *;

import javax swing *;

public class Frame extends JFrame {

public Frame () {

enableEvents(AWTEvent WINDOW_EVENT_MASK);

this setSize(new Dimension( ));

this setTitle( Frame );

}

protected void processWindowEvent(WindowEvent e) {

super processWindowEvent(e);

if (e getID() == WindowEvent WINDOW_CLOSING) {

System exit( );

}

}

}

直接實現(xiàn)WindowListener接口

//Frame java

import java awt *;

import java awt event *;

public class Frame extends Frame implements WindowListener {

public Frame () {

this setSize(new Dimension( ));

this setTitle( Frame );

this addWindowListener(this);

}

public void windowClosing(WindowEvent windowEvent) {

System exit( );

}

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) {? }

}

直接繼承窗體適配器WindowAdapter

//Frame java

import java awt *;

import java awt event *;

public class Frame extends? WindowAdapter {

public Frame () {

Frame f=new Frame();

f setSize(new Dimension( ));

f setTitle( Frame );

f addWindowListener(this);

f setVisible(true);

}

public static void main(String[] s){

new Frame ();

}

public void windowClosing(WindowEvent windowEvent) {

System exit( );

}

}

間接繼承窗體適配器WindowAdapter

//Frame java

import java awt *;

import java awt event *;

public class Frame extends? Frame {

public Frame () {

this setSize(new Dimension( ));

this setTitle( Frame );

this addWindowListener(new winAdapter());

this setVisible(true);

}

public static void main(String[] s){

new Frame ();

}

}

class winAdapter extends WindowAdapter{

public void windowClosing(WindowEvent windowEvent) {

System exit( );

}

}

間接實現(xiàn)WindowListener接口

//Frame java

import java awt *;

import java awt event *;

public class Frame extends? Frame {

public Frame () {

this setSize(new Dimension( ));

this setTitle( Frame );

this addWindowListener(new winEventHandle());

this setVisible(true);

}

public static void main(String[] s){

new Frame ();

}

}

class winEventHandle implements WindowListener {

public void windowClosing(WindowEvent windowEvent) {

System exit( );

}

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) {? }

}

使用Inner Class

//Frame java

import java awt *;

import java awt event *;

public class Frame {

public Frame (){

Frame f=new Frame();

f addWindowListener(new WindowAdapter(){

public void windowClosing(WindowEvent e){

System exit( );

}

});

f setSize(new Dimension( ));

f setVisible(true);

}

public static void main(String[] s){

new Frame ();

}

}

Jframe的關(guān)閉方法

setDefaultCloseOperation(EXIT_ON_CLOSE);

frame的關(guān)閉方法如下

this addWindowListener(new java awt event WindowAdapter() {

public void windowClosing(java awt event WindowEvent e) {

System exit( );

}

lishixinzhi/Article/program/Java/hx/201311/27073

文章題目:窗體關(guān)閉代碼java 永遠關(guān)不掉的窗口代碼
文章路徑:http://chinadenli.net/article16/dodspgg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供定制網(wǎng)站、網(wǎng)站維護、網(wǎng)站設(shè)計、云服務(wù)器、企業(yè)網(wǎng)站制作、網(wǎng)站收錄

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

外貿(mào)網(wǎng)站制作