javaswingjprogressbar

How to change JTextArea when Progress Bar is 100%


I am very new to Java language and I started to make a program just by myself and the internet. For now I have this :

package com.butoane;

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

public class App {
private JButton apasaAiciButton;
private JPanel Dunno;
private JButton apoiaici;
private JTextArea text1;
private JProgressBar progressBar1;
private JTextArea text2;

public App() {
   String a = "H";
   String b = "e";
   String y = "Ce faci sefule??";
    final String[] d = {"x"};
    final String[] f = {"D"};
    final int[] c = {0};
    apasaAiciButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            //apoiaici.setEnabled(true);
            //apasaAiciButton.setEnabled(false);
            text1.append(a);
            progressBar1.setValue(c[0] +1);
            c[0] = c[0] +1;
        }

    });
    apoiaici.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            //apoiaici.setEnabled(false);
            //apasaAiciButton.setEnabled(true);
            apasaAiciButton.setText("Apasa iar aici");
            text1.append(b);
            progressBar1.setValue(c[0] +1);
            c[0] = c[0] +1;
        }
    });

    }

public static void main(String[] args) {
    JFrame frame = new JFrame("App");
    frame.setContentPane(new App().Dunno);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.pack();
    frame.setVisible(true);
}
}

What I want to do is to add a functionality to text2 when progress bar is 100%. For example : When progressbar1 will be 100% , text2 to set the text to "You did it!" . How can I make this?

FYK : I viewed oracle docs about JProgressBar and JTextArea and I could not understand a thing.


Solution

  • Does the progress bar work? if it works, then just add.

    //the max value of the progress bar == actual value
    if (progressBar1.getMaximum() == progressBar1.getValue() {
        text2.append("You did it!");
    }