0

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);	

    }
}
2
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by imKEN
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.