⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 10例子7.txt

📁 这是一本java基础教程 对新手上路有很大帮助
💻 TXT
字号:
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Example10_7{
    public static void main(String args[]){
        MyWindow win=new MyWindow();
    }
}
class MyWindow extends JFrame{
    JTextField text; 
    PoliceStation police; 
    MyWindow(){
        setLayout(new FlowLayout());
        text=new JTextField(10);
        police=new PoliceStation();
        add(text);
        text.addActionListener(police);   //text是事件源,police是监视器
        setBounds(100,100,150,150);
        setVisible(true);
        validate();
        setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    }
}
class PoliceStation implements ActionListener {   //PoliceStation类必须要实现ActionListener接口
    public void actionPerformed(ActionEvent e){ 
        String str=e.getActionCommand();
        System.out.println(str);
        System.out.println(str.length()); 
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -