java - 代码不工作? [英] java - code not working?

查看:86
本文介绍了java - 代码不工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码



this is my code

UserNameTextBox = new JTextField();
    UserNameTextBox.setHorizontalAlignment(SwingConstants.CENTER);
    UserNameTextBox.setBounds(562, 326, 119, 20);
    contentPane.add(UserNameTextBox);
    UserNameTextBox.setColumns(10);

    UserNameTextBox.getDocument().addDocumentListener(new DocumentListener() {
      public void changedUpdate(DocumentEvent e) {
          UserNameTextBox.setBackground(Color.red);
      }
      public void removeUpdate(DocumentEvent e) {
          UserNameTextBox.setBackground(Color.red);
      }
      public void insertUpdate(DocumentEvent e) {
          UserNameTextBox.setBackground(Color.red);
      }
});





问题是,当我输入时没有任何反应在textfeild,它意味着变红,可以请一些人解释为什么它不会w?我很困惑



the problem is, is that nothing happens when I type in the textfeild, its meant to go red, can some one please explain why its not wokring? im so confused

推荐答案

这里的评论中有趣的apporaches。

我从未使用过任何一个,但是嘿(!) - 总是有第一次...



http://docs.oracle.com/javase/tutorial/uiswing/components/textfield.html [ ^ ]



我推荐一个ActionListener。
Interesting apporaches in the comments here.
I've never used any of them, but hey(!) - there is always a first time...

http://docs.oracle.com/javase/tutorial/uiswing/components/textfield.html[^]

I recommend an ActionListener.


这篇关于java - 代码不工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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