java中的requestFocus_Java JFormattedTextField.requestFocus方法代码示例
import javax.swing.JFormattedTextField; //导入方法依赖的package包/类
/**
* Constructor.
*/
public MassValueEntryNode( final BalanceGameModel balanceGameModel, PCanvas canvas ) {
this.model = balanceGameModel;
this.canvas = canvas;
// Add the textual prompt.
PText prompt = new PText( BalanceAndTorqueStudyResources.Strings.MASS_EQUALS );
prompt.setFont( TEXT_FONT );
// Create the sub-panel that will contain the edit box for entering
// the numerical value.
JPanel numericalValueEntryPanel = new JPanel();
numericalValueEntryPanel.setBackground( BACKGROUND_COLOR );
numberEntryField = new JFormattedTextField( NumberFormat.getNumberInstance() );
numberEntryField.setColumns( ANSWER_ENTRY_FIELD_COLUMNS );
numberEntryField.setFont( TEXT_FONT );
numberEntryField.setBorder( BorderFactory.createEtchedBorder() );
numberEntryField.requestFocus();
numericalValueEntryPanel.add( numberEntryField );
// Add the units label.
PText unitsLabel = new PText( BalanceAndTorqueStudyResources.Strings.KG );
unitsLabel.setFont( TEXT_FONT );
// Add a handler for the case where the user presses the Enter key.
numberEntryField.addActionListener( new ActionListener() {
public void actionPerformed( ActionEvent arg0 ) {
submitProposedAnswer();
}
} );
// Wrap the value entry panel in a PSwing.
PSwing valueEntryPSwing = new PSwing( numericalValueEntryPanel );
// Create the button for checking the answer.
checkAnswerButton = new TextButtonNode( BalanceAndTorqueStudyResources.Strings.CHECK_ANSWER, new PhetFont( 20 ), Color.YELLOW );
// Register to send the user's guess when the button is pushed.
checkAnswerButton.addActionListener( new ActionListener() {
public void actionPerformed( ActionEvent e ) {
submitProposedAnswer();
}
} );
// Lay out the node.
addChild( new ControlPanelNode( new VBox( 10, new HBox( 5, prompt, valueEntryPSwing, unitsLabel ), checkAnswerButton ), BACKGROUND_COLOR ) );
}
魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐


所有评论(0)