Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Textfield and JPasswordField ActionListener not working

  1. #1
    Junior Member
    Join Date
    Nov 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Textfield and JPasswordField ActionListener not working

    package theatre;
    import java.awt.event.KeyEvent;
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.JTabbedPane;
    import javax.swing.JFrame;
    import java.awt.event.*;
     
    public class Theatre extends JFrame  implements ActionListener {
        static JFrame Frame = new JFrame("Theatre");
        static NewJPanel pane = new NewJPanel();
        static NewJPanel1 pane2 = new NewJPanel1();
        static JTabbedPane Tabbed_Pane = new JTabbedPane();
        static final NewJPanel Admin_Login = new NewJPanel();
        static NewJPanel1 Set_Prices = new NewJPanel1();
        static String F;
        static String P;
        static String Username = "Team1";
        static String Password = "Team1";
        static boolean Login;
        static boolean Pass;
     
        public Theatre () {
            //set up
            setLocation(400,300);
            setSize(300,300);
     
            //setting up tabs
            Tabbed_Pane.addTab("Admin", null, null,"Administrative Priveleges");
            Tabbed_Pane.setMnemonicAt(0, KeyEvent.VK_1);
            Tabbed_Pane.setComponentAt(0, pane);
     
            //admin login          
            Admin_Login.jTextField1.addActionListener(this);
    //        Admin_Login.jTextField1.addActionListener(
    //            new ActionListener() {
    //                @Override
    //                public void actionPerformed(ActionEvent e) {
    //                    F = e.getActionCommand();
    //                    Admin_Login.jPasswordField1.setText(F);
    //                    if(F.equals(Username)){
    //                        System.out.print("yes");
    //                        Login = true;
    //                    } else {
    //                        Login = false;
    //                    }
    //                }
    //            }
    //        );
            //admin password
            Admin_Login.jPasswordField1.addActionListener(
                new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        char[] p = Admin_Login.jPasswordField1.getPassword();
                        P = e.getActionCommand();
                        if(P.equals(Password)){
                            System.out.print("yes");
                            Pass = true;
                        } else {
                            Pass = false;
                        }
                    }
                }
            );
            //start button
            Admin_Login.jButton1.setActionCommand("Start");
            Admin_Login.jButton1.addActionListener(
                new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        if(e.getActionCommand().equals("Start"));
                        char[] p = Admin_Login.jPasswordField1.getPassword();
                        F = Admin_Login.jTextField1.getText();
                    }
                }
            );
        }
        public static void main(String[] args) {
            Theatre GUI = new Theatre();
            GUI.setVisible(true);
            GUI.setAlwaysOnTop(true);
            GUI.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
            GUI.getContentPane().add(Tabbed_Pane);
        }
     
        @Override
        public void actionPerformed(ActionEvent e) {
            F = e.getActionCommand();
        }
    }

    package theatre;
     
    public class NewJPanel extends javax.swing.JPanel {
     
        public NewJPanel() {
            initComponents();
        }
     
        @SuppressWarnings("unchecked")                    
        private void initComponents() {
     
            jLabel1 = new javax.swing.JLabel();
            jLabel2 = new javax.swing.JLabel();
            jLabel3 = new javax.swing.JLabel();
            jTextField1 = new javax.swing.JTextField();
            jPasswordField1 = new javax.swing.JPasswordField();
            jButton1 = new javax.swing.JButton();
     
            jTextField1.setText("");
            jTextField1.setEditable(true);
     
            jLabel1.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
            jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
            jLabel1.setText("Login ");
     
            jLabel2.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
            jLabel2.setText("Username:");
     
            jLabel3.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
            jLabel3.setText("Password: ");
     
            jButton1.setText("Start");
     
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
            this.setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                            .addContainerGap()
                            .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 352, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(layout.createSequentialGroup()
                            .addGap(25, 25, 25)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addGroup(layout.createSequentialGroup()
                                    .addComponent(jLabel3)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(jPasswordField1))
                                .addGroup(layout.createSequentialGroup()
                                    .addComponent(jLabel2)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 155, javax.swing.GroupLayout.PREFERRED_SIZE))))
                        .addGroup(layout.createSequentialGroup()
                            .addGap(56, 56, 56)
                            .addComponent(jButton1)))
                    .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(26, 26, 26)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel2)
                        .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(jLabel3)
                        .addComponent(jPasswordField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(41, 41, 41)
                    .addComponent(jButton1)
                    .addContainerGap(60, Short.MAX_VALUE))
            );
        }                    
        public javax.swing.JButton jButton1;
        public javax.swing.JLabel jLabel1;
        public javax.swing.JLabel jLabel2;
        public javax.swing.JLabel jLabel3;
        public javax.swing.JPasswordField jPasswordField1;
        public javax.swing.JTextField jTextField1;                   
    }


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,966
    My Mood
    Hungover
    Thanks
    133
    Thanked 553 Times in 474 Posts

    Default Re: Textfield and JPasswordField ActionListener not working

    Please read the link in my signature on asking questions the smart way. What exactly do you mean by not working? Where is your SSCCE?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Junior Member
    Join Date
    Nov 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Textfield and JPasswordField ActionListener not working

    Quote Originally Posted by KevinWorkman View Post
    Please read the link in my signature on asking questions the smart way. What exactly do you mean by not working? Where is your SSCCE?
    Sorry. My actionlistener is not working for any of my components.

  4. #4
    Super Moderator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,097
    Thanks
    169
    Thanked 779 Times in 725 Posts
    Blog Entries
    5

    Default Re: Textfield and JPasswordField ActionListener not working

    Define 'not working'. Have you added println debug statements to see if they are getting called? Best to read post #2 again, in particular the link to the page describing what an SSCCE is.

Similar Threads

  1. ActionListener not working when button is clicked.
    By JamEngulfer221 in forum AWT / Java Swing
    Replies: 19
    Last Post: April 10th, 2012, 04:23 PM
  2. ActionListener inside another ActionListener
    By kpat in forum AWT / Java Swing
    Replies: 6
    Last Post: March 28th, 2012, 03:43 PM
  3. ComboBox and TextField
    By fahad in forum AWT / Java Swing
    Replies: 2
    Last Post: May 31st, 2010, 08:47 AM
  4. Need Help with my JComboBox and Textfield
    By superawesome in forum AWT / Java Swing
    Replies: 1
    Last Post: November 10th, 2009, 11:15 AM
  5. JComboBox and Textfield
    By Nexusfactor in forum AWT / Java Swing
    Replies: 3
    Last Post: November 9th, 2009, 11:57 AM