0
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!");
        }
    }

}
}

这是我的主要课程^^^

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

}
}

这是我的 Windows 课程 ^^
这是程序的样子 http://puu.sh/2kvpt

底部的文本框是我正在谈论的文本框

好的,所以这是我的问题,我正在尝试将我的整个程序转换为在 GUI 上显示,我对此非常感兴趣。但我不知道如何使底部文本框作为 System.in 工作以使扫描仪工作。我怎样才能做到这一点?谢谢!9错误的代码格式来自 4spaces stuff OO)

4

1 回答 1

2

不要使用 awt 组件(已弃用)。更喜欢使用 Swing 等效项:JTextArea

http://docs.oracle.com/javase/1.4.2/docs/api/javax/swing/JTextArea.html

然后,您可能会找到一个 getText() 方法

于 2013-03-19T17:15:16.090 回答