| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1958 人关注过本帖
标题:电话拨号盘的实现
只看楼主 加入收藏
kai
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:52
帖 子:3450
专家分:59
注 册:2004-4-25
收藏
得分:0 
// 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;
    }
  }
}

自由,民主,平等,博爱,进步.
中华民国,我的祖国,中华民国万岁!中华民国加油!
本人自愿加入中国国民党,为人的自由性,独立性和平等性而奋斗!
2005-08-24 00:05
tmy300
Rank: 1
等 级:新手上路
帖 子:33
专家分:0
注 册:2005-8-11
收藏
得分:0 
以下是引用飘飘叶子在2005-8-23 21:25:44的发言: 这道题目的完整题目怎么样的啊?说来听听…… 楼上几位都是上海北大青鸟的么?哪个分校?
呵呵!我是厦门分校的!

2005-08-24 16:01
快速回复:电话拨号盘的实现
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.011851 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved