gpt4 book ai didi

java - 在 GUI 中显示文本冒险

转载 作者:太空宇宙 更新时间:2023-11-04 13:06:02 25 4
gpt4 key购买 nike

我正在尝试将我的文本冒险放入 GUI 中,并使其没有按钮,只有文本和用户输入。这是我的 GUI 的代码

import java.awt.*;
import javax.swing.*;


public class Window {

public static void createwindow() {

JFrame frame = new JFrame("Game");

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

Component textLabel = null;


frame.setLocationRelativeTo(null);

frame.pack();
frame.setVisible(true);

}

public static void main(String[] args) {
createwindow(); }

}

我在一个单独的类中进行了我的文本冒险,并且想知道是否有任何简单的方法可以在此 GUI 中显示它。感谢您的帮助。

最佳答案

import javax.swing.*;

public class Window {

public static void createwindow() {

JFrame frame = new JFrame("Game");

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(600, 400);
frame.setLocationRelativeTo(null);
frame.setVisible(true);

// Component textLabel = null;
JTextArea jta = new JTextArea();
frame.add(jta);

// frame.pack();

}

public static void main(String[] args) {
createwindow(); }

}

根据我的理解,您只想要一个 TextArea。对吗?

关于java - 在 GUI 中显示文本冒险,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34428812/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com