Hello. I'm trying to make a calculator with JFrame. I'm only gonna make the appearance of the calculator (not functioning). The numbers and operators are supposed to be arranged this way:

7 8 9 +
4 5 6 -
1 2 3 x
# 0 * /

however, I only know borderlayout and flowlayout. Is there any layout or anything that will make the operators and number arranged that way (above)?

I've made a java code. Here it is:

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Calculator.java
 *
 * Created on Sep 7, 2009, 3:19:12 PM
 */

package calculator;

import java.awt.*;
import javax.swing.*;
/**
 *
 * @author William
 */
public class Calculator extends javax.swing.JFrame {

    /** Creates new form Calculator */
    public Calculator() {

        this.setLayout(new BorderLayout());
        JLabel lbl = new JLabel("Calculator");

        JTextField tf = new JTextField(30);
        tf.setBackground(Color.yellow);

        JPanel p1 = new JPanel();
        p1.setLayout(new BorderLayout());
        p1.add(lbl, BorderLayout.NORTH);
        p1.add(tf, BorderLayout.SOUTH);

        JButton b1 = new JButton("1");
        JButton b2 = new JButton("2");
        JButton b3 = new JButton("3");
        JButton b4 = new JButton("4");
        JButton b5 = new JButton("5");
        JButton b6 = new JButton("6");
        JButton b7 = new JButton("7");
        JButton b8 = new JButton("8");
        JButton b9 = new JButton("9");
        JButton b10 = new JButton("#");
        JButton b11 = new JButton("0");
        JButton b12 = new JButton("*");
        JButton b13 = new JButton("+");
        JButton b14 = new JButton("-");
        JButton b15 = new JButton("x");
        JButton b16 = new JButton("/");

        JPanel p2 = new JPanel(new FlowLayout());

        p2.add(b7);
        p2.add(b8);
        p2.add(b9);
        p2.add(b13);
        p2.add(b4);
        p2.add(b5);
        p2.add(b6);
        p2.add(b14);
        p2.add(b1);
        p2.add(b2);
        p2.add(b3);
        p2.add(b15);
        p2.add(b10);
        p2.add(b11);
        p2.add(b12);
        p2.add(b16);

        this.add(p1, BorderLayout.CENTER);
        this.add(p2, BorderLayout.CENTER);

        this.setTitle("Calculator");
        this.setVisible(true);




    }

thanks so much. ^_^

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.