java设置窗口按钮_java设置关闭窗口按钮

packagenoname;importjava.awt.*;importjava.awt.event.*;publicclassmainprogramextendsFrameimplementsActionListener,WindowListener{inti;Buttonb1=newButton("确定");Buttonb2=n...

package noname;

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)

{

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();

}

}

这里面的b1已经设置了监听,如何把b2设置为关闭窗口的按钮

展开

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值