
正文
java关闭键代码 java点击按钮关闭jpanel
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
java设置关闭窗口按钮
package org.t20110219.test;
/**
* 修改后的代码
* 能关闭,
* 希望能帮助你
*/
import java.awt.*;
import java.awt.event.*;
public class MainProgram extends Frame implements ActionListener,WindowListener
{
int i;
Button b1 = new Button("确定");
Button b2 = new Button("关闭");
void FlowLayoutEX()
{
this.setTitle("布局管理器");
this.setLayout(new FlowLayout());
this.add(b1);
b1.addActionListener(this);
this.add(b2);
b2.addActionListener(this);
this.addWindowListener(this);
this.setBounds(100, 100, 250, 250);
this.setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
/**------------修改代码--------------*/
/**
* 修改 合理就可以了
* e.getSource() 可以得到 你点击了哪个 按钮
* 判断之后就可以 设定 对应的 操作了
*/
if(e.getSource()==b2){
System.exit(0);
}else{
i++;
Button bi = new Button("按钮"+i);
this.add(bi);
this.show(true);
}
}
public void windowClosing(WindowEvent f)
{
System.exit(0);
}
public void windowOpened(WindowEvent f){}
public void windowClosed(WindowEvent f){}
public void windowIconified(WindowEvent f){}
public void windowDeiconified(WindowEvent f){}
public void windowActivated(WindowEvent f){}
public void windowDeactivated(WindowEvent f){}
public static void main(String args[])
{
MainProgram window = new MainProgram();
window.FlowLayoutEX();
}
}
相关问答
Q1: 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);
//继承JFrame的关闭窗口代码
//fr.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//继承Frame的
fr.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);//退出系统
}
});
fr.setVisible(true);
}
public FirstFrame(String str) {
super(str);
}
}
Q2: JAVA 中 按回车键退出的 程序代码怎么写?
import java.io.IOException;
public class TestEnter {
public static void main(String[] args) throws IOException{
while(true){
if(System.in.read() == '\n')
System.exit(0);
}
}
}
关于java关闭键代码和java点击按钮关闭jpanel的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。







