import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.BevelBorder;
@SuppressWarnings("serial")
public class TestPhoneNumber extends JFrame implements ActionListener
{
JTextArea result;
JTextField area;
JButton tijiao,qingchu,tuichu;
JPanel panel1,panel2,panel3,panel4;
public TestPhoneNumber()
{
setTitle("手机号码检测器");
Container c = getContentPane();
result = new JTextArea("请输入手机号码",3,10);
result.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
result.setFont(new Font("幼圆", Font.BOLD, 14));
result.setEditable(false);
result.setLineWrap(true);
result.setPreferredSize(new Dimension(250,50));
result.setBackground(new Color(200,200,252));
panel1 = new JPanel();
panel1.setBackground(new Color(229,238,250));
panel1.add(result);
area = new JTextField(22);
area.setPreferredSize(new Dimension(250,30));
area.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
area.setBackground(new Color(235,235,252));
panel2 = new JPanel();
panel2.setPreferredSize(new Dimension(250,35));
panel2.setBackground(new Color(229,238,250));
panel2.add(area);
tijiao = new JButton("开始检测");
tijiao.setFont(new Font("幼圆", Font.BOLD, 13));
tijiao.setPreferredSize(new Dimension(79,30));
tijiao.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
tijiao.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
tijiao.addActionListener(this);
qingchu = new JButton("全部清除");
qingchu.setFont(new Font("幼圆", Font.BOLD, 13));
qingchu.setPreferredSize(new Dimension(79,30));
qingchu.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
qingchu.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
qingchu.addActionListener(this);
tuichu = new JButton("退出");
tuichu.setFont(new Font("幼圆", Font.BOLD, 13));
tuichu.setPreferredSize(new Dimension(79,30));
tuichu.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
tuichu.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
tuichu.addActionListener(this);
panel3 = new JPanel();
panel3.setPreferredSize(new Dimension(250,35));
panel3.setBackground(new Color(229,238,250));
panel3.add(tijiao);
panel3.add(qingchu);
panel3.add(tuichu);
panel4 = new JPanel();
panel4.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
panel4.setBackground(new Color(229,238,250));
panel4.setLayout(new BoxLayout(panel4,BoxLayout.Y_AXIS));
panel4.add(panel1);
panel4.add(panel2);
panel4.add(panel3);
c.add(panel4);
pack();
setResizable(false);
setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
Object event = e.getSource();
if(event == tijiao)
{
String s1 = "";
int total = 0;
for(int i = 0;i < area.getText().length();i++)
{
if(area.getText().charAt(i)<'0'||area.getText().charAt(i)>'9')
s1 += area.getText().charAt(i);
else
total++;
}
if(s1.equals("") == false)
{
if(total < 11)
result.setText("该号码小于11位 包含非法字符串 "+s1);
if(total > 11)
result.setText("该号码大于11位 包含非法字符串 "+s1);
}
if(s1.equals(""))
{
if(total < 11)
result.setText("该号码小于11位");
if(total > 11)
result.setText("该号码大于11位 ");
}
if(total == 11 )
result.setText("该手机号码符合规则");
}
if(event == qingchu)
{
area.setText("");
result.setText("请输入手机号码");
}
if(event == tuichu)
System.exit(0);
}
public static void main(String[] args)
{
TestPhoneNumber test = new TestPhoneNumber();
test.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
bingoogol2
- 粉丝: 5
- 资源: 7
最新资源
- 水沸腾了加热过程中水的变化记录表.docx
- 小红书运营工作职责.docx
- 学生社会实践活动鉴定表.docx
- 学生职业行动能力实践调查表.docx
- 学校绩效考核及绩效工资分配方案.docx
- 学校教导处工作计划.docx
- 医学院试卷保密室管理规定、保密室值班制度、医学院试卷保密室监控管理制度.docx
- 医学院试卷保密室钥匙使用承诺书.docx
- 印刷画册常见尺寸表.docx
- 运动素养与身心健康测评标准表.docx
- 渔业资源增殖放流实施方案.docx
- 智力残疾评定标准一览表.docx
- 制定 护理标准 制度.docx
- 中心学校学生住宿服务事项及安全管理情况.docx
- 中心小学课题管理办法.docx
- 中心学校劳动教育开展情况.docx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
- 1
- 2
前往页