在破公司上班的最后一天,老板让我给他开发一个拨号程序——初级版(Java实现)
一个有趣Java小案例,练练手,目前还是初级版本,还在升级当中哦…(附实现代码在下面)
老板,这是你要拨打的电话吗?


实现的代码在这(特别提醒:代码在浏览器看没问题,但是在CSDN里看格式可能会错)
import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Random;
import java.awt.event.ActionEvent;
import java.awt.FlowLayout;
import com.jgoodies.forms.layout.FormLayout;
import com.jgoodies.forms.layout.ColumnSpec;
import com.jgoodies.forms.layout.FormSpecs;
import com.jgoodies.forms.layout.RowSpec;
import javax.swing.JLabel;
import java.awt.GridLayout;
import java.awt.CardLayout;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JLayeredPane;
import javax.swing.JTextField;
import java.awt.Font;public class Dial extends JFrame {/*** Launch the application.*/public static void main(String[] args) {EventQueue.invokeLater(new Runnable() {public void run() {try {Dial frame = new Dial();frame.setVisible(true);} catch (Exception e) {e.printStackTrace();}}});}/*** Create the frame.*/public Dial() {setTitle("\u62E8\u53F7");setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);setBounds(100, 100, 496, 300);getContentPane().setLayout(null);JLayeredPane layeredPane = new JLayeredPane();layeredPane.setBounds(89, 117, 1, 1);getContentPane().add(layeredPane);JButton btnNewButton = new JButton("\u662F");btnNewButton.setBounds(22, 142, 83, 48);getContentPane().add(btnNewButton);JLabel lblNewLabel = new JLabel("\u8FD9\u662F\u4F60\u8981\u62E8\u6253\u7684\u7535\u8BDD\u5417\uFF1F");lblNewLabel.setFont(new Font("微软雅黑", Font.PLAIN, 20));lblNewLabel.setBounds(23, 69, 219, 63);getContentPane().add(lblNewLabel);JLabel lblNewLabel_1 = new JLabel(radomPhone());lblNewLabel_1.setFont(new Font("微软雅黑", Font.BOLD, 21));lblNewLabel_1.setBounds(252, 85, 199, 28);getContentPane().add(lblNewLabel_1);JButton btnNewButton_1 = new JButton("\u4E0D\u662F");btnNewButton_1.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {//将随机手机号码给标签lblNewLabel_1.setText(radomPhone());}});btnNewButton_1.setBounds(115, 142, 83, 48);getContentPane().add(btnNewButton_1);}//抽取11位随机数的手机号码public String radomPhone() {Random r = new Random();String text = "";for(int i = 0;i<11;i++) {//随机数位数由循环决定,而随机的数字大小由r.nextInt决定text += r.nextInt(10);}return text;}
}
我是一颗剽悍的种子(一颗偏爱前端的后端新司机)
最近打算做——“破公司上班的最后一天,老板让我给他开发一个拨号程序”这一个系列,想让学Java路上也能好玩和有趣!
老板,可不要忘了收藏、点赞和关注哟~
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
