该程序会做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) {
}
}