
正文
java窗体退出代码 java退出功能
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
实现 界面登陆 退出 功能的java代码杂写
CS结构系统的退出如下:public void init() {
this.setTitle("用户登录界面");
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, "是否要退出登录界面?",
"系统提示:", JOptionPane.YES_NO_OPTION);
if (choose == JOptionPane.YES_OPTION) {
System.exit(1);
}
}
});
}其中this为JFrame对象。BS结构的退出直接用windows.close()方法就行了!
相关问答
Q1: Java记事本代码,窗体关闭功能代码,
如果这个窗体是JFrame或JDialogjava窗体退出代码,那就在构造方法里写
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
如果是Frame或Dialogjava窗体退出代码,那就在WindowListener的windowClosing(WindowEvent)方法里写
this.dispose();
两句话的意思是窗体关闭时释放自身java窗体退出代码,,,而不是退出,不要设成EXIT_ON_CLOSE或System.exit(0);,那样的话窗体关闭会导致整个程序退出。
Q2: 怎样用JAVA编程编写题目:设计一个窗体,在窗体中有个按钮,单击退出按钮,窗体消失
/** 希望 对你有用 同学 一个简单而 但 很 实用的例子 */import java.awt. * ;
import java.awt.event. * ;import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;public class swing extends JFrame { /**
* @param args
*/
JFrame j;
public swing() {
j = new JFrame("close windows");
j.setBounds(100, 100, 100, 100); // 设置 窗体 大小
j.getContentPane().setLayout(new FlowLayout(ABORT)); //设置 布局
JButton jbtn = new JButton();
jbtn.setText("退出");
jbtn.addMouseListener(new MouseAdapter(){ // 鼠标 监听 按下
public void mouseClicked(MouseEvent e) {
// TODO Auto-generated method stub
System.exit(0);
super.mouseClicked(e);
}
});
j.add(jbtn); // 按钮添加到 窗体
j.setVisible(true); // 设置窗体 可见
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable(){
public void run() {
// TODO Auto-generated method stub
new swing();
}
});
}
Q3: 实现界面登陆,退出功能的java代码怎么写?
CS结构系统java窗体退出代码的退出如下:public void init() {
this.setTitle("用户登录界面");
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, "是否要退出登录界面?",
"系统提示:", JOptionPane.YES_NO_OPTION);
if (choose == JOptionPane.YES_OPTION) {
System.exit(1);
}
}
});
}其中this为JFrame对象。BS结构的退出直接用windows.close()方法就行java窗体退出代码了java窗体退出代码!
Q4: Java jframe中如何实现窗口的关闭
效果图
参考代码和注释如下
import java.awt.event.*;
import javax.swing.*;
public class DemoFrame extends JFrame{
JButton jbExit;
public DemoFrame() {
jbExit = new JButton("退出");
//当点击退出 按钮时候的响应器
jbExit.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
doExit();//退出时候的方法
}
});
JPanel jp = new JPanel();
jp.add(jbExit);
add(jp);
setTitle("窗口");// 窗口标题
setSize(380, 185);// 窗口大小
setLocationRelativeTo(null);// 窗口居中
//setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//通常添加这行代码,点击窗口右下角的关闭时会结束程序
setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);//右下角的关闭,不主动采取任何行动
//当点击窗口右上角的关闭按钮时候的响应器
addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
doExit();
}
});
}
// main方法
public static void main(String[] args) {
new DemoFrame().setVisible(true);
}
//退出时候的选择
private void doExit() {
int n = JOptionPane.showConfirmDialog(null, "你确定要退出吗?", "消息提示",JOptionPane.YES_NO_OPTION);
//取消选择是 -1 ,确定是0 ,取消是1
System.out.println(n);
if(n==0) { //如果选择了确定
System.exit(0);//那么退出
}
}
}
Q5: java程序关闭窗口代码
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);
//继承JFramejava窗体退出代码的关闭窗口代码
//fr.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//继承Framejava窗体退出代码的
fr.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);//退出系统
}
});
fr.setVisible(true);
}
public FirstFrame(String str) {
super(str);
}
}
关于java窗体退出代码和java退出功能的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。






