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 }
  • 相关阅读:
    数据库优化
    Oracle语句集锦
    MVC Razor标签
    转载 操作MyBatis基础
    mysql sqlserver Oracle字符串连接
    Word
    部署IIS错误
    => 朗姆达表达式带入符号
    wcf例子01
    idea通过springboot初始化器新建项目
  • 原文地址:https://www.cnblogs.com/dennisac/p/2438059.html
Copyright © 2011-2022 走看看