dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Combination Lock for begginers

  1. #1
    Join Date
    Jan 2018
    Posts
    2

    Question Combination Lock for begginers

    anyone can help improve my code. I need to simulate a combination lock on the door. He must notify that the door is open when entering the code, and also close automatically after 20 seconds. Аlso need password reset function. The password is only changed when the door is open.
    Code:
    /*
    
    public class ComboNumber extends JFrame implements ActionListener{
    
    int one, two, three;
    String inData1, inData2, inData3;
    JButton[] button;
    private String secret = "5689";
    private String guess = "";
    public ComboNumber()
    {
        getContentPane().setLayout(new FlowLayout());
        Container c = getContentPane();
        button = new JButton[10];
        for(int i = 0; i < button.length; ++i) 
        {
            button[i] = new JButton("" + i);
            c.add(button[i]);
            button[i].addActionListener(this);
        }
        setTitle("Comboination Lock");
        JPanel panel = new JPanel();
    }
       public void actionPerformed(ActionEvent evt) {
        Object o = evt.getSource();
        if (o instanceof JButton) {
            JButton btn = (JButton) o;
                guess += btn.getText();
            if (guess.equals(secret)) {
                JOptionPane.showMessageDialog(this, "Welcome Overloard Master");
                dispose();
            } else if (guess.length() >= 4) {
                JOptionPane.showMessageDialog(this, "WRONG", "Wrong", JOptionPane.ERROR_MESSAGE);
                guess = "";
            }
        }
    }
    public static void main (String[] args)
        {
       ComboNumber frm = new ComboNumber();
        WindowQuitter wQuit = new WindowQuitter();
        frm.addWindowListener(wQuit);
        frm.setSize(500, 500);
        frm.setVisible(true);
        }
    }
    
    class WindowQuitter extends WindowAdapter{
    public void windowClosing(WindowEvent e)
        {
           System.exit(0);
        }
    }

  2. #2
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,787

    Re: Combination Lock for begginers

    Does the posted code do what you want it to do?
    If not, please explain what is wrong with what it does and explain how you want it to act differently.

    Also posted at: https://coderanch.com/t/689561/java/...giners#3236253
    Norm

  3. #3
    Join Date
    Jan 2018
    Posts
    2

    Re: Combination Lock for begginers

    unfortunately not, I want to add a library import javax.swing.Timer; which will ask for a password for example in 20 seconds. And password reset function

  4. #4
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,787

    Re: Combination Lock for begginers

    Ok, what have you tried?
    Be sure to wrap any posted code in code tags.
    Norm

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)