简体   繁体   English

在Java Swing上获取已更改的JTextField的值

[英]get value of changed JTextField on Java Swing

Hey guyz i'm working on a GPA calculator for my java assignment, and the gui i have created is 100% based on Events ie no buttons for the user to submit his data. 嗨,伙计,我正在为我的Java作业开发GPA计算器,我创建的GUI是基于事件的100%,即用户没有按钮可以提交他的数据。 my question is how do i know if a textfield value has changed and if it did how do i get the original value befor the change. 我的问题是如何知道文本字段的值是否已更改,以及是否知道更改后的原始值。 another question how can i store each component in an arrayList do the user can create as many rows as they like Thanks this is the snapshot of mu GUI enter image description here BTW feel free any other suggestion 另一个问题我如何将每个组件存储在arrayList中,用户可以创建任意数量的行吗?这是mu GUI的快照,请在此处输入图像描述,顺便说一句,还有其他建议吗?

You can use keylistener 您可以使用keylistener

    JTextField usernameTextField= newJTextField(); 
usernameTextField.addKeyListener(new () { public void keyReleased(Key KeyAdapter Event e) { JTextField textField = (JTextField) e.getSource(); String text = textField.getText(); textField.setText(text.toUpperCase()); } public void keyTyped(KeyEvent e) { } public void keyPressed(KeyEvent e) { } });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM