zoukankan      html  css  js  c++  java
  • java 使用ActionListener监控

     1 package test;
    2
    3 import java.awt.Font;
    4 import java.awt.GridLayout;
    5 import java.awt.LayoutManager;
    6 import java.awt.event.ActionEvent;
    7 import java.awt.event.ActionListener;
    8 import java.awt.event.WindowAdapter;
    9 import java.awt.event.WindowEvent;
    10 //import java.util.EmptyStackException;
    11
    12 import javax.swing.JButton;
    13 import javax.swing.JFrame;
    14 import javax.swing.JLabel;
    15 import javax.swing.JPanel;
    16 import javax.swing.JScrollPane;
    17 import javax.swing.JTextArea;
    18 import javax.swing.JTextField;
    19
    20 class ActionHandle{
    21 private JFrame f=new JFrame("Welcome to use Login!");
    22 private JButton but=new JButton("显示");
    23 private JLabel lab=new JLabel();
    24 private JTextField text=new JTextField(10);
    25 private JPanel pan=new JPanel();
    26 public ActionHandle(){
    27 Font fnt=new Font("Serief",Font.ITALIC+Font.BOLD,28);
    28 lab.setFont(fnt);
    29 lab.setText("等待用户输入信息!");
    30 but.addActionListener(new ActionListener() {
    31 public void actionPerformed(ActionEvent e) {
    32 if(arg0.getSource()==but){
    33 lab.setText(text.getText());
    34 }
    35 }
    36 });
    37 f.addWindowListener(new WindowAdapter() {
    38 public void windowClosing(WindowEvent arg0){
    39 System.exit(1);
    40 }
    41 });
    42 f.setLayout(new GridLayout(2,1));
    43 pan.setLayout(new GridLayout(1,2));
    44 pan.add(text);
    45 pan.add(but);
    46 f.add(pan);
    47 f.add(lab);
    48 f.pack();
    49 f.setVisible(true);
    50 }
    51 }
    52 public class test {
    53 public static void main(String[] args) {
    54
    55 new ActionHandle();
    56 }
    57
    58 }
  • 相关阅读:
    .NET 回归
    Smart ORM v0.4.1开发计划
    计算4的1万次方的结果
    GMS Modem 短信收发组件
    计划任务的编成实现
    告别2007,展望2008
    Smart ORM v0.3发布(完全面向对象的轻量级ORM工具)
    Java中委托事件模型 (转)
    刚刚开通了博客,写点东西
    ASP.NET弹出对话框(转)
  • 原文地址:https://www.cnblogs.com/dennisac/p/2438059.html
Copyright © 2011-2022 走看看