如何从java中的TextArea获取输入?
这是我的主课^^^如何从java中的TextArea获取输入?,java,swing,Java,Swing,这是我的主课^^^ public class Idunno { static Scanner commandSystem = new Scanner (System.in); public static String[] nextCmd; public static void tellConsole(String msg) { Window.tellWindow(msg); System.out.println(msg); } public static void main
public class Idunno
{
static Scanner commandSystem = new Scanner (System.in);
public static String[] nextCmd;
public static void tellConsole(String msg)
{
Window.tellWindow(msg);
System.out.println(msg);
}
public static void main (String[] args)
{
Window.main();
tellConsole("I dunno Version 1.0.0.0 By: Lukario45");
tellConsole("Type /help for command list!");
while (true)
{
String nextCmd = commandSystem.nextLine();
if (nextCmd.startsWith("/"))
{
String[] cmdNext = nextCmd.split(" ");
String cmd = cmdNext[0];
Command.run(cmd , nextCmd);
}
else
{
tellConsole("I am sorry! You can only do commands in this version!");
}
}
}
}
这是我的Windows类^^下面是这个程序的样子 底部的文本框就是我正在谈论的文本框 好的,现在我的问题是,我正试图将我的整个程序转换为我为它制作的GUI上的太多显示。但是我不知道如何使底部的文本框像System.in一样工作,以便扫描仪工作。我该怎么做?谢谢9错误的代码格式来自4O.O)请勿使用awt组件(已弃用)。更喜欢使用Swing等效项:JTextArea 看
然后,您可能会找到一个getText()方法有一个getText方法。我想知道的是如何使该文本与扫描仪一起工作。与已经过时的Java1.4.2相反。请链接到当前文档。
package net.mcthunder.idunno.src;
import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import java.awt.TextArea;
import java.awt.TextField;
import java.awt.Label;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class Window extends JFrame {
static TextArea outputBox2 = new TextArea();
public static TextField inputBox2 = new TextField();
private JPanel contentPane;
public void read()
{
}
/**
* Launch the application.
*/
public static void main() {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Window frame = new Window();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
public static void tellWindow(String msg)
{
outputBox2.setText(outputBox2.getText() + msg + "\n");
}
/**
* Create the frame.
*/
public Window() {
setTitle("IDunno Verson 1.0.0.0");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 568, 396);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
TextArea outputBox = new TextArea();
outputBox = outputBox2;
outputBox.setBounds(5, 38, 537, 282);
contentPane.add(outputBox);
TextField inputBox = new TextField();
inputBox.setBounds(5, 326, 537, 22);
contentPane.add(inputBox);
Label label = new Label("IDunno Version 1.0.0.0");
label.setBounds(5, 10, 311, 22);
contentPane.add(label);
}
}