私はそれがほしいと思わないときにポップアップする迷惑なメッセージボックスがあります。 ユーザーがログオンして非表示のボタンが表示された後に問題が発生しますが、クリックすると「正しい」メッセージが再び表示されますか? Iveは最初のステートメントとボトムの上に置いてみました。 EDIT:あなたはすべてのあなたのactionPerformed
方法でこれを入れて迷惑なメッセージは、ログインが成功した後に来るのメッセージではない、と私はいけない何をスペルチェックする必要があり、else文のスウィング
class MyWindowListener extends WindowAdapter {
public void windowClosing(WindowEvent e) {
System.out.println("Closing window!");
System.exit(0);
}
}
class LoginForm extends JFrame implements ActionListener {
private final String username = "user";
private final String password = "pass";
JFrame frame;
JPanel jPanel;
JLabel userLabel;
final JTextField userText;
JLabel passLabel;
final JPasswordField passText;
JButton loginBtn;
JButton shopBtn;
JLabel welcome;
{
frame = new JFrame();
jPanel = new JPanel();
userLabel = new JLabel("Login : ");
userText = new JTextField(10);
passLabel = new JLabel("Password : ");
passText = new JPasswordField(10);
loginBtn = new JButton("Login");
shopBtn = new JButton("Go to Shop");
welcome = new JLabel("Welcome to ECSE501 Computers");
setTitle("Login Page");
loginBtn.addActionListener(this);
shopBtn.addActionListener(this);
Container c1 = new Container();
c1.setLayout(new GridLayout (3,2));
c1.add(userLabel);
c1.add(userText);
c1.add(passLabel);
c1.add(passText);
c1.add(loginBtn);
Container c2 = new Container();
c2.setLayout(new BoxLayout(c2, BoxLayout.Y_AXIS));
c2.add(welcome);
c2.add(shopBtn);
welcome.setVisible(false);
shopBtn.setVisible(false);
add(jPanel);
jPanel.add(c1);
jPanel.add(c2);
}
public void actionPerformed(ActionEvent e) {
String userInput = userText.getText();
char[] pass = passText.getPassword();
String p = new String(pass);
if (userInput.equals(username) && p.equals(password)) {
jPanel.setVisible(true);
welcome.setVisible(true);
jPanel.setBackground(Color.green);
JOptionPane.showMessageDialog(null, "Correct");
shopBtn.setVisible(true);
JButton hiddenBtn = (JButton) e.getSource();
if (hiddenBtn == shopBtn)
{
SelectionForm selection = new SelectionForm();
selection.select();
}
}
else {
jPanel.setBackground(Color.red);
JOptionPane.showMessageDialog(null, "Wrong Login Details");
}
}
}
public class LoginTester {
public static void main(String[] args) {
// register an event handler for frame events
LoginForm frame = new LoginForm();
frame.addWindowListener(new MyWindowListener());
frame.setSize(300, 200);
frame.setVisible(true);
//frame.pack();
}
}
このfuctionをループで呼んでいるようです。 (主要部として) – StackFlowed
1)より良いヘルプをもっと早く得るために、[SSCCE](http://sscce.org/)を投稿してください。 2)* '' Corerect ''*間違っています。スペルチェッカーを使用します。 3)*「迷惑なメッセージ」*の正確なテキストは何ですか? –
'' Corerect ''?それが私の上に現れたら、私は迷惑になるだろう。申し訳ありませんが、皮肉に抵抗できませんでした。 –