Skip to main content

Button Problem

No replies
Identyi
Offline
Joined: 2013-04-07
Points: 0

I made myself little applet and everything works fine expect for the final button.
Heres the code:

import java.applet.*; 
import java.awt.*;
import java.awt.event.*;

import javax.swing.*;

public class server01 extends Applet implements ActionListener {
   Label helloLabel = new Label("applet v 0.3.4 | created for testing purpose");
   Label hello2Label = new Label("this applet will be up-to-date.");
   Button buttonButton = new Button("START" + " Button");
   Label buttonLabel = new Label("Starting applet...");
   TextField field1TextField = new TextField("PASSWORD HERE");
   Button cleartextButton = new Button("CLEAR");
   Button exitButton = new Button("EXIT");
   boolean ifTrue = false;
   boolean ifClicked = false;
   Button correctPassLabel = new Button("[ TOP SECRET ]");
   String string = new String("codepassl");
   Label passLabel = new Label("TestProfile pass is 123");
  
  
private static final long serialVersionUID = 1L;
  public void init() {
  setBackground(Color.black);
  setForeground(Color.white);
  buttonButton.setForeground(Color.black);
  add(helloLabel);
  add(hello2Label);
  add(buttonButton);
  buttonButton.addActionListener(this);
  field1TextField.setForeground(Color.black);
  cleartextButton.addActionListener(this);
  cleartextButton.setForeground(Color.black);
  exitButton.addActionListener(this);
  exitButton.setForeground(Color.black);
  add(exitButton);
  correctPassLabel.setForeground(Color.black);
  passLabel.setForeground(Color.black);
  correctPassLabel.addActionListener(this);

  }
 
  
   public void actionPerformed(ActionEvent e) { 
   if(e.getSource() == buttonButton) {
   ifClicked = true;
  add(buttonLabel);
  validate();
  add(field1TextField);
  validate();
  add(cleartextButton);
  validate();
  ifTrue = true;
  }
  
if(e.getSource() == cleartextButton) {
String cleartext = "";
field1TextField.setText(cleartext);
validate();
      }
KeyListener kl = new KeyAdapter(){
    public void keyTyped(KeyEvent evt){
        if(field1TextField.getText().equals(string)) {
            add(correctPassLabel);
            validate();
        }
    }
};
field1TextField.addKeyListener(kl);
if(e.getSource() == exitButton) {
if(ifTrue == true) {
  remove(buttonLabel);
  validate();
  remove(field1TextField);
  validate();
  remove(cleartextButton);
  validate();
  ifTrue = false;
}
}
if(ifTrue == false) {
int dialogButton = JOptionPane.showConfirmDialog (null, "Are you sure?");
                if(dialogButton == JOptionPane.YES_OPTION) {
                System.exit(0);
                if(dialogButton == JOptionPane.NO_OPTION) {
                  remove(dialogButton);
                    }
                  }
    }
if(e.getSource() == correctPassLabel) { //
add(passLabel);                    // <------ THE PROBLEM
validate();                       // 
      }
            }
          }