<i id='r6GpY'><tr id='r6GpY'><dt id='r6GpY'><q id='r6GpY'><span id='r6GpY'><b id='r6GpY'><form id='r6GpY'><ins id='r6GpY'></ins><ul id='r6GpY'></ul><sub id='r6GpY'></sub></form><legend id='r6GpY'></legend><bdo id='r6GpY'><pre id='r6GpY'><center id='r6GpY'></center></pre></bdo></b><th id='r6GpY'></th></span></q></dt></tr></i><div id='r6GpY'><tfoot id='r6GpY'></tfoot><dl id='r6GpY'><fieldset id='r6GpY'></fieldset></dl></div>
<legend id='r6GpY'><style id='r6GpY'><dir id='r6GpY'><q id='r6GpY'></q></dir></style></legend>
    1. <small id='r6GpY'></small><noframes id='r6GpY'>

        <bdo id='r6GpY'></bdo><ul id='r6GpY'></ul>
    2. <tfoot id='r6GpY'></tfoot>

        getSource() 和 getActionCommand()

        the getSource() and getActionCommand()(getSource() 和 getActionCommand())
        <i id='ChF4Z'><tr id='ChF4Z'><dt id='ChF4Z'><q id='ChF4Z'><span id='ChF4Z'><b id='ChF4Z'><form id='ChF4Z'><ins id='ChF4Z'></ins><ul id='ChF4Z'></ul><sub id='ChF4Z'></sub></form><legend id='ChF4Z'></legend><bdo id='ChF4Z'><pre id='ChF4Z'><center id='ChF4Z'></center></pre></bdo></b><th id='ChF4Z'></th></span></q></dt></tr></i><div id='ChF4Z'><tfoot id='ChF4Z'></tfoot><dl id='ChF4Z'><fieldset id='ChF4Z'></fieldset></dl></div>

        <tfoot id='ChF4Z'></tfoot>
      1. <legend id='ChF4Z'><style id='ChF4Z'><dir id='ChF4Z'><q id='ChF4Z'></q></dir></style></legend>

                <bdo id='ChF4Z'></bdo><ul id='ChF4Z'></ul>
              • <small id='ChF4Z'></small><noframes id='ChF4Z'>

                    <tbody id='ChF4Z'></tbody>
                • 本文介绍了getSource() 和 getActionCommand()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  什么是getSource?它返回什么?

                  What is getSource? and what does it return?

                  什么是getActionCommand(),它返回什么??

                  and what is getActionCommand() and what does it return??

                  我对这两者感到困惑,任何人都可以给我或区分它们吗?UI 中的 getSource 和 getActionCommand() 有什么用?具体是 TextField 还是 JTextField?

                  I am getting confused between these two can anyone give or differentiate them to me? what's the use of getSource and getActionCommand() in UI's? specifically TextField or JTextField?

                  推荐答案

                  假设你说的是 ActionEvent 类,那么这两种方法有很大区别.

                  Assuming you are talking about the ActionEvent class, then there is a big difference between the two methods.

                  getActionCommand() 给你一个代表动作命令的字符串.该值是特定于组件的;对于 JButton 您可以选择使用 setActionCommand(String command) 设置值,但对于 JTextField 如果您不设置此值,它会自动为您提供文本字段的值.根据 javadoc,这是为了与 java.awt.TextField 兼容.

                  getActionCommand() gives you a String representing the action command. The value is component specific; for a JButton you have the option to set the value with setActionCommand(String command) but for a JTextField if you don't set this, it will automatically give you the value of the text field. According to the javadoc this is for compatability with java.awt.TextField.

                  getSource()ActionEvent 是子级的 EventObject 类指定(通过 java.awt.AWTEvent).这为您提供了对事件来自的对象的引用.

                  getSource() is specified by the EventObject class that ActionEvent is a child of (via java.awt.AWTEvent). This gives you a reference to the object that the event came from.

                  这是一个例子.有两个字段,一个具有明确设置的操作命令,另一个没有.在每个中输入一些文本,然后按 Enter.

                  Here is a example. There are two fields, one has an action command explicitly set, the other doesn't. Type some text into each then press enter.

                  public class Events implements ActionListener {
                  
                    private static JFrame frame; 
                  
                    public static void main(String[] args) {
                  
                      frame = new JFrame("JTextField events");
                      frame.getContentPane().setLayout(new FlowLayout());
                  
                      JTextField field1 = new JTextField(10);
                      field1.addActionListener(new Events());
                      frame.getContentPane().add(new JLabel("Field with no action command set"));
                      frame.getContentPane().add(field1);
                  
                      JTextField field2 = new JTextField(10);
                      field2.addActionListener(new Events());
                      field2.setActionCommand("my action command");
                      frame.getContentPane().add(new JLabel("Field with an action command set"));
                      frame.getContentPane().add(field2);
                  
                  
                      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                      frame.setSize(220, 150);
                      frame.setResizable(false);
                      frame.setVisible(true);
                    }
                  
                    @Override
                    public void actionPerformed(ActionEvent evt) {
                      String cmd = evt.getActionCommand();
                      JOptionPane.showMessageDialog(frame, "Command: " + cmd);
                    }
                  
                  }
                  

                  这篇关于getSource() 和 getActionCommand()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Lucene Porter Stemmer not public(Lucene Porter Stemmer 未公开)
                  How to index pdf, ppt, xl files in lucene (java based or python or php any of these is fine)?(如何在 lucene 中索引 pdf、ppt、xl 文件(基于 java 或 python 或 php 中的任何一个都可以)?)
                  KeywordAnalyzer and LowerCaseFilter/LowerCaseTokenizer(KeywordAnalyzer 和 LowerCaseFilter/LowerCaseTokenizer)
                  How to search between dates (Hibernate Search)?(如何在日期之间搜索(休眠搜索)?)
                  How to get positions from a document term vector in Lucene?(如何从 Lucene 中的文档术语向量中获取位置?)
                  Java Lucene 4.5 how to search by case insensitive(Java Lucene 4.5如何按不区分大小写进行搜索)

                    <i id='qOfpC'><tr id='qOfpC'><dt id='qOfpC'><q id='qOfpC'><span id='qOfpC'><b id='qOfpC'><form id='qOfpC'><ins id='qOfpC'></ins><ul id='qOfpC'></ul><sub id='qOfpC'></sub></form><legend id='qOfpC'></legend><bdo id='qOfpC'><pre id='qOfpC'><center id='qOfpC'></center></pre></bdo></b><th id='qOfpC'></th></span></q></dt></tr></i><div id='qOfpC'><tfoot id='qOfpC'></tfoot><dl id='qOfpC'><fieldset id='qOfpC'></fieldset></dl></div>

                    • <small id='qOfpC'></small><noframes id='qOfpC'>

                          <tbody id='qOfpC'></tbody>

                        • <bdo id='qOfpC'></bdo><ul id='qOfpC'></ul>
                          <tfoot id='qOfpC'></tfoot>
                          <legend id='qOfpC'><style id='qOfpC'><dir id='qOfpC'><q id='qOfpC'></q></dir></style></legend>