Ação do botão - calcular

Seguinte, quero implementar um botão que ao clicar ele faça a ação de calcular as respectivas porcentagens e exibir o valor no final no label, beleza, eu não sei muito como funciona o Listener, gostaria de que através deste exemplo, pudessem me ajudar a entender.
Grato!
image

 package telas;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;

    import javax.swing.*;
    import java.awt.Toolkit;
    public class CalculadoraImposto extends JFrame{
    	//Declarando os componentes
    	public JLabel lblTituloPrograma;
    	public JLabel lblValorTotalNota;
    	public JLabel lblIrrf;
    	public JLabel lblPis;
    	public JLabel lblCofins;
    	public JLabel lblCsll;
    	public JLabel lbltotal;
    	public JLabel lblPorcentagem;
    	public JButton btnCalcular;

    	public JTextField txtValorTotalNota;
    	public JTextField txtIrff;
    	public JTextField txtPis;
    	public JTextField txtCofins;
    	public JTextField txtCsll;
    	

    //construtor 
    	public CalculadoraImposto(){
    		
    		//look and feel pega do OS atual
    		try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } 
        catch (Exception e) {
        }
    				this.setResizable(false);
    				this.setTitle("Calculadora");
    				this.setBounds(50,50,300,310);
    				this.getContentPane().setLayout(null);
    				
    				
    					
    		//label - Titulo do Programa
    				lblTituloPrograma = new JLabel();
    				lblTituloPrograma.setText("Calculadora de Impostos");
    				lblTituloPrograma.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/calculadora.png")));
    				lblTituloPrograma.setBounds(50,2,190,50);
    				this.add(lblTituloPrograma);
    				
    		//label - valor total da nota
    				lblValorTotalNota = new JLabel();
    				lblValorTotalNota.setText("Valor total da Nota:");
    				lblValorTotalNota.setBounds(10,40,108,50);
    				this.add(lblValorTotalNota);
    		
    		//textfield - valor total nota
    				txtValorTotalNota = new JTextField();
    				txtValorTotalNota.setBounds(110,55,70,20);
    		        this.add(txtValorTotalNota);
    		
    		 //label - porcentagem taxa
    				lblPorcentagem = new JLabel();
    				lblPorcentagem.setText("Insira a taxa %");
    				lblPorcentagem.setBounds(70,75,108,50);
    				this.add(lblPorcentagem);
    				
    		//label - lblIrrf
    				lblIrrf = new JLabel();
    				lblIrrf.setText("IRRF:");
    				lblIrrf.setBounds(40,95,108,50);
    				this.add(lblIrrf);
    		
    		//textfield - irff
    				txtIrff = new JTextField();
    				txtIrff.setBounds(70,110,70,20);
    				this.add(txtIrff);
    		
    		//label - lblPis
    				lblPis = new JLabel();
    				lblPis.setText("PIS:");
    				lblPis.setBounds(48,125,108,50);
    				this.add(lblPis);
    		
    		//textfield - pis
    				txtPis = new JTextField();
    				txtPis.setBounds(70,140,70,20);
    				this.add(txtPis);
    		
    		//label - lblCofins
    				lblCofins = new JLabel();
    				lblCofins.setText("COFINS:");
    				lblCofins.setBounds(27,150,108,50);
    				this.add(lblCofins);

    		//textfield - cofins
    				txtCofins = new JTextField();
    				txtCofins.setBounds(70,165,70,20);
    				this.add(txtCofins);
    		
    		//label - lblCsll
    				lblCsll = new JLabel();
    				lblCsll.setText("CSLL:");
    				lblCsll.setBounds(42,180,108,50);
    				this.add(lblCsll);
    				
    		//textfield - csll
    				txtCsll = new JTextField();
    				txtCsll.setBounds(70,195,70,20);
    				this.add(txtCsll);
    		
    		
    		
    		
    		
    		//botao calcular
    		btnCalcular = new JButton();
    		btnCalcular.setText("Calcular");
    		btnCalcular.setBounds(100, 240, 90, 25);
    		this.add(btnCalcular);
    		
    		
    		//acao do botao calcular
    		  btnCalcular.addActionListener(new ActionListener() {
    	            public void actionPerformed(ActionEvent evt) {
    	            	
    	               
    	            }
    	        });
    		  
    	}
    	
    	public static void main(String[] args) {
    		CalculadoraImposto exemplo = new CalculadoraImposto();
            exemplo.setVisible(true);
            
       
    	}
    }
btnCalcular.addActionListener(new ActionListener() {

    public void actionPerformed(ActionEvent evt) {
        // aqui você chama algum método para realizar o que você deseja
    }
});

Esta parte eu entendi, mas como fazer isso que não sei…
Tô querendo fazer o seguinte, o usuário insere os valores, o valor total da nota, e ele sabe as porcentagens de cada imposto, quando clicar no botão calcular, aparece na frente dos impostos os valores dos respectivos impostos…
image
esses vermelhos serão os label que receberá os valores do respectivo imposto
image
quando clicar em calcular, ele aparece o valor de cada imposto na frente

só que preciso aprender … converter string para double, saber como colocar para que quando o usuário digitar, aparecer a vírgula e a % após o número.
Sei que para fazer isso, toda ação ficará num só botão, agora como fazer isso eu não tô conseguindo

Você vai precisar pôr uns JLabels para apresentar valores nos retângulos vermelhos.

Trate o acionamento do botão assim:

// acao do botao calcular
btnCalcular.addActionListener(event -> apresentarResultados());

E implemente estes métodos:

private void apresentarResultados() {
    double valorTotalNota = doubleValue(txtValorTotalNota);

    double cofins = doubleValue(txtCofins) / 100.0;
    double csll = doubleValue(txtCsll) / 100.0;
    double irff = doubleValue(txtIrff) / 100.0;
    double pis = doubleValue(txtPis) / 100.0;

    lblResultadoCofins.setText(String.format("%.2f", cofins * valorTotalNota));
    lblResultadoCsll.setText(String.format("%.2f", csll * valorTotalNota));
    lblResultadoIrrf.setText(String.format("%.2f", irff * valorTotalNota));
    lblResultadoPis.setText(String.format("%.2f", pis * valorTotalNota));
}

// retorna o conteúdo do JTexField informado na forma de um double
private double doubleValue(JTextField textField) {
    String text = textField.getText().trim();
    if (text.isEmpty()) {
        return 0.0;
    }
    return Double.parseDouble(text);
}
1 curtida

vou tentar aqui parceiro e te dou um feedback, no momento grato!