import  com.dbmanage.*;
import java.awt.*;
import java.awt.Font.*;
import java.awt.event.*;
import java.util.Date;
import javax.swing.*;
import java.sql.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.border.*;
import java.awt.event.FocusListener ;
public class HIMSDBA  extends JPanel  implements ActionListener ,FocusListener{
  public int  IDint2;
    public String GLY_Name;
        public  String Sex1;
         public String  JG;
          public  String DZ;
           public  String phone;
               public  String MM;
           public  String E_Mail;
             public  String nowTime1;    Label lable10=new Label("管理员注册界面");
      Label lable1=new Label("管理员名称");
        Label lable11=new Label("性别");
Choice sex=new Choice();
        Label lable2=new Label("籍贯");
        Label lable3=new Label("地址");
        Label lable4=new Label("联系方式");
        Label lable5=new Label("新密码");
        Label lable6=new Label("确认密码");
        Label lable7=new Label("E_Mail");
        JButton Button1=new JButton("注册");
              JButton Button2=new JButton("取消");
              TextField text1=new     TextField (5);
               TextField text2=new     TextField (10);
               TextField text3=new     TextField (20);
               TextField text4=new     TextField (15);
             TextField text5=new     TextField (10);
                TextField text6=new     TextField (10);
                TextField text7=new     TextField (15);
    public   HIMSDBA (){
         text6.setEchoChar('*');
        Box baseBox ,baseBox0 ,boxV0,boxV1,boxV2,boxV3,boxV5,boxV4;
    boxV0=Box.createVerticalBox();
      boxV0.add(lable10);
        lable10.setFont(new java.awt.Font("SansSerif",1,20));
               lable10.setForeground(Color.red);
       boxV1=Box.createVerticalBox();
      boxV1.add(lable1);
       boxV1.add(Box.createVerticalStrut(38));
      boxV1.add(lable11);
      boxV1.add(Box.createVerticalStrut(38));
      boxV1.add(lable2);
      boxV1.add(Box.createVerticalStrut(38));
       boxV1.add(lable3);
      boxV1.add(Box.createVerticalStrut(38));
      boxV1.add(lable4);
        boxV1.add(Box.createVerticalStrut(38));
      boxV1.add(lable5);
       boxV1.add(Box.createVerticalStrut(38));
      boxV1.add(lable6);
        boxV1.add(Box.createVerticalStrut(38));
      boxV1.add(lable7);
      //boxV1.add(Box.createVerticalStrut(138));
     // boxV1.add(button1);
      boxV2=Box.createVerticalBox();      boxV2.add(text1);
             boxV2.add(Box.createVerticalStrut(38));
      boxV2.add(sex);
           boxV2.add(Box.createVerticalStrut(38));
      boxV2.add(text2);
      boxV2.add(Box.createVerticalStrut(38));
      boxV2.add(text3);
      boxV2.add(Box.createVerticalStrut(38));
      boxV2.add(text4);
       boxV2.add(Box.createVerticalStrut(38));
      boxV2.add(text5);
             boxV2.add(Box.createVerticalStrut(38));
      boxV2.add(text6);
             boxV2.add(Box.createVerticalStrut(38));
      boxV2.add(text7);         boxV5=Box.createHorizontalBox();
      boxV5.add(Button1);
      boxV5.add(Box.createHorizontalStrut(60));
     boxV5.add(Button2);      baseBox=Box.createHorizontalBox();
      baseBox.add(boxV1);
      baseBox.add(Box.createHorizontalStrut(2));
      baseBox.add(boxV2);       baseBox0=Box.createVerticalBox();
      baseBox0.add(boxV0);
      baseBox0.add(Box.createVerticalStrut(38));
       baseBox0.add( baseBox);
       baseBox0.add(Box.createVerticalStrut(38));
       baseBox0.add(  boxV5);
      setLayout(new FlowLayout());      add(baseBox0);
      sex.add("男");
            sex.add("女");
            text5.addFocusListener(this);
             Button1.addActionListener(this);
          Button2.addActionListener(this);       }
   public   void focusLost(FocusEvent e)
    {  if(e.getSource()==text6){
           if(!text5.getText().trim().equals(text6.getText().trim()))
           {
           JOptionPane.showMessageDialog(null, "    密码错误!","系统信息", JOptionPane.PLAIN_MESSAGE);
           }       }      }这是其中一段代码,我想密码的文本框实现失去焦点时实现密码校对检验  
不过怎么出现Exception in thread "AWT-EventQueue-0" java.lang.UnsupportedOperationException: Not supported yet.
初学还没用过这个方法。各位大侠帮帮忙!!

解决方案 »

  1.   

    问题一:
    你只给text5添加了FocusListener
    而你的focusLost方法中判断中却只写了事件源为text6的情况
    理论上说,你的这个事件中的代码是永远不会触发的
    你这两个地方至少要一致吧,或者给text也加一下FocusListener问题二:
    你既然实现了FocusListener,ActionListener这两个接口
    那就必须把它们所有的方法都实现
    就是这两个方法
    @Override
    public void actionPerformed(ActionEvent e) {
    // TODO Auto-generated method stub } @Override
    public void focusGained(FocusEvent e) {
    // TODO Auto-generated method stub }
    也可能是楼主的代码没贴全
      

  2.   


    这是一段代码而已,那个ActionListener  我已经实现了,现在改为text6可以实现检验密码,不过为什么还是出现下面的错误呢我是用netsBean的Exception in thread "AWT-EventQueue-0" java.lang.UnsupportedOperationException: Not supported yet.
            at com.HIMSDBA.HIMSDBA.focusGained(HIMSDBA.java:190)
            at java.awt.Component.processFocusEvent(Component.java:6156)
            at java.awt.Component.processEvent(Component.java:6023)
            at java.awt.TextComponent.processEvent(TextComponent.java:659)
            at java.awt.TextField.processEvent(TextField.java:565)
            at java.awt.Component.dispatchEventImpl(Component.java:4630)
            at java.awt.Component.dispatchEvent(Component.java:4460)
            at java.awt.KeyboardFocusManager.redispatchEvent(KeyboardFocusManager.java:1850)
            at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(DefaultKeyboardFocusManager.java:901)
            at java.awt.DefaultKeyboardFocusManager.dispatchEvent(DefaultKeyboardFocusManager.java:513)
            at java.awt.Component.dispatchEventImpl(Component.java:4502)
            at java.awt.Component.dispatchEvent(Component.java:4460)
            at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
            at java.awt.SequencedEvent.dispatch(SequencedEvent.java:101)
            at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
            at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
            at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
            at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
            at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
      

  3.   

    问题出在你的focusGained方法,这个方法你怎么写的……
      

  4.   

     public void focusLost(FocusEvent e)
      { if(e.getSource()==text6){
      if(!text5.getText().trim().equals(text6.getText().trim()))
      {
      JOptionPane.showMessageDialog(null, " 密码错误!","系统信息", JOptionPane.PLAIN_MESSAGE);
      }  }  }
    我这样写对吗?
    if(e.getSource()==text6){
    是这一句错了吧,要怎么改,其实e的方法有几个,失去焦点的我不知写哪个,最后就写了e.getSource()
      

  5.   

    输入不一样时、TAB无法移动焦点。
    import java.awt.*;
    import javax.swing.*;
    import java.util.*;public class SamePassword {
        public static void main(final String[] args) {
    java.awt.EventQueue.invokeLater(new Runnable(){
    public void run(){
        JFrame  frame = new JFrame("Same Password");
        JPanel content = new JPanel(new GridLayout(3,2,5,5));
        content.add(new JLabel("Password"));
        JPasswordField p1 = new JPasswordField();
        content.add(p1);
        content.add(new JLabel("Password Again"));
        JPasswordField p2 = new JPasswordField();
        content.add(p2);
        p2.setInputVerifier(new SamePasswordVerifier(p1));
        content.add(new JButton("Register"));
        content.add(new JButton("Cancel"));
        frame.setContentPane(content);
        frame.pack();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    }
        });
        }
        
        private static class SamePasswordVerifier extends InputVerifier{
    private JPasswordField passwordfield;
    public SamePasswordVerifier(JPasswordField passwordfield){
        this.passwordfield = passwordfield;
    }
    @Override public boolean verify(JComponent input){
        JPasswordField pf = (JPasswordField)input;
        return Arrays.equals(passwordfield.getPassword(),pf.getPassword());
    }
        }