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

📄 10例子24.txt

📁 这是一本java基础教程 对新手上路有很大帮助
💻 TXT
字号:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Example10_24{
    public static void main(String args[]){
        Win win=new Win();
    }
}
class Win extends JFrame implements KeyListener, FocusListener{
    TextField text[]=new TextField[3];
    JButton b; 
    Win(){
        setLayout(new FlowLayout());
        for(int i=0;i<3;i++){
            text[i]=new TextField(7);
            text[i].addKeyListener(this);  //监视键盘事件
            text[i].addFocusListener(this);//监视焦点事件
            add(text[i]);
        }
        b=new JButton("确定");
        add(b);
        text[0].requestFocusInWindow();
        setBounds(10,10,300,300);
        setVisible(true); 
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
    public void keyPressed(KeyEvent e){
        TextField t=(TextField)e.getSource();
        if(t.getCaretPosition()>=6)
            t.transferFocus(); 
    }
    public void keyTyped(KeyEvent e){}
    public void keyReleased(KeyEvent e){}
    public void focusGained(FocusEvent e){
         TextField text=(TextField)e.getSource();
         text.setText(null); 
    }
    public void focusLost(FocusEvent e){}
}

⌨️ 快捷键说明

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