在破公司上班的最後一天,老闆讓我給他開發一個撥號程序——升級版(Java實現)

一個有趣Java小案例,練練手,初級版本鏈接放下面,目前已經是升級版本,還有終極版本哦…所以要點贊和關注喲(附實現代碼在下面)

在破公司上班的最後一天,老闆讓我給他開發一個撥號程序——初級版(Java實現)

哈哈哈…,上一章初級版本的評論
在這裏插入圖片描述

老闆,你點破了十六個鼠標了,換這個撥號吧!!!

在這裏插入圖片描述
完整代碼在這

import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLayeredPane;
import javax.swing.JTextField;
import javax.swing.JLabel;
import java.awt.Color;
import javax.swing.JButton;
import java.awt.Font;
import java.awt.event.ActionListener;
import java.util.Random;
import java.util.Timer;
import java.util.TimerTask;
import java.awt.event.ActionEvent;
public class Dial_Upgrade extends JFrame {
	private JPanel contentPane;
	private JTextField textField;
	private JTextField textField_1;
	private JTextField textField_2;
	private JTextField textField_3;
	private JTextField textField_4;
	private JTextField textField_5;
	private JLabel lblNewLabel_2;
	private JTextField textField_6;
	private JTextField textField_7;
	private JTextField textField_8;
	private JTextField textField_9;
	private JTextField textField_10;
	private static int i = 0;
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Dial_Upgrade frame = new Dial_Upgrade();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public Dial_Upgrade() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 580, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane.setLayout(new BorderLayout(0, 0));
		setContentPane(contentPane);
		
		JLayeredPane layeredPane = new JLayeredPane();
		contentPane.add(layeredPane, BorderLayout.CENTER);
		
		textField = new JTextField();
		textField.setFont(new Font("微軟雅黑", Font.BOLD, 20));
		textField.setBounds(25, 94, 42, 54);
		layeredPane.add(textField);
		textField.setColumns(10);
		
		JButton btnNewButton = new JButton("\u91CD\u65B0\u542F\u52A8");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				textField.setText("");
				textField_1.setText("");
				textField_2.setText("");
				textField_3.setText("");
				textField_4.setText("");
				textField_5.setText("");
				textField_6.setText("");
				textField_7.setText("");
				textField_8.setText("");
				textField_9.setText("");
				textField_10.setText("");
				i=0;
			}
		});
		btnNewButton.setBounds(25, 183, 165, 35);
		layeredPane.add(btnNewButton);
		
		JLabel lblNewLabel = new JLabel("\u8BF7\u8F93\u5165\u4F60\u7684\u624B\u673A\u53F7\u7801\uFF1A");
		lblNewLabel.setFont(new Font("微軟雅黑", Font.BOLD, 20));
		lblNewLabel.setBounds(25, 35, 225, 35);
		layeredPane.add(lblNewLabel);
		
		JButton btnNewButton_1 = new JButton("\u62E8\u53F7");
		btnNewButton_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				i++;
				Timer timer = new Timer();
				timer.schedule(new Dial_Number(),100);
				
			
			}
		});
		btnNewButton_1.setBounds(208, 183, 165, 35);
		layeredPane.add(btnNewButton_1);
		
		textField_1 = new JTextField();
		textField_1.setFont(new Font("微軟雅黑", Font.BOLD, 20));
		textField_1.setColumns(10);
		textField_1.setBounds(71, 94, 42, 54);
		layeredPane.add(textField_1);
		
		textField_2 = new JTextField();
		textField_2.setFont(new Font("微軟雅黑", Font.BOLD, 20));
		textField_2.setColumns(10);
		textField_2.setBounds(117, 94, 42, 54);
		layeredPane.add(textField_2);
		
		textField_3 = new JTextField();
		textField_3.setFont(new Font("微軟雅黑", Font.BOLD, 20));
		textField_3.setColumns(10);
		textField_3.setBounds(164, 94, 42, 54);
		layeredPane.add(textField_3);
		
		textField_4 = new JTextField();
		textField_4.setFont(new Font("微軟雅黑", Font.BOLD, 20));
		textField_4.setColumns(10);
		textField_4.setBounds(210, 94, 42, 54);
		layeredPane.add(textField_4);
		
		textField_5 = new JTextField();
		textField_5.setFont(new Font("微軟雅黑", Font.BOLD, 20));
		textField_5.setColumns(10);
		textField_5.setBounds(256, 94, 42, 54);
		layeredPane.add(textField_5);
		
		JLabel lblNewLabel_1 = new JLabel("-");
		lblNewLabel_1.setFont(new Font("微軟雅黑", Font.BOLD, 14));
		lblNewLabel_1.setBounds(157, 112, 18, 16);
		layeredPane.add(lblNewLabel_1);
		
		lblNewLabel_2 = new JLabel("-");
		lblNewLabel_2.setFont(new Font("微軟雅黑", Font.BOLD, 14));
		lblNewLabel_2.setBounds(299, 112, 18, 16);
		layeredPane.add(lblNewLabel_2);
		
		textField_6 = new JTextField();
		textField_6.setFont(new Font("微軟雅黑", Font.BOLD, 20));
		textField_6.setColumns(10);
		textField_6.setBounds(306, 94, 42, 54);
		layeredPane.add(textField_6);
		
		textField_7 = new JTextField();
		textField_7.setFont(new Font("微軟雅黑", Font.BOLD, 20));
		textField_7.setColumns(10);
		textField_7.setBounds(352, 94, 42, 54);
		layeredPane.add(textField_7);
		
		textField_8 = new JTextField();
		textField_8.setFont(new Font("微軟雅黑", Font.BOLD, 20));
		textField_8.setColumns(10);
		textField_8.setBounds(398, 94, 42, 54);
		layeredPane.add(textField_8);
		
		textField_9 = new JTextField();
		textField_9.setFont(new Font("微軟雅黑", Font.BOLD, 20));
		textField_9.setColumns(10);
		textField_9.setBounds(443, 94, 42, 54);
		layeredPane.add(textField_9);
		
		textField_10 = new JTextField();
		textField_10.setFont(new Font("微軟雅黑", Font.BOLD, 20));
		textField_10.setColumns(10);
		textField_10.setBounds(489, 94, 42, 54);
		layeredPane.add(textField_10);
	}
	
	public class Dial_Number extends TimerTask{
		Random r = new Random();
		String text = "";
		@Override
		public void run() {
		
		if(i == 1) {
			while(2>i) {
				text = "  " + r.nextInt(10);
				textField.setText(text);
			}
		}
		if(i == 2) {
			while(3>i) {
				text = "  " + r.nextInt(10);
				textField_1.setText(text);
			}
		}
		if(i == 3) {
			while(4>i) {
				text = "  " + r.nextInt(10);
				textField_2.setText(text);
			}
		}
		if(i == 4) {
			while(5>i) {
				text = "  " + r.nextInt(10);
				textField_3.setText(text);
			}
		}
		if(i == 5) {
			while(6>i) {
				text = "  " + r.nextInt(10);
				textField_4.setText(text);
			}
		}
		if(i == 6) {
			while(7>i) {
				text = "  " + r.nextInt(10);
				textField_5.setText(text);
			}
		}
		if(i == 7) {
			while(8>i) {
				text = "  " + r.nextInt(10);
				textField_6.setText(text);
			}
		}
		if(i == 8) {
			while(9>i) {
				text = "  " + r.nextInt(10);
				textField_7.setText(text);
			}
		}
		if(i == 9) {
			while(10>i) {
				text = "  " + r.nextInt(10);
				textField_8.setText(text);
			}
		}
		if(i == 10) {
			while(11>i) {
				text = "  " + r.nextInt(10);
				textField_9.setText(text);
			}
		}
		if(i == 11) {
			while(12>i) {
				text = "  " + r.nextInt(10);
				textField_10.setText(text);
				}
			}
		}
	}
}

我是一顆剽悍的種子(一顆偏愛前端的後端新司機)
最近打算做——“破公司上班的最後一天,老闆讓我給他開發一個撥號程序”這一個系列,已經從初級版本到現在的升級版,還有一個終極版本,嘻嘻,想讓學Java路上也能好玩和有趣!

老闆,可不要忘了收藏、點贊和關注喲~

還有想說的嗎?有的話也讓你上終極版呀

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章