java 实现创建拨号_电话拨号盘的实现

本文展示了一个使用Java实现的电话拨号盘程序,包括文本输入框和按钮组件。当用户点击按钮时,程序会在文本域中显示所按数字。目前的问题是如何在用户连续点击特定按钮组合(如1,1,0)时,在文本域中显示对应的组合数字(如110)。" 131764958,17783637,提升自动化测试稳定性和可维护性的策略,"['自动化测试', 'pytest', '运维', 'allure', '测试框架']
摘要由CSDN通过智能技术生成

电话拨号盘的实现

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咋实现?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值