CS結(jié)構(gòu)系統(tǒng)的退出如下:public void init() {
我們提供的服務(wù)有:成都網(wǎng)站建設(shè)、成都網(wǎng)站設(shè)計(jì)、微信公眾號(hào)開(kāi)發(fā)、網(wǎng)站優(yōu)化、網(wǎng)站認(rèn)證、茂名ssl等。為上千多家企事業(yè)單位解決了網(wǎng)站和推廣的問(wèn)題。提供周到的售前咨詢(xún)和貼心的售后服務(wù),是有科學(xué)管理、有技術(shù)的茂名網(wǎng)站制作公司
this.setTitle("用戶(hù)登錄界面");
this.add(createCenterPane());
this.setDefaultCloseOperation(this.DO_NOTHING_ON_CLOSE);
this.setSize(new Dimension(450, 335));
this.setLocationRelativeTo(null);
// this.setVisible(true);
this.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
int choose = JOptionPane.showConfirmDialog(null, "是否要退出登錄界面?",
"系統(tǒng)提示:", JOptionPane.YES_NO_OPTION);
if (choose == JOptionPane.YES_OPTION) {
System.exit(1);
}
}
});
}其中this為JFrame對(duì)象。BS結(jié)構(gòu)的退出直接用windows.close()方法就行了!
如果是要實(shí)現(xiàn)單擊按鈕退出,建議刪掉這行代碼:
if(e.getActionCommand().equals("Eixt"))
或者,將實(shí)現(xiàn)接口的兩個(gè)類(lèi)變?yōu)閜ublic的內(nèi)部類(lèi),同時(shí)稍微修改下,如下
import java.awt.*;
import java.awt.event.*;
public class lesson1 {
private Frame f;
private Button b;
public lesson1() {
f = new Frame("event");
b = new Button("Exit");
}
public void launchFrame() {
b.addMouseListener(new ButtonHandler());
f.addWindowListener(new ClosingHander());
f.add(b, BorderLayout.CENTER);
f.setSize(400, 300);
f.setVisible(true);
f.setVisible(true);
f.setSize(400, 300);
}
public static void main(String args[]) {
lesson1 aa = new lesson1();
aa.launchFrame();
}
class ButtonHandler extends MouseAdapter {
public void mouseClicked(MouseEvent e)
{
if (e.getSource() == b) {
System.exit(0);
}
}
}
class ClosingHander extends WindowAdapter {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
}
}
如果是點(diǎn)擊上面的那個(gè)叉號(hào)退出的話就加上這樣一句setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
如果是通過(guò)按鈕退出就用監(jiān)聽(tīng)器實(shí)現(xiàn)如:
class MyListener2 implements ActionListener {
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
}
一般情況下這兩種都有。