我需要部分Java代码的帮助. [英] I need help with part of Java code.

查看:74
本文介绍了我需要部分Java代码的帮助.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此代码没有任何错误.我想知道是否有人可以告诉我这是否是使用

I do not get any errors with this code. I was wondering if anyone could tell me if this is the correct way to use the

setFocusTraversalPolicy


的正确方法



class FocusHandler implements FocusListener

    {

        public void focusGained (FocusEvent e)

        {

            if(e.getSource() == lengthField || e.getSource() == widthField)

            {

                areaField.setText("");

            }

            else if (e.getSource() == areaField)

            {

                areaField.setFocusTraversalPolicy(null);

                calculateButton.grabFocus();



                // or maybe calculateButton.requestFocusInWindow();

            }

        }

        public void focusLost(FocusEvent e)

        {

            if(e.getSource() == widthField)

            {

                widthField.setFocusTraversalPolicy(null);

                calculateButton.grabFocus();



            }

        }

    }

推荐答案

这是FocusListener的一部分.它们通常被实现为接口,并称为处理程序.您可以匿名使用它们,或让某些Worker-class获取接口.

在此处阅读: http://docs.oracle.com/javase/tutorial/uiswing/events/focuslistener .html [^ ]

..有关各种侦听器的更多信息.
This is part of a FocusListener. They are often implemented as Interfaces and called Handler. You can use them anonymous or let some Worker-class get the interface.

Read here: http://docs.oracle.com/javase/tutorial/uiswing/events/focuslistener.html[^]

..much much more about Listeners of all kind.


这篇关于我需要部分Java代码的帮助.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆