java - 为什么我的字符串数组在我输入到 JLabel 时不起作用?
问题描述
我正在尝试创建一个类似于俄勒冈小道这样的路径选择游戏。我试图找出为什么当我尝试创建一个 JLabel 来显示文本时,我将其设置为的文本是另一个类中的一个数组,称为StoryLine
. 每当我将标签添加到我的框架时,文本都不会在屏幕上弹出。我已将文本更改为"hey"
并且它有效,但由于某种原因它不适用于我的数组。
考虑这段代码:
public static void intro() {
JFrame frame = new JFrame("Lost Boy");
JLabel textbox = Components.Textbox();
JLabel bed = Components.Bedroom();
JLabel text = Components.TextFormat(StoryLine.story[2]);
frame.setSize(1000, 600);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
text.setBounds(10, -70,400,200);
frame.add(text);
frame.add(textbox);
frame.add(bed);
frame.setLayout(null);
frame.setVisible(true);
}
类Components.TextFormat
public static JLabel TextFormat(String stry) {
JLabel text = new JLabel();
text.setText(stry);
text.setFont(MyFont());
text.setForeground(Color.WHITE);
return text;
}
类StoryLine.string[]
public static void Script() {
story[2] = "You're just putting on your shoes before you walk out the\n"
+ "door. You see your dog sitting at the door wagging his tail\n"
+ "expecting to come. Do you choose to bring him?";
解决方案
推荐阅读
- python - 如何通过读取文本文件中提到的日期来计算总天数?
- mysql - 如何从两个表中获取空值 WHERE user_id IS NULL 在 Node.js MYSQL 中不起作用
- python - Django:与多对多关系相关的问题
- javascript - 属性“z”的唯一值
- typescript - 打字稿转换错误以获取输入值
- wpf - WPF 处理文本、图像和文件粘贴事件
- python - 使用 Selenium 时如何获取 HTTP 重定向数据?
- python - 为什么 2d 光线追踪 + 镜子做(有时)半透明镜子(光线穿过并反射)
- kendo-ui - 将 Kendo UI 升级到版本 2020.1.406 后,用于 MVC 的 Kendo Grid 在获取数据时显示“未找到记录”消息
- odoo - 在自定义模块中添加字段时,xml 文件中的 Odoo 13 错误