Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.*;
- import javax.swing.border.*;
- import java.awt.*;
- //Nothing special here, just importing the stuff we need.
- public class phoneDialer {
- void PhoneDialer() { //We create the GUI in the constructor.
- JFrame Dialer = new JFrame();
- Dialer.setSize(200, 250); //Size of the window should be 200 by 250 pixels
- Dialer.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //This should cause the program to exit when you press the "X" in the corner of the window.
- JPanel mainPanel = new JPanel();
- mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS)); //Creating a new JPanel and assigning it a vertical layout
- Border newBorder = BorderFactory.createEmptyBorder(10, 10, 10, 10); //Creating a new border for use in between buttons
- mainPanel.setBorder(newBorder); //Setting newPanel to use newBorder
- JPanel topLabel = new JPanel(new FlowLayout());
- topLabel.add(new JLabel("Enter the number to dial:")); //Making a new Panel and giving it a label
- JPanel gridPanel = new JPanel(new GridLayout(4, 3, 5, 5)); //Creating a new JPanel for the buttons, and giving it a grid layout
- Border gridBorder = BorderFactory.createEmptyBorder(5, 5, 5, 5);
- gridPanel.setBorder(gridBorder); //Creating and setting the border for gridPanel
- gridPanel.add(new JButton("1"));
- gridPanel.add(new JButton("2"));
- gridPanel.add(new JButton("3"));
- gridPanel.add(new JButton("4"));
- gridPanel.add(new JButton("5"));
- gridPanel.add(new JButton("6"));
- gridPanel.add(new JButton("7"));
- gridPanel.add(new JButton("8"));
- gridPanel.add(new JButton("9"));
- gridPanel.add(new JButton("-"));
- gridPanel.add(new JButton("0"));
- mainPanel.add(topLabel, gridPanel);
- mainPanel.add(new JButton("Dial Number"), Component.CENTER_ALIGNMENT);
- mainPanel.setVisible(true);
- }
- }
- public static void main(String[] args) {
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement