| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1958 人关注过本帖
标题:电话拨号盘的实现
取消只看楼主 加入收藏
爱好者
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2005-8-15
收藏
 问题点数:0 回复次数:1 
电话拨号盘的实现

import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*;

public class Myframe50 extends JFrame implements ActionListener { JTextField txt1,txt2; Mypanel1 p1; public Myframe50() { setTitle("电话拨号盘"); txt1=new JTextField(20); txt2=new JTextField(20); p1=new Mypanel1(); this.getContentPane().setLayout(new BorderLayout()); this.getContentPane().add(txt1,BorderLayout.NORTH); this.getContentPane().add(p1,BorderLayout.CENTER); this.getContentPane().add(txt2,BorderLayout.SOUTH); p1.b1.addActionListener(this); p1.b2.addActionListener(this); p1.b3.addActionListener(this); p1.b4.addActionListener(this); p1.b5.addActionListener(this); p1.b6.addActionListener(this); p1.b7.addActionListener(this); p1.b8.addActionListener(this); p1.b9.addActionListener(this); p1.b10.addActionListener(this); p1.b11.addActionListener(this); p1.b12.addActionListener(this); setSize(200,250); setLocation(300,300); setVisible(true); } public void actionPerformed(ActionEvent e) { if(e.getSource()==p1.b10) { txt1.setText(""); txt2.setText(""); } else if(e.getSource()==p1.b12) { if(Long.parseLong(txt1.getText())==110||Long.parseLong(txt1.getText())==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("不是市话"); } } } } public static void main(String args[]) { new Myframe50(); } } class Mypanel1 extends JPanel { JButton b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12; Font f; public Mypanel1() { f=new Font("Arial",Font.BOLD,14); b1=new JButton("1"); b2=new JButton("2"); b3=new JButton("3"); b4=new JButton("4"); b5=new JButton("5"); b6=new JButton("6"); b7=new JButton("7"); b8=new JButton("8"); b9=new JButton("9"); b10=new JButton("*"); b11=new JButton("0"); b12=new JButton("#"); 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); } } 各位高人,我初学JAVA,我做了一个电话拨号盘的程序,在文本域中得到单击按钮的名称,比如:单击 b1,再次单击b1,有单击b11,在文本域中应该得到110,用JAVA咋实现?

搜索更多相关主题的帖子: 拨号 电话 
2005-08-22 23:16
爱好者
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2005-8-15
收藏
得分:0 
我是北大青鸟的,有谁有其他的方法实现该功能?比如说:我在文本域中想得到按钮的名称,我用(e.getActionCommand())砸实现?
2005-08-23 17:43
快速回复:电话拨号盘的实现
数据加载中...
 
   



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

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