日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > java >内容正文

java

java实现红包要多少钱_Java实现发红包模拟

發布時間:2025/3/13 java 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java实现红包要多少钱_Java实现发红包模拟 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

packagecom.cmk;import javax.swing.*;import java.awt.*;importjava.awt.event.KeyAdapter;importjava.awt.event.KeyEvent;importjava.awt.event.MouseAdapter;importjava.awt.event.MouseEvent;importjava.util.ArrayList;importjava.util.HashMap;/*** 紅包的框架 RedPacketFrame

*

* AWT / Swing / JavaFX

**/

public abstract class RedPacketFrame extendsJFrame {private static final long serialVersionUID = 1L;private static final String DIR = "E:\\mycode\\Hongbao\\pic";private ArrayList moneyList = null;private static int initMoney = 0;private static int totalMoney = 0; //單位為“分”

private static int count = 0;private static HashMap panelLable = new HashMap<>();//設置字體

private static Font fontYaHei = new Font("微軟雅黑", Font.BOLD, 20);private static Font msgFont = new Font("微軟雅黑", Font.BOLD, 20);private static Font totalShowFont = new Font("微軟雅黑", Font.BOLD, 40);private static Font nameFont = new Font("微軟雅黑", Font.BOLD, 40);private static Font showNameFont = new Font("微軟雅黑", Font.BOLD, 20);private static Font showMoneyFont = new Font("微軟雅黑", Font.BOLD, 50);private static Font showResultFont = new Font("微軟雅黑", Font.BOLD, 15);/*** 窗體大小 WIDTH:400 HEIGHT:600*/

private static final int FRAME_WIDTH = 416; //靜態全局窗口大小

private static final int FRAME_HEIGHT = 650;private static JLayeredPane layeredPane = null;/// private static JPanel contentPane = null;

/*** page1:輸入頁面 - InputPanel . 組件和初始化!*/

private static JPanel inputPanel = newJPanel();//private static JTextField input_total = new JTextField("200");//測試用//private static JTextField input_count = new JTextField("3");//測試用

private static JTextField input_total = newJTextField();private static JTextField input_count = newJTextField();private static JTextField input_people = new JTextField("30");private static JTextField input_msg = new JTextField("恭喜發財 , 大吉大利");private static JTextField input_total_show = new JTextField("$ " +input_total.getText().trim());private static JLabel input_inMoney = new JLabel(); //不可見

private static JLabel input_bg_label = new JLabel(new ImageIcon(DIR + "\\01_input.jpg"));static{//設置位置

input_total.setBounds(200, 90, 150, 50);

input_count.setBounds(200, 215, 150, 50);

input_people.setBounds(90, 275, 25, 30);

input_msg.setBounds(180, 340, 200, 50);

input_total_show.setBounds(130, 430, 200, 80);

input_inMoney.setBounds(10, 535, 380, 65);

input_bg_label.setBounds(0, 0, 400, 600); //背景//設置字體

input_total.setFont(fontYaHei);

input_count.setFont(fontYaHei);

input_people.setFont(fontYaHei);

input_msg.setFont(msgFont);

input_msg.setForeground(new Color(255, 233, 38)); //字體顏色 為金色

input_total_show.setFont(totalShowFont);

input_inMoney.setFont(fontYaHei);//透明

input_people.setOpaque(false);

input_total_show.setOpaque(false);//編 輯 -- 不可編輯

input_people.setEditable(false);

input_total_show.setEditable(false);//邊界 -- 無

input_total.setBorder(null);

input_count.setBorder(null);

input_people.setBorder(null);

input_msg.setBorder(null);

input_total_show.setBorder(null);

}/*** page2:打開頁面 - openPanel . 組件和初始化!*/

private static JPanel openPanel = newJPanel();private static JTextField open_ownerName = new JTextField("誰誰誰");private static JLabel open_label = new JLabel(new ImageIcon(DIR + "\\02_open_2.gif"));private static JLabel open_bg_label = new JLabel(new ImageIcon(DIR + "\\02_open_1.jpg"));static{//設置 位置.

open_ownerName.setBounds(0, 110, 400, 50);

open_bg_label.setBounds(0, 0, 400, 620);

open_label.setBounds(102, 280, 200, 200);

open_ownerName.setHorizontalAlignment(JTextField.CENTER);//設置字體

open_ownerName.setFont(nameFont);

open_ownerName.setForeground(new Color(255, 200, 163)); //字體顏色 為金色//背景色//open_name.setOpaque(false);

open_ownerName.setBackground(new Color(219, 90, 68));//不可編輯

open_ownerName.setEditable(false);//邊框

open_ownerName.setBorder(null);

}/*** page3:展示頁面 - showPanel . 組件和初始化!*/

private static JPanel showPanel = newJPanel();private static JPanel showPanel2 = newJPanel();private static JScrollPane show_jsp = newJScrollPane(showPanel2);private static JLabel show_bg_label = new JLabel(new ImageIcon(DIR + "\\03_money_1.jpg"));private static JTextField show_name = new JTextField("用戶名稱");private static JTextField show_msg = new JTextField("祝福信息");private static JTextField show_money = new JTextField("99.99");private static JTextField show_result = new JTextField(count + "個紅包共" + (totalMoney / 100.0) + "元,被搶光了");static{//分別設置水平和垂直滾動條自動出現//jsp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);//jsp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);

/** 兩部分 頁面 . 1.本人獲得的紅包-- showPanel 2.別人獲得的紅包-- show_jsp*/show_name.setBounds(125, 180, 100, 30);

show_name.setOpaque(false);

show_name.setBorder(null);

show_name.setFont(showNameFont);

show_msg.setBounds(0, 220, 400, 30);

show_msg.setOpaque(false);

show_msg.setBorder(null);

show_msg.setFont(msgFont);

show_msg.setHorizontalAlignment(JTextField.CENTER);

show_money.setBounds(0, 270, 250, 40);

show_money.setOpaque(false);

show_money.setBorder(null);

show_money.setFont(showMoneyFont);

show_money.setForeground(new Color(255, 233, 38)); //字體顏色 為金色

show_money.setHorizontalAlignment(SwingConstants.RIGHT);

show_result.setBounds(10, 460, 400, 20);

show_result.setOpaque(false);

show_result.setBorder(null);

show_result.setFont(showResultFont);

show_result.setForeground(new Color(170, 170, 170)); //字體顏色 為灰色//設置 圖片.

show_bg_label.setBounds(0, 0, 400, 500);

}static{//頁面和 背景的對應關系.

panelLable.put(inputPanel, input_bg_label);

panelLable.put(openPanel, open_bg_label);

panelLable.put(showPanel, show_bg_label);

}private voidinit() {//層次面板-- 用于設置背景

layeredPane = this.getLayeredPane();//System.out.println("層次面板||" + layeredPane);//System.out.println(layeredPane);//初始化框架 -- logo 和基本設置

initFrame();//初始化 三個頁面 -- 準備頁面

initPanel();//2.添加 頁面 --第一個頁面, 輸入 panel 設置到 頁面上.

setPanel(inputPanel);//3.添加 監聽

addListener();

}/*** 初始化框架 -- logo 和基本設置*/

private voidinitFrame() {//logo

this.setIconImage(Toolkit.getDefaultToolkit().getImage(DIR + "\\logo.gif"));//System.out.println("LOGO初始化...");//窗口設置

this.setSize(FRAME_WIDTH, FRAME_HEIGHT); //設置界面大小

this.setLocation(280, 30); //設置界面出現的位置

this.setDefaultCloseOperation(EXIT_ON_CLOSE);this.setLayout(null);//測試期 注釋 拖 拽 , 運行放開//this.setResizable(false);

this.setVisible(true);

}/*** 初始化頁面-- 準備三個頁面*/

private voidinitPanel() {//System.out.println("頁面初始化...");

initInputPanel();

initOpenPanel();

initShowPanel();

}private voidinitInputPanel() {

inputPanel.setLayout(null);

inputPanel.setBounds(0, -5, 400, 600);//this.add(bg_label);

inputPanel.add(input_total);

inputPanel.add(input_count);

inputPanel.add(input_people);

inputPanel.add(input_msg);

inputPanel.add(input_total_show);

inputPanel.add(input_inMoney);//System.out.println("輸入頁面||" + inputPanel);

}private voidinitOpenPanel() {

openPanel.setLayout(null);

openPanel.setBounds(0, 0, 400, 600);//this.add(bg_label);

openPanel.add(open_ownerName);

openPanel.add(open_label);//System.out.println("打開頁面||" + openPanel);

}private voidinitShowPanel() {

showPanel.setLayout(null);

showPanel.setBounds(10, 10, 300, 600);//==============

showPanel.add(show_name);

showPanel.add(show_msg);

showPanel.add(show_money);

showPanel.add(show_result);//System.out.println("展示頁面||" + showPanel);//====================================//showPanel2.setLayout(null);//showPanel2.setBounds(0, 500, 401, 300);

showPanel2.setPreferredSize(new Dimension(300, 1000));

showPanel2.setBackground(Color.white);

show_jsp.setBounds(0, 500, 400, 110);

}/*** 每次打開頁面, 設置 panel的方法*/

private voidsetPanel(JPanel panel) {//移除當前頁面

layeredPane.removeAll();//System.out.println("重新設置:新頁面");//背景lable添加到layeredPane的默認層

layeredPane.add(panelLable.get(panel), JLayeredPane.DEFAULT_LAYER);//面板panel設置為透明

panel.setOpaque(false);//面板panel 添加到 layeredPane的modal層

layeredPane.add(panel, JLayeredPane.MODAL_LAYER);

}//private void setShowPanel(JPanel show) {//setPanel(show);//layeredPane.add(show_jsp, JLayeredPane.MODAL_LAYER);//

//}

/*** 設置組件的監聽器*/

private voidaddListener() {

input_total.addKeyListener(newKeyAdapter() {

@Overridepublic voidkeyReleased(KeyEvent e) {//System.out.println(e);

String input_total_money =input_total.getText();

input_total_show.setText("$ " +input_total_money);

}

});

input_count.addKeyListener(newKeyAdapter() {

@Overridepublic voidkeyReleased(KeyEvent e) {//System.out.println(e);//System.out.println("個數:" + input_count.getText());

}

});

input_msg.addKeyListener(newKeyAdapter() {

@Overridepublic voidkeyReleased(KeyEvent e) {//System.out.println(e);//System.out.println("留言:" + input_msg.getText());

}

});

input_inMoney.addMouseListener(newMouseAdapter() {

@Overridepublic voidmouseClicked(MouseEvent e) {try{//獲取頁面的值.

totalMoney = (int) (Double.parseDouble(input_total.getText()) * 100); //轉換成"分"

count =Integer.parseInt(input_count.getText());if (count > 30) {

JOptionPane.showMessageDialog(null, "紅包個數不得超過30個", "紅包個數有誤", JOptionPane.INFORMATION_MESSAGE);return;

}

initMoney=totalMoney;

System.out.println("總金額:[" + totalMoney + "]分");

System.out.println("紅包個數:[" + count + "]個");

input_inMoney.removeMouseListener(this);//System.out.println("跳轉-->打開新頁面");//設置群主名稱

open_ownerName.setText(ownerName);//設置打開頁面

setPanel(openPanel);

}catch(Exception e2) {

JOptionPane.showMessageDialog(null, "請輸入正確【總金額】或【紅包個數】", "輸入信息有誤", JOptionPane.ERROR_MESSAGE);

}

}

});//open_ownerName ,點擊 [名稱],觸發的方法 , 提示如何設置群主名稱.

open_ownerName.addMouseListener(newMouseAdapter() {

@Overridepublic voidmouseClicked(MouseEvent arg0) {

JOptionPane.showMessageDialog(null, "請通過【setOwnerName】方法設置群主名稱", "群主名稱未設置",

JOptionPane.QUESTION_MESSAGE);

}

});//open label , 點擊 [開],觸發的方法,提示如何設置打開方式.

open_label.addMouseListener(newMouseAdapter() {

@Overridepublic voidmouseClicked(MouseEvent e) {if (openWay == null) {

JOptionPane.showMessageDialog(null, "請通過【setOpenWay】方法設置打開方式", "打開方式未設置",

JOptionPane.QUESTION_MESSAGE);return;

}//System.out.println("跳轉-->展示頁面");

moneyList=openWay.divide(totalMoney, count);//System.out.println(moneyList);

/** showPanel 添加數據

**/show_name.setText(ownerName);

show_msg.setText(input_msg.getText());if (moneyList.size() > 0) {

show_money.setText(moneyList.get(moneyList.size()- 1) / 100.0 + "");

}

show_result.setText(count+ "個紅包共" + (initMoney / 100.0) + "元,被搶光了");

open_label.removeMouseListener(this);

setPanel(showPanel);//添加數據

for (int i = 0; i < moneyList.size(); i++) {

JTextField tf= newJTextField();

tf.setBorder(null);

tf.setFont(showNameFont);

tf.setHorizontalAlignment(JTextField.LEFT);if (i == moneyList.size() - 1) {

tf.setText(ownerName+ ":\t" + moneyList.get(i) / 100.0 + "元");

}else{

tf.setText("群成員-" + i + ":\t" + moneyList.get(i) / 100.0 + "元");

}

showPanel2.add(tf);

}

layeredPane.add(show_jsp, JLayeredPane.MODAL_LAYER);

}

});

}/*======================================================================

* **********************************************************************

* * 以上代碼均為頁面部分處理,包括布局/互動/跳轉/顯示等,大家 *

* * *

* * *

* **********************************************************************

* ======================================================================*/

/*** ownerName : 群主名稱*/

private String ownerName = "誰誰誰"; //群主名稱

/*** openWay : 紅包的類型 [普通紅包/手氣紅包]*/

private OpenMode openWay = null;/*** 構造方法:生成紅包界面。

*

*@paramtitle 界面的標題*/

publicRedPacketFrame(String title) {super(title);//頁面相關的初始化

init();

}public voidsetOwnerName(String ownerName) {this.ownerName =ownerName;

}public voidsetOpenWay(OpenMode openWay) {this.openWay =openWay;

}

}

總結

以上是生活随笔為你收集整理的java实现红包要多少钱_Java实现发红包模拟的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 亚洲一区二区三区不卡视频 | 久久精品五月天 | 粉嫩av一区二区三区 | 欧洲精品久久久久毛片完整版 | 亚洲国产高清国产精品 | 72种无遮挡啪啪的姿势 | 日本免费一区视频 | 国产在线视频卡一卡二 | 亚洲v国产 | bt天堂新版中文在线地址 | 一区二区影视 | 美女尿尿网站 | 一级毛片黄片 | 99久久久国产精品无码网爆 | 亚洲卡一| 男女激情四射网站 | 欧美激情偷拍 | 欧美性生活一区 | 美女被男人插 | 非洲黑寡妇性猛交视频 | 麻豆视频网| 草色网| 爆乳2把你榨干哦ova在线观看 | 国产精品porn| 激情丁香网| 日本美女一级视频 | 日日干天天干 | www.国产区 | 成人动漫一区二区三区 | 亚州av网 | 夜夜骑天天操 | 成人欧美一区二区三区在线播放 | 精品久久一区 | 精品国产乱子伦 | 美女少妇av | 四虎黄色片 | 国产九一精品 | 青青草一区 | 在线观看福利视频 | 色网站在线| 欧美精品video | 国产原创麻豆 | 欧美久久久久久久久久久久 | 国产在线美女 | 台湾150部性三级 | 国产经典一区二区 | 解开人妻的裙子猛烈进入 | 少妇人妻一区二区三区 | 熊出没之冬日乐翻天免费高清观看 | 欧美日韩国产综合网 | 欧美精品动漫 | 丁香婷婷久久久综合精品国产 | 国产欧美一区二区三区鸳鸯浴 | 日本不卡视频一区二区三区 | 国产精品伦一区 | 亚洲一区二区三区三州 | 国产毛片毛片毛片毛片毛片毛片 | 欧美日韩免费高清一区色橹橹 | 99国产成人精品 | 美女被娇喘流出白 | 日韩精品成人免费观看视频 | 性欧美丰满熟妇xxxx性久久久 | 熟女丝袜一区 | 日韩 国产 | 国产伦精品一区二区三区视频网站 | 东京热无码av一区二区 | 亚洲精品一区二区三区新线路 | 一区二区视频免费在线观看 | 美女黄污网站 | 538精品在线视频 | 香蕉色视频 | 国产色综合网 | 亚洲图片视频小说 | 国产九色sp调教91 | aa在线视频 | 中国一级黄色 | 全部免费毛片在线播放 | 日韩一区二区三区四区五区六区 | 国产香蕉一区 | 日韩精品极品视频在线观看免费 | 国产小精品| 国产精品天干天干 | 凸凹人妻人人澡人人添 | 日本一级淫片1000部 | 精品久久二区 | 久久久一| 国产精品亚洲二区在线观看 | 亚洲区自拍 | 51久久久 | 国产精品野外户外 | 国产精品露脸视频 | 免费观看成人毛片 | 96精品视频在线观看 | 超碰中文字幕在线 | 女女同性高清片免费看 | 99国产精品99久久久久久粉嫩 | 毛片国产 | 中文字幕日韩欧美一区二区 | 理论片中文 |