// try it
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
public class Myframe50 extends JFrame
{
JTextField txt1,txt2;
Mypanel1 p1;
public Myframe50()
{
setTitle("电话拨号盘");
txt1=new JTextField(20);
txt2=new JTextField(20);
p1=new Mypanel1(txt1, txt2);
this.getContentPane().setLayout(new BorderLayout());
this.getContentPane().add(txt1,BorderLayout.NORTH);
this.getContentPane().add(p1,BorderLayout.CENTER);
this.getContentPane().add(txt2,BorderLayout.SOUTH);
setSize(200,250);
setLocation(300,300);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);
}
public static void main(String args[])
{
new Myframe50();
}
}
class Mypanel1 extends JPanel implements ActionListener
{
JButton b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12;
Font f;
JTextField txt1,txt2;
StringBuffer sb = new StringBuffer();
public Mypanel1(JTextField txt1, JTextField txt2)
{
this.txt1 = txt1;
this.txt2 = txt2;
f=new Font("Arial",Font.BOLD,14);
b1=new JButton("1");
b1.setActionCommand("1");
b2=new JButton("2");
b2.setActionCommand("2");
b3=new JButton("3");
b3.setActionCommand("3");
b4=new JButton("4");
b4.setActionCommand("4");
b5=new JButton("5");
b5.setActionCommand("5");
b6=new JButton("6");
b6.setActionCommand("6");
b7=new JButton("7");
b7.setActionCommand("7");
b8=new JButton("8");
b8.setActionCommand("8");
b9=new JButton("9");
b9.setActionCommand("9");
b10=new JButton("*");
b10.setActionCommand("*");
b11=new JButton("0");
b11.setActionCommand("0");
b12=new JButton("#");
b12.setActionCommand("#");
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
b5.addActionListener(this);
b6.addActionListener(this);
b7.addActionListener(this);
b8.addActionListener(this);
b9.addActionListener(this);
b10.addActionListener(this);
b11.addActionListener(this);
b12.addActionListener(this);
b1.setFont(f);
b2.setFont(f);
b3.setFont(f);
b4.setFont(f);
b5.setFont(f);
b6.setFont(f);
b7.setFont(f);
b8.setFont(f);
b9.setFont(f);
b10.setFont(f);
b11.setFont(f);
b12.setFont(f);
this.setLayout(new GridLayout(4,3));
this.add(b1);
this.add(b2);
this.add(b3);
this.add(b4);
this.add(b5);
this.add(b6);
this.add(b7);
this.add(b8);
this.add(b9);
this.add(b10);
this.add(b11);
this.add(b12);
}
public void actionPerformed(ActionEvent e)
{
char command = e.getActionCommand().charAt(0);
switch(command)
{
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
case '0':
sb.append(command);
txt1.setText(sb.toString());
break;
case '*':
txt1.setText(null);
txt2.setText(null);
sb = new StringBuffer();
break;
case '#':
if(txt1.getText().equals("110")||txt1.getText().equals("119"))
txt2.setText("正在拨号:"+txt1.getText());
else if(txt1.getText().charAt(0)=='0')
txt2.setText("无效号码:"+txt1.getText());
else
{
if(txt1.getText().length()==8)
txt2.setText("正在拨号"+txt1.getText());
else
txt2.setText("不是市话");
}
break;
}
}
}
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
public class Myframe50 extends JFrame
{
JTextField txt1,txt2;
Mypanel1 p1;
public Myframe50()
{
setTitle("电话拨号盘");
txt1=new JTextField(20);
txt2=new JTextField(20);
p1=new Mypanel1(txt1, txt2);
this.getContentPane().setLayout(new BorderLayout());
this.getContentPane().add(txt1,BorderLayout.NORTH);
this.getContentPane().add(p1,BorderLayout.CENTER);
this.getContentPane().add(txt2,BorderLayout.SOUTH);
setSize(200,250);
setLocation(300,300);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);
}
public static void main(String args[])
{
new Myframe50();
}
}
class Mypanel1 extends JPanel implements ActionListener
{
JButton b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12;
Font f;
JTextField txt1,txt2;
StringBuffer sb = new StringBuffer();
public Mypanel1(JTextField txt1, JTextField txt2)
{
this.txt1 = txt1;
this.txt2 = txt2;
f=new Font("Arial",Font.BOLD,14);
b1=new JButton("1");
b1.setActionCommand("1");
b2=new JButton("2");
b2.setActionCommand("2");
b3=new JButton("3");
b3.setActionCommand("3");
b4=new JButton("4");
b4.setActionCommand("4");
b5=new JButton("5");
b5.setActionCommand("5");
b6=new JButton("6");
b6.setActionCommand("6");
b7=new JButton("7");
b7.setActionCommand("7");
b8=new JButton("8");
b8.setActionCommand("8");
b9=new JButton("9");
b9.setActionCommand("9");
b10=new JButton("*");
b10.setActionCommand("*");
b11=new JButton("0");
b11.setActionCommand("0");
b12=new JButton("#");
b12.setActionCommand("#");
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
b5.addActionListener(this);
b6.addActionListener(this);
b7.addActionListener(this);
b8.addActionListener(this);
b9.addActionListener(this);
b10.addActionListener(this);
b11.addActionListener(this);
b12.addActionListener(this);
b1.setFont(f);
b2.setFont(f);
b3.setFont(f);
b4.setFont(f);
b5.setFont(f);
b6.setFont(f);
b7.setFont(f);
b8.setFont(f);
b9.setFont(f);
b10.setFont(f);
b11.setFont(f);
b12.setFont(f);
this.setLayout(new GridLayout(4,3));
this.add(b1);
this.add(b2);
this.add(b3);
this.add(b4);
this.add(b5);
this.add(b6);
this.add(b7);
this.add(b8);
this.add(b9);
this.add(b10);
this.add(b11);
this.add(b12);
}
public void actionPerformed(ActionEvent e)
{
char command = e.getActionCommand().charAt(0);
switch(command)
{
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
case '0':
sb.append(command);
txt1.setText(sb.toString());
break;
case '*':
txt1.setText(null);
txt2.setText(null);
sb = new StringBuffer();
break;
case '#':
if(txt1.getText().equals("110")||txt1.getText().equals("119"))
txt2.setText("正在拨号:"+txt1.getText());
else if(txt1.getText().charAt(0)=='0')
txt2.setText("无效号码:"+txt1.getText());
else
{
if(txt1.getText().length()==8)
txt2.setText("正在拨号"+txt1.getText());
else
txt2.setText("不是市话");
}
break;
}
}
}
自由,民主,平等,博爱,进步.
中华民国,我的祖国,中华民国万岁!中华民国加油!
本人自愿加入中国国民党,为人的自由性,独立性和平等性而奋斗!