精华内容
下载资源
问答
  • import java.awt.Canvas; //导入方法依赖的package包/类public Java2DFrame(Spark game){super(GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration());this.game...

    import java.awt.Canvas; //导入方法依赖的package包/类

    public Java2DFrame(Spark game)

    {

    super(GraphicsEnvironment.getLocalGraphicsEnvironment()

    .getDefaultScreenDevice().getDefaultConfiguration());

    this.game = game;

    ge = GraphicsEnvironment.getLocalGraphicsEnvironment();

    gd = ge.getDefaultScreenDevice();

    gc = gd.getDefaultConfiguration();

    setTitle("Spark");

    setFocusable(false);

    setBackground(Color.black);

    setFocusTraversalKeysEnabled(false);

    setResizable(false);

    setIgnoreRepaint(true);

    if (game.gameOptions.displayWindowed == false)

    setUndecorated(true);

    setIconImage(new ImageIcon("spark/images/imgIcon.gif").getImage());

    // Invisible cursor

    int[] pixels = new int[16 * 16];

    Image image = Toolkit.getDefaultToolkit().createImage(

    new MemoryImageSource(16, 16, pixels, 0, 16));

    Cursor transparentCursor = Toolkit.getDefaultToolkit()

    .createCustomCursor(image, new Point(0, 0), "invisibleCursor");

    setCursor(transparentCursor);

    drawCanvas = new Canvas(gc);

    drawCanvas.setPreferredSize(new Dimension(game.ResolutionX,

    game.ResolutionY));

    drawCanvas.setBackground(Color.black);

    drawCanvas.setIgnoreRepaint(true);

    drawCanvas.setFocusTraversalKeysEnabled(false);

    drawCanvas.addKeyListener(this);

    drawCanvas.addMouseListener(this);

    drawCanvas.addMouseWheelListener(this);

    drawCanvas.setCursor(transparentCursor);

    add(drawCanvas);

    addWindowListener(this);

    pack();

    setLocationRelativeTo(null);

    if (game.gameOptions.displayWindowed == false)

    {

    setFullScreen();

    }

    setVisible(true);

    drawCanvas.requestFocus();

    }

    展开全文
  • numberEntryField.requestFocus(); numericalValueEntryPanel.add( numberEntryField ); // Add the units label. PText unitsLabel = new PText( BalanceAndTorqueStudyResources.Strings.KG ); unitsLabel....

    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 ) );

    }

    展开全文
  • 但遇到的问题是对话框弹出很多次,原因是“如果你的lostfocus成立,你原来的程序就会要求得到焦点,即requestfocus,可是这个时候,你又要弹出一个message,所以就又会lostfocus,这个时候系统该怎么做呢?就会一个紧的...
    textfield,需要在失去焦点的时候检查值是否合法,如果不合法,弹出对话框提示。
    但遇到的问题是对话框弹出很多次,原因是“如果你的lostfocus成立,你原来的程序就会要求得到焦点,即requestfocus,可是这个时候,你又要弹出一个message,所以就又会lostfocus,这个时候系统该怎么做呢?就会一个紧的循环了!”
     
    例如
    class IvjEventHandler implements java.awt.event.ActionListener, java.awt.event.FocusListener, java.awt.event.MouseListener, javax.swing.event.ChangeListener {
         public void focusGained(java.awt.event.FocusEvent e) {}
         public void focusLost(java.awt.event.FocusEvent e) {
            if (e.getSource() == Bill.this.getJTextField1()) 
            connEtoC4(e);
    }

    private void connEtoC4(java.awt.event.FocusEvent arg1) {
        try {
            this.jTextField1_FocusLost(arg1);
        } catch (java.lang.Throwable ivjExc) {
            handleException(ivjExc);
        }
    }

    public void jTextField1_FocusLost(java.awt.event.FocusEvent focusEvent) {
        if (!focusEvent.isTemporary()) {
            if (!checkMIDFormat(ivjJTextField1.getText().trim())) {
                JOptionPane.showMessageDialog(
                    null,"请正确输入手机号码!","输入错误",JOptionPane.ERROR_MESSAGE);
                ivjJTextField1.requestFocus();
            }
        }
        return;
    }

    解决办法为
    把ivjJTextField1.requestFocus();
    改为:
    javax.swing.SwingUtilities.invokeLater(new Runnable{

        public void run()
        {
            ivjJTextField1.requestFocusInWindow();
        }
    });
     
    解释如下:
    invokeLater这个东西很复杂,
    在java swing中有一个线程叫做事件派发线程 AWT-Dispather-Thread
    所有画面部分的更新修改等事件就是在这个线程中等待处理的
    你的lostFocus没有加错,但是由于在执行你的LostFocus的事件listener之后
    系统还有其它的事情要作 在干了其它的事情之后,focus就跑到其它地方去了
    通过调用 invokeLater 把一个新的事件(就是你的runable) 放到这个事件派发线程的最后, 这样等其它的调用完成之后, 就乖乖的执行你的 run , 把focus抢回来

    另外,如果还要相应回车事件,建议采用如下方法触发焦点转移。
    public void actionPerformed(java.awt.event.ActionEvent e) {
        transferFocus();
    }
    展开全文
  • //导入方法依赖的package包/类 /** * {@inheritDoc} */ public final void dataChanged(int row, int column) { if(row == Integer.MIN_VALUE) { // special case...... cell.requestFocus(); revalidate(); }

    import com.codename1.ui.Component; //导入方法依赖的package包/类

    /**

    * {@inheritDoc}

    */

    public final void dataChanged(int row, int column) {

    if(row == Integer.MIN_VALUE) {

    // special case... Rebuild the table

    updateModel();

    revalidate();

    return;

    }

    // prevents the table from rebuilding on every text field edit which makes the table

    // more usable on iOS devices with the VKB/Native editing

    if(editingColumn == column && editingRow == row) {

    editingColumn = -1;

    editingRow = -1;

    return;

    }

    Object value;

    boolean e;

    if(row < 0) {

    e = false;

    value = model.getColumnName(column);

    } else {

    value = model.getValueAt(row, column);

    e = model.isCellEditable(row, column);

    }

    Component cell = createCellImpl(value, row, column, e);

    TableLayout t = (TableLayout)getLayout();

    TableLayout.Constraint con = createCellConstraint(value, row, column);

    if(includeHeader) {

    row++;

    }

    Component c = t.getComponentAt(row, column);

    if(c != null) {

    removeComponent(c);

    // a repaint sent right before this might result in an artifact for some use cases so

    // removing visibility essentially cancels repaints

    c.setVisible(false);

    }

    addComponent(con, cell);

    layoutContainer();

    cell.requestFocus();

    revalidate();

    }

    展开全文
  • 我是Android和Java的新手.我一直在使用Android Developer和其他网站提供的MediaPlayer和AudioManager示例.AudioManager audioManager = (AudioManager) getSystemService(Context.AUdio_SERVICE);int result = ...
  • 众所周知,JFrame.pack()方法为适应屏幕大小的方法,所以,requestFocus()方法必须要在pack()方法之后调用,不然就会失效。 下面说说我经常用到的java gui中的一些方法吧! 1.JPanel.setBorder(BorderFactory....
  • 使用JOptionPane.showConfirmDialog和自定义组件(JPanel),我喜欢在...代码示例:当对话框打开时,JPasswordField pf应该具有焦点…import java.awt.BorderLayout;import java.awt.GridBagConstraints;import java....
  • 我遇到了Mac OS X上看起来不同的JTextField.requestFocus()行为问题.这是我的情况:我有一个带有JList和JTextField的对话框.用户应该在文本字段中编写布尔表达式,该列表包含可能在表达式中输入的所有变量的名称.由于...
  • <ul><li><a href="https://bugs.openjdk.java.net/browse/JDK-8244418">JDK-8244418</a>: MenuBar: IOOB exception on requestFocus on empty bar</li></ul> <h3>Reviewers <ul><li>Jeanette Winzenburg ...
  • ViewStub是一个不可见的,大小为0的View,最佳用途就是实现View的延迟加载,在需要的时候再加载View,和Java中常见的性能优化方法延迟加载一样。当调用ViewStub的setVisibility函数设置为可见或则调用inflate()方
  • java实验答案3你成功了");for(int k=0;k{ label[k].removeKeyListener(this);label[k].removeFocusListener(label[k]);label[k].setBackground...}inputWord.requestFocus();}}}WordMainClass.javapublic class W...
  • Java FX 焦点事件

    2020-12-26 14:37:15
    Java FX 焦点事件 简介: ​ 简单记录下 Java FX 的焦点事件的使用。 绑定焦点: //文本框绑定焦点事件 TextField textField = new TextField(); textField.setText("文本框"); textField.requestFocus(); //按钮...
  • 我所做的只是在最后移动requestFocus()方法.基本上这些是你要做的两件事情,当它按回车键并且默认情况下它是重点.frame.getRootPane().setDefaultButton(start);start.requestFocus();package sof;import java.awt....
  • at android.view.View.requestFocus(View.java:8455) at android.view.View.requestFocus(View.java:8422) at android.view.View.requestFocus(View.java:8401) at android.view.View.onTouchEvent(View.java:...
  • 问题Hello I have a problem with the focusmytext= new ...mytext.requestFocus(true);gc.fill =GridBagConstraints.HORIZONTAL ;gc.gridx =3; gc.gridy=4;gbl.setConstraints(mytext,gc);jContentPane.add...
  • at android.view.ViewGroup.requestFocus(ViewGroup.java:2384) at android.view.ViewGroup.onRequestFocusInDescendants(ViewGroup.java:2425) at android.view.ViewGroup.requestFocus(ViewGroup.java:2381) ...
  • at android.view.ViewGroup.requestFocus(ViewGroup.java:2618) at android.view.View.requestFocus(View.java:7594) at android.view.View.requestFocus(View.java:7573) at android.view.ViewRootImpl....
  • at android.view.View.requestFocus(View.java:8094) at android.view.View.requestFocus(View.java:8061) at android.view.View.requestFocus(View.java:8040) at android.view.View.onTouchEvent(View.java:...
  • publicvoidactionPerformed(ActionEventae){//如果getSource()得到的用户名和密码if(ae.getSource()==txtName)txtPwd.requestFocus();elseif(ae.getSource()==txtPwd)btnOk.requestFo...public void actionPerformed...
  • }}textResult.requestFocus();validate();}}MainClass.javapublic class MainClass{ public static void main(String args[]){ ComputerFrame frame;frame=【代码9】//创建窗口,其标题为:算术测试}}?实验...
  • 一定要在最后面加requestFocus(); 一定要在最后面加requestFocus(); 一定要在最后面加requestFocus(); 一定要在最后面加requestFocus(); 一定要在最后面加requestFocus();
  • (框架有它.)当面板添加到屏幕时,您可能想要requestFocus.>当图形发生变化时,您需要调用重绘.>您不能在paintComponent方法中调用repaint.>您需要在再次绘制字符串之前清除绘图区域(否则所有字符将最终在...
  • 好像就这两个函数setSelectionEnd(pos)jTextArea1.setSelectionStart(pos)a.requestFocus看看textArea的属性里有getCaretPosition();一个继承自Class TextComponent的方法也可以getSelectionStart();(1):如果是刚刚...
  • at android.view.View.requestFocus (View.java:9757) at android.view.View.requestFocus (View.java:9724) at android.view.View.requestFocus (View.java:9703) at android.view.View.onTouchEvent (View....
  • java设置组件得到光标

    2010-12-09 15:22:03
    java设置组件得到光标: 开发中经常要用到组牛得到光标,方法如下 组件.requestFocus(); //获取光标
  • View刷新过程Java-JNI

    2018-04-03 23:31:51
    这里只讨论Java&lt;-&gt;JNI之间的刷新,仅限CPU部分。GPU和Display部分需要看C++源码,暂时忽略 View invalidate() requestFocus() ViewParent invalidateChild() ViewGroup invalidateChildInParent...
  • 总结一下我在java swing 编程实践中的一些经验以及要注意的问题 (1)如何在启动swing界面时指定组件(文本框)聚焦呢? 范例: CreateMD5App frame = new CreateMD5App(); frame.setVisible(true); ...
  • jTextField.requestFocus();

空空如也

空空如也

1 2 3 4 5 ... 9
收藏数 168
精华内容 67
关键字:

javarequestfocus

java 订阅