日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
java窗體關(guān)閉代碼 關(guān)閉窗體的代碼

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

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

公司主營業(yè)務(wù):網(wǎng)站制作、網(wǎng)站設(shè)計、移動網(wǎng)站開發(fā)等業(yè)務(wù)。幫助企業(yè)客戶真正實現(xiàn)互聯(lián)網(wǎng)宣傳,提高企業(yè)的競爭能力。創(chuàng)新互聯(lián)是一支青春激揚、勤奮敬業(yè)、活力青春激揚、勤奮敬業(yè)、活力澎湃、和諧高效的團隊。公司秉承以“開放、自由、嚴謹、自律”為核心的企業(yè)文化,感謝他們對我們的高要求,感謝他們從不同領(lǐng)域給我們帶來的挑戰(zhàn),讓我們激情的團隊有機會用頭腦與智慧不斷的給客戶帶來驚喜。創(chuàng)新互聯(lián)推出成縣免費做網(wǎng)站回饋大家。

如一樓所說的,給按鈕加一個監(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

java程序關(guān)閉窗口代碼

import?java.applet.*;

import?java.awt.Color;

import?java.awt.Frame;

import?javax.swing.JFrame;

import?java.awt.event.*;

public?class?FirstFrame?extends?Frame?{

public?static?void?main(String?args[])?{

FirstFrame?fr?=?new?FirstFrame("First?contianer!");

fr.setSize(240,?240);

//繼承JFrame的關(guān)閉窗口代碼

//fr.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

//繼承Frame的

fr.addWindowListener(new?WindowAdapter()?{????

public?void?windowClosing(WindowEvent?e)?{????????

System.exit(0);//退出系統(tǒng)???

}

});

fr.setVisible(true);

}

public?FirstFrame(String?str)?{

super(str);

}

}


新聞標題:java窗體關(guān)閉代碼 關(guān)閉窗體的代碼
鏈接URL:http://www.dlmjj.cn/article/doddhed.html