I'm making a simple java calculator. I'm done with the GUI part but don't know how to start on it's functions.

Anyone can tell and help me how to start it's function?

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

class Calculator extends JFrame
{
	private JPanel p1,p2;
	private JTextField tf;
	private JButton b[];
	private String bs[] = {"7","8","9","/","4","5","6","*","1","2","3","-","0",".","=","+"};
	
	Calculator()
	{
		super("Calculator");
		p1 = new JPanel();
		p2 = new JPanel();
		tf = new JTextField(20);
		tf.setEditable(false);
		p1.add(tf);
		b = new JButton[bs.length];
		for(int t=0;t<b.length;t++)
		{
			b[t] = new JButton (bs[t]);
			p2.add(b[t]);
		}
		
		
		p2.setLayout(new GridLayout(4,4));
		add(p1,BorderLayout.NORTH);
		add(p2);
		
	}
	
}

public class TestCalculator {
    
    public static void main(String[] args) {
    Calculator c = new Calculator();
    c.setBounds(200,200,230,249);
    c.setVisible(true);
    c.setResizable(false);
    c.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);	

    }
}

how can i assign one action listener to each buttons?

with add ActionListener to JButton

I mean with buttons that are in an array.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.