我有一个小问题占据了我几个小时。
我希望玩家在游戏过程中进行输入,然后我将进一步使用。但是我不知道该怎么做...
试过了JOptionPane
,JTextField
和Scanner
。Scanner
工作,但我想要它不使用控制台:我
所以,这是我的代码:
窗户:
package Main;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Window
{
public static JFrame frame = new JFrame("Z-Stories");
public static JLabel Label = new JLabel ("<html></html>", JLabel.CENTER);
public static String LabelText;
public Window()
{
Label.setVerticalAlignment(JLabel.TOP);
frame.setSize(1920, 1080);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(Label, BorderLayout.CENTER);
frame.setIconImage(new ImageIcon(getImage()).getImage());
frame.pack();
frame.setVisible(true);
}
protected static Image getImage()
{
java.net.URL imgURL = Window.class.getResource("Logo32.png");
if (imgURL != null)
{
return new ImageIcon(imgURL).getImage();
} else
{
return null;
}
}
public static void addText(String Text)
{
LabelText = Label.getText();
LabelText = LabelText.replace("</html>", "");
if(Text != null)
{
Label.setText(LabelText + "<br/>" + Text + "</html>");
}else
{
Label.setText(LabelText + "<br/><br/></html>");
}
System.out.println(Label.getText());
Label.validate();
}
public static int InputInt()
{
//User Input here
//Maybe parse into Int
return output;
}
public static String InputText()
{
//User Input here
//Maybe convert to String
return outputText;
}
}
还有 Game.java
...
public void StartGame()
{
ErstesSpiel = 1;
Window.addText("Wähle deine Sprache | Select your language");
Window.addText("");
Window.addText("Deutsch (1) | English (2)");
Window.addText("");
int var3 = Window.InputInt();
Window.addText("");
....