• 初学java之触发响应事件举例子


    设置一个触发响应事件?

      比如消息框.....

     1 package hello;
     2 import javax.swing.*;
     3 import project.readerListen;
     4 import java.awt.*;
     5 import java.awt.event.*;
     6 class WindGrid extends  JFrame{
     7     
     8     JTextField text;
     9     ActionListener listener;    
    10     
    11     public WindGrid(String title)
    12     {
    13       setTitle(title);
    14       init();
    15       setBounds(40,50,260,270);
    16       setVisible(true);    
    17       setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    18     }    
    19     
    20     void init()
    21     {
    22       text = new JTextField(10);
    23       listener = new ReaderListen();  //自定义的 那个类
    24       setLayout(new FlowLayout());
    25       text.addActionListener(listener);
    26       add(new Label("输入蚊子 "));
    27       add(text);
    28     }
    29 
    30 }
    31 public class test {
    32     public static void main(String args[])
    33     {
    34       new WindGrid("第一个窗口");    
    35     }
    36 }
    View Code
     1 package hello;
     2 
     3 import java.awt.event.ActionEvent;
     4 import java.awt.event.ActionListener;
     5 import javax.swing.*;
     6 public class ReaderListen extends JFrame implements ActionListener 
     7 {
     8 
     9     public void actionPerformed(ActionEvent e)
    10     {
    11     // TODO Auto-generated method stub    
    12         JFrame myjframe;
    13         myjframe = new JFrame();
    14         JTextArea mytest;
    15         mytest =new JTextArea(e.getActionCommand(),8,9);
    16         myjframe.add(mytest);
    17         myjframe.setBounds(20, 30, 200, 300);
    18         myjframe.setVisible(true);
    19         
    20     }
    21 }
    View Code

  • 相关阅读:
    mysql show profiles 使用分析sql 性能
    面向对象三大特征---封装、继承、多态
    http_build_query用法,挺方便的
    请求数据
    多模匹配算法之Aho-Corasick
    php命名空间如何引入一个变量类名?
    MySQL错误:Can't connect to MySQL server (10060)
    Vim完全教程
    路由
    wireshark
  • 原文地址:https://www.cnblogs.com/gongxijun/p/3725549.html
Copyright © 2020-2023  润新知