Arraylist和JTextArea显示问题(Arraylist and JTextArea Display issue)
我想知道是否有人可以指出我正确的方向。
我正在尝试创建一个接受输入的GUI,当按下按钮时,它会将其添加到JTextArea。
我希望能够继续这样做,直到单击退出按钮。我可以得到第一个显示的输入,但是我花了很多时间试图弄清楚如何继续添加输入直到单击退出按钮。
import javax.swing.*; import java.awt.*; import java.awt.event.*; import javax.swing.event.*; import java.util.ArrayList; public class Window extends JFrame{ private final int WIDTH=400; private final int HEIGHT=200; private JButton button; private JTextArea textArea; private JTextField textField; private JPanel panel; private JButton exit; public Window() { super("TextArea"); setSize(WIDTH, HEIGHT); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setLayout(new BorderLayout()); buildPanel(); add(panel); setVisible(true); } public void buildPanel(){ panel= new JPanel(); textField = new JTextField(10); textArea = new JTextArea(); button = new JButton("Add"); button.addActionListener(new Calc()); exit = new JButton("exit"); exit.addActionListener(new ExitListener()); panel.add(textField); panel.add(button); panel.add(exit); panel.add(textArea); } private class Calc implements ActionListener{ public void actionPerformed(ActionEvent e){ ArrayList<String> array= new ArrayList<String>(); String str = (String) textField.getText(); array.add(str); textArea.setText(str); } } private class ExitListener implements ActionListener{ public void actionPerformed(ActionEvent e){ System.exit(0); } } public static void main(String []args){ new Window(); } }
I was wondering if someone can point me in the right direction.
I am trying to create a GUI that takes input, and when a button is pressed it adds it to a JTextArea.
I want to be able to keep doing this until the exit button is clicked.I can get the first input to display, but I have spent a lot of time trying to figure out how to keep adding input till the exit button is clicked.
import javax.swing.*; import java.awt.*; import java.awt.event.*; import javax.swing.event.*; import java.util.ArrayList; public class Window extends JFrame{ private final int WIDTH=400; private final int HEIGHT=200; private JButton button; private JTextArea textArea; private JTextField textField; private JPanel panel; private JButton exit; public Window() { super("TextArea"); setSize(WIDTH, HEIGHT); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setLayout(new BorderLayout()); buildPanel(); add(panel); setVisible(true); } public void buildPanel(){ panel= new JPanel(); textField = new JTextField(10); textArea = new JTextArea(); button = new JButton("Add"); button.addActionListener(new Calc()); exit = new JButton("exit"); exit.addActionListener(new ExitListener()); panel.add(textField); panel.add(button); panel.add(exit); panel.add(textArea); } private class Calc implements ActionListener{ public void actionPerformed(ActionEvent e){ ArrayList<String> array= new ArrayList<String>(); String str = (String) textField.getText(); array.add(str); textArea.setText(str); } } private class ExitListener implements ActionListener{ public void actionPerformed(ActionEvent e){ System.exit(0); } } public static void main(String []args){ new Window(); } }
原文:
最满意答案
You should take a look at
react-native-background-geolocation
.
相关问答
更多-
标记为反应原生(Marked for react-native)[2023-01-20]
我没有机会尝试任何,但看起来有一些库可用,可以处理降价https://github.com/lwansbrough/react-native-markdown,https://github.com/Benjamin- Dobell / react-native-markdown-view , https://github.com/CharlesMangwa/react-native-simple-markdown I did not have a chance to try any, but it look ... -
Redux和其他'基于通量'的模式很好地与React / React-Native结合,因为它们遵循相同的原则(数据的不变性,单向流等等)。 但最终的选择是你的。 为数据管理集成不同的模式可能有点棘手(因为您必须将它与React组件生命周期集成),但这绝对是可能的。 实际上,Redux本身需要绑定到React, react-redux ,因为它不是React的库。 无论如何,我建议你不要放弃Redux。 可能需要一些时间,直到一切都在你的脑海中有意义,但在那之后它很容易处理。 如果您在任何特定主题(行动,减 ...
-
您应该使用API,因为您不是本地开发的: https://firebase.google.com/docs/database/web/start?hl=es You should use the API cause you are not developing natively: https://firebase.google.com/docs/database/web/start?hl=es
-
react-native init指定反应版本和反应原生版本(react-native init specify react version and react-native version)[2023-11-11]
创建一个项目: react-native init MyNewApp --version 0.45.0 如果你想要改变版本然后尝试这个: npm install --save react-native@0.44.0 npm install --save react@16.0.0-alpha.6 Create a project : react-native init MyNewApp --version 0.45.0 If you want do change version then try wit ... -
尝试使用socket.once()而不是socket.on() ,尽管它每次都会创建连接,但它不会传播事件。 So here I come with an answer. I'll try to leave an answer as the one I'd like to find. A sort of tutorial about how to include Socket.io in React-native. Please, if you know a better solution, write i ...
-
无法从Android Studio构建react-native,Build失败(cannot build react-native from Android Studio, Build failed)[2022-04-28]
这是错误: 错误:任务应用程序执行失败:processDebugGoogleServices'。 请通过更新google-services插件的版本来修复版本冲突(有关最新版本的信息, 请访问https://bintray.com/android/android-tools/com.google.gms.google-services/ )或将com.google.android.gms的版本更新为11.6.2。 你需要改变这一点: classpath 'com.google.gms:google-s ... -
我使用了fetch方法并使用RESTgul API连接到Parse。 以下是一些可能对您有所帮助的链接: https://www.parse.com/docs/rest/guide http://updates.html5rocks.com/2015/03/introduction-to-fetch I have used fetch method and connected to Parse using the RESTgul API. Here are some links that may help ...
-
这是react-native@0.54.2上的错误。 升级到react-native@0.54.4或更新以解决此问题。 This is a bug on react-native@0.54.2. Upgrade to react-native@0.54.4 or newer to fix this issue.
-
最正确的方法是在所有应用程序中引用相同版本的库。 但如果不可能 - 您可以将一个模块与静态版本的库链接,而将第二个模块链接为像往常一样共享。 但这种方法相当于解决方法而不是真正的解决方案。 因为至少有下一个缺点: 应用程序大小膨胀,因为现在您正在为两个版本的库而不是一个版本部署代码 不同库版本中相同类的对象可能是二进制不兼容的 - 因此,如果您尝试在依赖于不同lib版本的代码之间传递c ++对象,则最终会出现未定义的行为。 最后:如果真的没有办法在任何地方使用相同的版本,我会三思而后行。 The most ...
-
后台服务采用反应原生(Background services in react-native)[2022-12-27]
你应该看看react-native-background-geolocation 。 You should take a look at react-native-background-geolocation.