幫翻譯java裡的這一段程式碼

我只打出下面一小段 不懂的地方是 ( hoursInput.getText() );

這個地方可以更換成( event.getActionCommand());

這2個為什麼會一樣呢

麻煩java高手幫忙解釋翻譯一下

public void actionPerformed( ActionEvent event )

{

double hours = Double.parseDouble( hoursInput.getText() );

fee = calculat( hours );

totalReceipts += fee;

showStatus( \"當前的費用: \" + fee +

\"; 全部收到之款: \" + totalReceipts );

}

1 Answer

Rating
  • Jeremy
    Lv 4
    1 decade ago
    Best Answer

    就目前所知是一樣的 (?)

    從JButton元件來看,要取得文字可以使用getActionCommand()

    從JRadioButton元件來看,要取得文字可以使用getActionCommand()

    從JCheckBox元件來看,要取得文字可以使用getActionCommand()

    當這些元件引發事件時,ActionListener在收到事件後可以由getActionCommand()來取得文字,這是從ActionEvent事件來看待這些含有addActionListen方法的物件。

    JDK文件

    -----------------------------------------------------------------------------------------------------------

    public String getActionCommand()

    Returns the command string associated with this action. This string allows a "modal" component to specify one of several commands, depending on its state. For example, a single button might toggle between "show details" and "hide details". The source object and the event would be the same in each case, but the command string would identify the intended action.

    Returns:

      the string identifying the command for this event

    Source(s): me & JDK.Docs
Still have questions? Get your answers by asking now.