java窗口监听器的简单例子

  package javaFrame;

  import java.awt.*;

  import javax.swing.*;

  import java.awt.event.*;

  import java.awt.FlowLayout;

  public class FrameEx2 implements ActionListener{

  JFrame jf;

  JPanel jp;

  JButton button1,button2;

  TextArea tf1;

  public FrameEx2(){

  jf = new JFrame("小小菜");

  button1 = new JButton("我得");

  button2 = new JButton("你得");

  Label label1 = new Label("监听器听到");

  tf1 = new TextArea();

  jp = new JPanel();

  jf.setVisible(true);

  button1.addActionListener(new secondbutton());

  button2.addActionListener(new firstbutton());

  jp.add(button1);

  jp.add(button2);

  jf. setLayout(new GridLayout(5,1));

  jf.add(label1);

  jf.add(tf1);

  jf.add(jp);

  jf.setSize(500,300);

  }

  public static void main(String[] args) {

  FrameEx2 action = new FrameEx2();

  }

  public void actionPerformed(ActionEvent e) {

  }

  class secondbutton implements ActionListener{

  public void actionPerformed(ActionEvent e) {

  tf1.append("这是左边,"+e.getActionCommand()+"\n\n");

  }

  }

  class firstbutton implements ActionListener{

  public void actionPerformed(ActionEvent e) {

  tf1.append("这是右边,"+e.getActionCommand()+"\n\n");

  }

  }

  }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值