Q:

Can't get action listener to work with JButton and JText

Today I am attempting to create a GUI with a text field and three buttons. The user will be able to input a variety of numbers in the text field and depending upon the number they type and the button clicked various decision statements will occur. 
I have created my code and added the action listeners but for some reason the action listener for my first button doesn't work. I want it to change the value of a variable I am using as a counter or another method if it works better. I will paste me code below if someone can tell and show me how to accomplish what I want I would very much appreciate it! 
package nacha;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class Testing extends javax.swing.JFrame
{

    static  String code = null;
    static int button1Toggle = 0;

    public static void main(String args[]){

        int sixBatch1TotalCounter=1;
        int sixBatch1Total=2;
        int main = 1000001;

        JPanel p = new JPanel();
        JPanel p2 = new JPanel();

        BorderLayout layout = new BorderLayout();

        layout.setHgap(10);
        layout.setVgap(10);

        final JTextField reasonCode = new JTextField(10);

        reasonCode.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent ev){
                Object source = ev.getSource();
                }
                });

        JButton button1 = new JButton("Next");
        button1.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent ev){
            button1Toggle=1;
            }
            });

        final JButton button2 = new JButton("Next Batch");
        button2.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent ev){

            }
        });

        final JButton button3 = new JButton("Submit");
        button3.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent ev){

            }
        });

        JLabel label = new JLabel("<html>" +
                "Entry Detail: "+
                "<br>"+main+
                "<br>Entry Detail "+sixBatch1TotalCounter+" of "+sixBatch1Total+
                "<br><br>Please type 1-21 to apply reason code and addenda record to the entry detail record."+
                "<br>To omit displayed entry detail from the return, simply leave the input line blank and press enter."+
                "<br><br>Reason Code Descriptions:"+
                "<br>R01 - Insufficient Funds"+
                "<br>R02 - Account Closed"+
                "<br>R03 - No Account"+
                "<br>R04 - Invalid Account Number"+
                "<br>R05 - Unauthorized Debit to Consumer Account Using Corporate SEC Code"+
                "<br>R06 - Returned per ODFI Request"+
                "<br>R07 - Auth Revoked by Customer"+
                "<br>R08 - Payment Stopped"+
                "<br>R09 - Uncollected Funds"+
                "<br>R10 - Customer Advises Not Authorized"
                );

        p.setLayout(layout);
        p.add(label,BorderLayout.NORTH);
        p.add(reasonCode,BorderLayout.SOUTH);
        p2.add(button1,BorderLayout.WEST);
        p2.add(button2,BorderLayout.CENTER);
        p2.add(button3, BorderLayout.EAST);

        JFrame frame = new JFrame();
        frame.setSize(450,450);

        BorderLayout BorderLayout = new BorderLayout();
        BorderLayout.setHgap(10);
        BorderLayout.setVgap(10);

        frame.setLayout(BorderLayout);
        frame.add(p,BorderLayout.NORTH);
        frame.add(p2,BorderLayout.SOUTH);

        frame.setVisible(true);

            code = reasonCode.getText();
            if (reasonCode.getText().equals("1") && button1Toggle==1){
                System.out.println("Pass");

            }

        }

    }

A:

Hovercraft really answered this question in the comments.
Quoted:
That if block at the end will be called once and only once, and will be called before the user even has a chance to interact with the GUI in any way. As noted above by @3kings, if you want that code called when the button is pressed, it had better be within the ActionListener. This question goes to the core of what it means to write event-driven programs, and you're going to want to think on this error and why it doesn't work as you've written it because this understanding must be met if you're to progress. 

