Question
Telephone Keypad Files Telephone.java and TelephonePanel.java contain the skeleton for a program to lay out a GUI that looks like telephone keypad with a title
Telephone Keypad
Files Telephone.java and TelephonePanel.java contain the skeleton for a program to lay out a GUI that looks like telephone keypad with a title that says Your Telephone!!. Save these files to your directory. Telephone.java is complete, but TelephonePanel.java is not. 1. Using the comments as a guide, add code to TelephonePanel.java to create the GUI. Some things to consider: a. TelephonePanel (the current object, which is a JPanel) should get a BorderLayout to make it easy to separate the title from the keypad. The title will go in the north area and the keypad will go in the center area. The other areas will be unused. b. You can create a JLabel containing the title and add it directly to the north section of the TelephonePanel. However, to put the keypad in the center you will first need to create a new JPanel and add the keys (each a button) to it, then add it to the center of the TelephonePanel. This new panel should have a 43 GridLayout. c. Your keypad should hold buttons containing 1 2 3, 4 5 6, 7 8 9, * 0 # in the four rows respectively. So youll create a total of 12 buttons. 2. Compile and run Telephone.java. You should get a small keypad and title. Grow the window (just drag the corner) and see how the GUI changes - everything grows proportionately. 3. Note that the title is not centered, but it would look nicer if it were. One way to do this is to create a new JPanel, add the title label to it, then add the new JPanel to the north area of the TelephonePanel (instead of adding the label directly). This works because the default layout for a JPanel is a centered FlowLayout, and the JPanel itself will expand to fill the whole north area. Modify your program in this way so that the title is centered.
//************************************************************ // Telephone.java // // Uses the TelephonePanel class to create a (functionless) GUI // like a telephone keypad with a title. // Illustrates use of BorderLayout and GridLayout. //************************************************************ import javax.swing.*; public class Telephone { public static void main(String[] args) { JFrame frame = new JFrame("Telephone"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().add(new TelephonePanel()); frame.pack(); frame.setVisible(true); } }
//************************************************************ // TelephonePanel.java // // Lays out a (functionless) GUI like a telephone keypad with a title. // Illustrates use of BorderLayout and GridLayout. //************************************************************ import java.awt.*; import javax.swing.*; public class TelephonePanel extends JPanel { public TelephonePanel() { //set BorderLayout for this panel //create a JLabel with "Your Telephone" title //add title label to north of this panel //create panel to hold keypad and give it a 4x3 GridLayout //add buttons representing keys to key panel //add key panel to center of this panel } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started