Q:

How to Disable JButton

I want my JButton to be Disabled until all of the fields has inputs.
package Grade;

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class GradeGUI extends JFrame {
    private  JLabel quizL,exerL,partL,partLL,examL,finalSL,totalIL,totalL,blankL,blankL2,blankL3,blankL4,blankL5,blankL6,blankL7,blankL8;
    private  JTextField quizTF,exerTF,examTF,partTF,quizTF1,exerTF1,examTF1,total1,total2,total3,total4,totalF,letterTF;
    private  JButton calculateB,exitB;
    private  CalculateButtonHandler cbHandler;
   private  ExitButtonHandler exitHandler;

    public GradeGUI(){
        blankL8=new JLabel("");
        blankL7=new JLabel("");
        blankL6=new JLabel("");
        blankL5=new JLabel("");
        blankL4=new JLabel("");
        blankL3=new JLabel("");
        blankL2=new JLabel("");
        blankL=new JLabel("");
        partLL=new JLabel("");
        quizL=new JLabel("Quiz: ");
        exerL=new JLabel("Exercise: ");
        partL=new JLabel("Participation: ");
        examL=new JLabel("Exams: ");
        finalSL=new JLabel("Final Score");
        totalIL=new JLabel("Total # of Items");
        totalL=new JLabel("Final Score");

        letterTF=new JTextField(25);
        quizTF=new JTextField(25);
        exerTF=new JTextField(25);
        examTF=new JTextField(25);
        partTF=new JTextField(25);
        quizTF1=new JTextField(25);
        exerTF1=new JTextField(25);
        examTF1=new JTextField(25);
        total1=new JTextField(25);
        total2=new JTextField(25);
        total3=new JTextField(25);
        total4=new JTextField(25);
        totalF=new JTextField(25);

        total1.setEditable(false);
        total2.setEditable(false);
        total3.setEditable(false);
        total4.setEditable(false);
        totalF.setEditable(false);
        letterTF.setEditable(false);

        calculateB=new JButton("Calculate");
        exitB=new JButton("Exit");

        calculateB=new JButton("Calculate");
        cbHandler= new CalculateButtonHandler();
        calculateB.addActionListener(cbHandler);

        exitB=new JButton("Exit");
        exitHandler= new ExitButtonHandler();
        exitB.addActionListener(exitHandler);

         setTitle("Grade Calculator");

        Container p = getContentPane();
        p.setLayout(new GridLayout(6,5));

        p.add(blankL);
        p.add(finalSL);
        p.add(totalIL);
        p.add(totalL);
        p.add(blankL4);
        p.add(quizL);
        p.add(quizTF);
        p.add(quizTF1);
        p.add(total1); 
        p.add(blankL5);
        p.add(exerL);
        p.add(exerTF);
        p.add(exerTF1);
        p.add(total2);
        p.add(blankL6);
        p.add(partL);
        p.add(partTF);

        p.add(blankL2);
        p.add(total3);
        p.add(blankL7);
        p.add(examL);
        p.add(examTF);
        p.add(examTF1);
        p.add(total4);
        p.add(blankL8);
        p.add(blankL3);
        p.add(calculateB);
        p.add(exitB);
        p.add(totalF);
        p.add(letterTF);

        setSize(500,400);

        setVisible(true);
        setDefaultCloseOperation(EXIT_ON_CLOSE);

    }

    private class CalculateButtonHandler implements ActionListener{
    public void actionPerformed(ActionEvent e){

       try{ 
        double quiz,exam,exer,part,quizT,examT,exerT;
        double total11,total22,total33,total44,totalFf;
        double quizTT,examTT,partTT,exerTT;

        quiz=Integer.parseInt(quizTF.getText());
        exam=Integer.parseInt(examTF.getText());
        exer=Integer.parseInt(exerTF.getText());
        part=Integer.parseInt(partTF.getText());

        quizT=Integer.parseInt(quizTF1.getText());
        examT=Integer.parseInt(examTF1.getText());
        exerT=Integer.parseInt(exerTF1.getText());

        quizTT=((quiz/quizT)*100)*0.20;
        examTT=((exam/examT)*100)*0.30;
        partTT=part*0.10;
        exerTT=((exer/exerT)*100)*0.40;

        total1.setText(""+quizTT);
        total2.setText(""+examTT);
        total3.setText(""+partTT);
        total4.setText(""+exerTT);

        total11=Double.parseDouble(total1.getText());
        total22=Double.parseDouble(total2.getText());
        total33=Double.parseDouble(total3.getText());
        total44=Double.parseDouble(total4.getText());

        totalFf=total11+total22+total33+total44;
        totalF.setText(""+totalFf);

        if(totalFf>=95){

            letterTF.setText("A");
        }else if(totalFf>=90){

            letterTF.setText("B");
        }else if(totalFf>=85){

            letterTF.setText("C");
        }else if(totalFf>=80){

            letterTF.setText("D");
        }else if(totalFf>=75){

            letterTF.setText("E");
        }else{
            letterTF.setText("F");
        }
         }catch(Exception s){
             JOptionPane.showMessageDialog(null,"Please Try Again!!","ERROR",JOptionPane.ERROR_MESSAGE);
    }

    }
}

    private class ExitButtonHandler implements ActionListener{
        public void actionPerformed(ActionEvent e){

            System.exit(0);
        }
    }

    public static void main(String[]args){

        GradeGUI a=new GradeGUI();
    }
}

A:

Using the JTextField class's addCaretListener method, you can check for changes in each text field. When characters are typed into a text field, the caret's position will change, and a javax.swing.event.CaretEvent will be fired, which you can use to check if each text field is empty or not; based on this, you can then set your button to be enabled or disabled. For example:
quizTF.addCaretListener(new CaretListener() {
    public void caretUpdate(CaretEvent ev) {
        calculateB.setEnabled(!quizTF.getText().isEmpty() && !exerTF.getText().isEmpty() && ...);
    }
});

// code here

Personally, I would place all your JTextField objects in an ArrayList or something similar so you can loop through and perform operations on them and it won't be tedious writing so much code.

