zoukankan      html  css  js  c++  java
  • FocusListener焦点监听器

    【FocusListener焦点监听器】

    public class Demo extends JFrame {
        public Demo(){
            setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
            setBounds(100,100,200,120);
    
            Container c=getContentPane();
    c.setLayout(new FlowLayout());
    JTextField sk1
    =new JTextField();
    JTextField sk2
    =new JTextField();
    JTextField sk3
    =new JTextField();
    sk1.setColumns(
    15);
    sk2.setColumns(
    15);
    sk3.setColumns(
    15);
    c.add(sk1);
    c.add(sk2);
    c.add(sk3);
    sk1.addFocusListener(
    new myFocusListenera() );//调用自定义焦点监听方法类
    sk2.addFocusListener(
    new myFocusListener());
    sk3.addFocusListener(
    new myFocusListener());
             setVisible(true);
         }
    //在myFocusListener 上 ,按Alt+Ins导入Java类快捷键 implements FocusListener
          class  myFocusListener implements FocusListener{//实现焦点监听 有光标点击为绿色,无光标点击为红色。
         @Override
            public void focusGained(FocusEvent e) {
              JTextField sk=(JTextField) e.getSource();//获取触发焦点事件的控件,强制转换为文本
               sk.setBorder(BorderFactory.createLineBorder(Color.green));
            }
    
            @Override
            public void focusLost(FocusEvent e) {
              JTextField sk=(JTextField) e.getSource();//获取焦点事件触发的控件。强制转换为文本
                sk.setBorder(BorderFactory.createLineBorder(Color.RED));
            }
        }
        public static void main(String[] args) {
            new Demo();
        }
    }
            
  • 相关阅读:
    ASP.NET MVC简介
    jQuery
    C#webform LinQ
    webform LinQ
    C# WebForm内置对象2+Repeater的Command
    C#WebForm内置对象
    JavaScricp
    Webform 内置对象 Session对象、Application全局对象,ViewState
    Webform 内置对象 Response对象、Request对象,QueryString
    WebForm复杂控件
  • 原文地址:https://www.cnblogs.com/mld1040871703/p/10230765.html
Copyright © 2011-2022 走看看