gpt4 book ai didi

java 为什么切换器不工作?

转载 作者:行者123 更新时间:2023-12-01 07:35:42 24 4
gpt4 key购买 nike

该程序将执行 text = invoertextbox.getText();invoertextbox.setText("");但它不想打开切换器或默认值。有人有建议吗?它也不显示消息框。

import java.awt.event.*;
import javax.swing.JTextField;
import javax.swing.*;
import java.awt.*;
import java.io.*;
import java.awt.Toolkit;
import java.util.Timer;
import java.util.TimerTask;

public class Paneel extends JPanel {

private static final long serialVersionUID = 1L;
String text;
String AccountName = "default";
String autosavecheck = "";
int level = 0;
String iss;
JLabel monsterlabel, progresslabel, commandslabel, label1;
JProgressBar monsterbar, progressbar;
JButton sendknop, clearknop, creditsknop, saveknop, loadknop, restartknop,
disableautosaveknop;
JTextField commandstextbox, naamtextbox, invoertextbox, dialoogtextbox;
JOptionPane resetdialog;
Toolkit toolkit;
Timer timer;

public Paneel() {

setLayout(null);

dialoogtextbox = new JTextField(12);
dialoogtextbox.setFont(new Font("sansserif", Font.BOLD, 12));
dialoogtextbox.setBounds(12, 12, 838, 207);
dialoogtextbox.list();
invoertextbox = new JTextField(12);
invoertextbox.setBounds(12, 330, 982, 20);
commandstextbox = new JTextField(12);
commandstextbox.setBounds(856, 28, 138, 191);
naamtextbox = new JTextField(12);
naamtextbox.setBounds(772, 263, 220, 20);
sendknop = new JButton("Send");
sendknop.setBounds(12, 260, 75, 23);
sendknop.addActionListener(new sendknopHandler());

add(dialoogtextbox);
add(invoertextbox);
add(commandstextbox);
add(naamtextbox);
add(sendknop);

class sendknopHandler implements ActionListener {
public void actionPerformed(ActionEvent e) {
doen();
}
}

private void doen() {
text = invoertextbox.getText();
invoertextbox.setText("");
// Spellingcheck

switch (level) {
case 0:
if (text == "start") {
messagebox("test");
level = 1;
AccountName = naamtextbox.getText();
dialoogtextbox.setText(dialoogtextbox.getText() + "\n"
+ " you are " + AccountName);
dialoogtextbox.setText(dialoogtextbox.getText()
+ "\n"
+ " you found you're self in a basement with furniture and a door.");
commandstextbox.setText("open door");
commandstextbox.setText(commandstextbox.getText() + "\n"
+ "check table");
}
break;
default:
dialoogtextbox.setText("niks");
break;
// Hall key Gebruiken
}
progressbar.setValue(level);
}

private void messagebox(String string) {
}
}

最佳答案

替换

text == "start"

"start".equals(text)
<小时/>

查看

关于java 为什么切换器不工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12507314/

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