⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 phonepad1.java

📁 idea to make mobile phone interface in java
💻 JAVA
字号:
import java.util.*;
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class PhonePad1 implements ActionListener {

    private JFrame frame;
    private JPanel panel;
    private JTextField textField = new JTextField();

    public PhonePad1() {
    }

    public void createWindow() {

        System.out.println("Initializing Window");

        frame = new JFrame("London Telepad");

        frame.addWindowListener(new WindowAdapter() {
               public void windowClosing(WindowEvent e) {
                   System.exit(0);
               }
        });

        // Lets set a layout for the frame.
        frame.getContentPane().setLayout(new BorderLayout());

        // At the top lets add our textField.
        // We align the numbers to the right and then add it to the top panel.
        textField.setHorizontalAlignment(JTextField.RIGHT);
        frame.getContentPane().add(textField, BorderLayout.NORTH);

        panel = new JPanel();
        panel.setLayout(new GridLayout(4, 3));
        JButton butt1 = new JButton("1");
        JButton butt2 = new JButton("2");
        JButton butt3 = new JButton("3");
        JButton butt4 = new JButton("4");
        JButton butt5 = new JButton("5");
        JButton butt6 = new JButton("6");
        JButton butt7 = new JButton("7");
        JButton butt8 = new JButton("8");
	JButton butt9 = new JButton("9");
        JButton butt10 = new JButton("C" );
        JButton buttback = new JButton("back");
        JButton butt0 = new JButton("0");
       


        butt0.addActionListener(this);
        butt1.addActionListener(this);
        butt2.addActionListener(this);
        butt3.addActionListener(this);
        butt4.addActionListener(this);
        butt5.addActionListener(this);
        butt6.addActionListener(this);
        butt7.addActionListener(this);
        butt8.addActionListener(this);
	butt9.addActionListener(this);
        butt10.addActionListener(this);
        
        
        panel.add(butt1);
        panel.add(butt2);
        panel.add(butt3);
        panel.add(butt4);
        panel.add(butt5);
        panel.add(butt6);
        panel.add(butt7);
        panel.add(butt8);
        panel.add(butt9);
	panel.add(buttback);
        panel.add(butt0);
        panel.add(butt10);
       

    
        // Lets put our number pad in the middle
        frame.getContentPane().add(panel, BorderLayout.CENTER);

        frame.setSize(200, 300);
        frame.setVisible(true);

        System.out.println("Window Initialized");
    }

    // method needed for testing with Robot class

    public JFrame getFrame() {

        return frame;
    }

    public static void main(String args[]) {

        PhonePad1 app = new PhonePad1();
        app.createWindow();
    }

    public void actionPerformed(ActionEvent e) {

        // Get text from textfield
        String keyedin = textField.getText();

        // If this was issued by a key that reads "Delete" and there is values in the textfiled
        // then remove the last digit. otherwise add to the field as normal.

        if (e.getActionCommand().equals("C")) {
                if (keyedin.length() > 0) {
                        textField.setText(keyedin.substring(0,keyedin.length() - 1));
                }
        }
        else {
        
                textField.setText(textField.getText() + e.getActionCommand());
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -