Cats萌萌
想必你是初学者,为了让你更好的理解看一下这个程序吧import java.awt.BorderLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JPanel;import javax.swing.JTextField;public class Moble extends JFrame {// Java实现一个简单的手机面板及数字输入功能private static final long serialVersionUID = 1L;private JTextField txtView;public static void main(String args[]) {new Moble();}public Moble() {setTitle("Moble");setBounds(100, 100, 200, 300);setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);final JPanel panel = new JPanel();getContentPane().add(panel, BorderLayout.CENTER);setResizable(false);txtView = new JTextField();panel.setLayout(null);panel.add(txtView);final JButton btn1 = new JButton();btn1.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent arg0) {txtView.setText(txtView.getText().concat("1"));}});btn1.setText("1");btn1.setBounds(0, 73, 59, 23);panel.add(btn1);final JButton btn2 = new JButton();btn2.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent arg0) {txtView.setText(txtView.getText().concat("2"));}});btn2.setText("2");btn2.setBounds(65, 73, 59, 23);panel.add(btn2);final JButton btn3 = new JButton();btn3.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent arg0) {txtView.setText(txtView.getText().concat("3"));}});btn3.setText("3");btn3.setBounds(130, 73, 59, 23);panel.add(btn3);final JButton btn4 = new JButton();btn4.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent arg0) {txtView.setText(txtView.getText().concat("4"));}});btn4.setText("4");btn4.setBounds(0, 102, 59, 23);panel.add(btn4);final JButton btn5 = new JButton();btn5.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent arg0) {txtView.setText(txtView.getText().concat("5"));}});btn5.setText("5");btn5.setBounds(65, 102, 59, 23);panel.add(btn5);final JButton btn6 = new JButton();btn6.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent arg0) {txtView.setText(txtView.getText().concat("6"));}});btn6.setText("6");btn6.setBounds(130, 102, 59, 23);panel.add(btn6);final JButton btn7 = new JButton();btn7.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent arg0) {txtView.setText(txtView.getText().concat("7"));}});btn7.setText("7");btn7.setBounds(0, 131, 59, 23);panel.add(btn7);final JButton btn8 = new JButton();btn8.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent arg0) {txtView.setText(txtView.getText().concat("8"));}});btn8.setText("8");btn8.setBounds(65, 131, 59, 23);panel.add(btn8);final JButton btn9 = new JButton();btn9.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent arg0) {txtView.setText(txtView.getText().concat("9"));}});btn9.setText("9");btn9.setBounds(130, 131, 59, 23);panel.add(btn9);final JButton btn0 = new JButton();btn0.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent arg0) {txtView.setText(txtView.getText().concat("0"));}});btn0.setText("0");btn0.setBounds(68, 160, 57, 23);panel.add(btn0);txtView = new JTextField();txtView.setBounds(59, 24, 90, 21);panel.add(txtView);final JButton btnSend = new JButton();btnSend.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent arg0) {if (txtView.getText().indexOf("calling...") == -1) {txtView.setText(txtView.getText().concat("calling..."));} else {return;}}});btnSend.setText("Send");btnSend.setBounds(40, 189, 127, 23);panel.add(btnSend);final JButton btnclear = new JButton();btnclear.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent arg0) {txtView.setText("");}});btnclear.setText("Clear");btnclear.setBounds(40, 212, 127, 23);panel.add(btnclear);final JButton btnOff = new JButton();btnOff.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent arg0) {System.exit(0);}});btnOff.setText("Exit");btnOff.setBounds(40, 232, 127, 23);panel.add(btnOff);setVisible(true);}}