Numeric Keypad (Basic Java Programming)

Hi all, here is the problem.  I need to design and implement a java program that displays a numeric keypad that might appear on a phone. Above the keypad buttons I need to show a label that displays the numbers as they are picked. To the right of the keypad buttons, I need to include another button to clear the display. I'm thinking that the "Border Layout" may be the best Layout Manager for this task. With a "Grid Layout" within one of the Border Layout fields. The book (I'm taking a java class, if you haven't figured that out yet.) doesn't explain how to call an call a panel into an existing panel.  Here is what I have so far.

//********************************************************************
//  BorderDemo.java      
//
//  Demonstrates the use of various types of borders.
//********************************************************************

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

public class PhoneReal extends JPanel
{
   //-----------------------------------------------------------------
   //  Creates several bordered panels and displays them.
   //-----------------------------------------------------------------
   
      
      public static void main (String[] args)
   {
      JFrame frame = new JFrame ("Phone");
      frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
            
     
      JPanel panel = new JPanel();
      panel.setLayout (new GridLayout (4, 3));
      panel.setBorder (BorderFactory.createLineBorder (Color.gray, 3));
      panel.setBackground (Color.white);

      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 b0 = new JButton ("0");

      panel.add (b1);
      panel.add (b2);
      panel.add (b3);
      panel.add (b4);
      panel.add (b5);
      panel.add (b6);
      panel.add (b7);
      panel.add (b8);
      panel.add (b9);
      panel.add (b0);
     
            frame.getContentPane().add (panel);
      frame.pack();
      frame.setVisible(true);
            
   }
}

So I'm really lost.  Some examples on how to do the above describe problem would be great. Thank you.
romeotheriaultAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

GrandSchtroumpfCommented:
Example adding a panel to the north of another panel:

JPanel myPanel = ...  // this is the panel you want to add to the other panel

BorderLayout bLayout new BorderLayout();
JPanel bPanel = new JPanel(bLayout);
bPanel.add(myPanel, BorderLayout.NORTH);
0
GrandSchtroumpfCommented:
0
GrandSchtroumpfCommented:
oooops,
BorderLayout bLayout new BorderLayout();
should have been
BorderLayout bLayout = new BorderLayout();
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

ThummalaRaghuveerCommented:
Here is the code that helps you with Layout but Implement action listeners for all buttons to get the functionality....

// ********************************************************************
//BorderDemo.java
//
//Demonstrates the use of various types of borders.
//********************************************************************

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.GridLayout;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class PhoneReal extends JPanel {
    //-----------------------------------------------------------------
    //  Creates several bordered panels and displays them.
    //-----------------------------------------------------------------

    public static void main(String[] args) {
        JFrame frame = new JFrame("Phone");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        JPanel panel = new JPanel();
        panel.setLayout(new GridLayout(4, 3));
        //panel.setBorder(BorderFactory.createLineBorder(Color.gray, 3));
        panel.setBackground(Color.white);

        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 b0 = new JButton("0");

        panel.add(b1);
        panel.add(b2);
        panel.add(b3);
        panel.add(b4);
        panel.add(b5);
        panel.add(b6);
        panel.add(b7);
        panel.add(b8);
        panel.add(b9);
        panel.add(b0);

        frame.getContentPane().setLayout(new BorderLayout());
        frame.getContentPane().add(panel,BorderLayout.CENTER);
        JButton clearBt = new JButton("Clear");
        JTextField number = new JTextField();
        number.setColumns(15);
        frame.getContentPane().add(number,BorderLayout.NORTH);
        frame.getContentPane().add(clearBt,BorderLayout.WEST);
        System.out.println(frame.getContentPane().getLayout());
        System.out.println(frame.getContentPane().getComponentCount());
        frame.pack();
        frame.setVisible(true);

    }
}
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
GrandSchtroumpfCommented:
ThummalaRaghuveer,
we're not supposed to do other people's homework, we should just guide them.
0
GrandSchtroumpfCommented:
<:°)
0
romeotheriaultAuthor Commented:
GrandSchtroumpf, how did you get that little O that makes his mouth.
0
GrandSchtroumpfCommented:
> that little O that makes his mouth.
it's a "degree" sign and it's supposed to be his round nose, lol.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.