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 のもの 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 に答える