ellow,
I want to make a code where you have 3 buttons(1,2,3) and you have to press the buttons in a correct order to open the vault. and the code you entered is shown in a textfield the code is 3321. however i am only able to get one letter every time on the screen now i know why that is and that what i did is wrong, however i do not know the correct way...obviously.
so i was wondering if someone is kind enough to help me
here is the code:
Code:import java.awt.*; import java.awt.event.*; import javax.swing.*; class MyFrame extends JFrame implements ActionListener { private JButton b1, b2, b3, b4; private JLabel lab1, lab2; private JTextField tfUit; private final String wachtwoord = "3321"; public MyFrame() { setLayout(new FlowLayout()); lab1 = new JLabel ("raad de geheime code"); add(lab1); b1 = new JButton("1"); add(b1); b1.addActionListener(this); b2 = new JButton("2"); add(b2); b2.addActionListener(this); b3 = new JButton("3"); add(b3); b3.addActionListener(this); tfUit = new JTextField(8); add(tfUit); lab2 = new JLabel("hier komt de uitvoer"); add(lab2); b4 = new JButton("clear"); add(b4); b4.addActionListener(this); setSize(180, 250); setVisible(true); setDefaultCloseOperation(EXIT_ON_CLOSE); } public void actionPerformed(ActionEvent event) { String s = tfUit.getText(); if (s.equals(wachtwoord) ) { lab2.setText("Yes! geraden"); } else { lab2.setText("de kluis blijft dicht"); } if (event.getSource() == b4) { lab2.setText("hier komt de uitvoer"); tfUit.setText(""); } if (event.getSource() == b1) { tfUit.getText(); tfUit.setText("1"); } if (event.getSource() == b2) { tfUit.getText(); tfUit.setText("2"); } if (event.getSource() == b3) { tfUit.getText(); tfUit.setText("3"); } } }
and this is the main:
Code:public class Main { public static void main(String [] args) { MyFrame Frame = new MyFrame(); } }




Reply With Quote