在搶紅包時有判斷啊,如果10個中已搶5個,那么還剩5個,同理,已搶10個,那么就沒有了,再有人搶就提示紅包已搶完。貌似這個沒有任何特殊的技術難點吧。。。。。。
創(chuàng)新互聯(lián) - 成都服務器托管,四川服務器租用,成都服務器租用,四川網(wǎng)通托管,綿陽服務器托管,德陽服務器托管,遂寧服務器托管,綿陽服務器托管,四川云主機,成都云主機,西南云主機,成都服務器托管,西南服務器托管,四川/成都大帶寬,機柜大帶寬、租用·托管,四川老牌IDC服務商
微信可以設置自動收紅包轉賬方法如下: 1、打開你的微信,你就可以看朋友的頭像發(fā)來的轉賬消息,請你確認收錢。 2、點擊打開消息,可以看到轉賬金額,點擊進入確認收款。 3、若一天內未及時收款,就會退回給轉賬方。
public class Lucky {
public static void main(String[] args){
System.out.println("請輸入您的4位會員卡號:");
Scanner sc = new Scanner(System.in);
int number = sc.nextInt(); //接收用戶從控制臺輸入的會員卡號,并保存在會員卡號變量中
int a = number/1000; //千位
int b = number%1000/100; //百位
int c = number%100/10; //十位
int d = number%10; //個位
if((a+b+c+d)20){
System.out.println("恭喜中獎!您是幸運客戶");
}else{
System.out.println("謝謝參與!");
}
}
}
最基礎的 沒有異常判斷 無限循環(huán)輸入什么東西
很簡單的應用,為了節(jié)省字數(shù),代碼注釋我就不加了
首先是顯示層,LoinWindow:
import?java.awt.FlowLayout;
import?java.awt.GridBagConstraints;
import?java.awt.GridBagLayout;
import?java.awt.GridLayout;
import?java.awt.event.ActionEvent;
import?java.awt.event.ActionListener;
import?java.awt.event.FocusEvent;
import?java.awt.event.FocusListener;
import?javax.swing.JButton;
import?javax.swing.JFrame;
import?javax.swing.JLabel;
import?javax.swing.JOptionPane;
import?javax.swing.JPanel;
import?javax.swing.JTextField;
import?javax.swing.border.EmptyBorder;
public?class?LoinWindow?extends?JFrame?implements?ActionListener,?FocusListener?{
private?JPanel?mainPanel,?namePanel,?btnPanel;
private?JTextField?tfName,?tfPsd;
private?JButton?btnLogin,?btnCancel;
private?static?final?int?WIDTH?=?300;
private?static?final?int?HEIGHT?=?200;
private?LoginService?service?=?new?LoginService();
public?LoinWindow()?{
super("登錄窗體");
}
public?void?launch()?{
setSize(WIDTH,?HEIGHT);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
GridLayout?mainLayout?=?new?GridLayout(2,?1);
mainLayout.setVgap(10);
mainPanel?=?new?JPanel(mainLayout);
GridBagLayout?nameLayout?=?new?GridBagLayout();
namePanel?=?new?JPanel(nameLayout);
namePanel.setBorder(new?EmptyBorder(10,?10,?10,?10));
JLabel?nameLabel?=?new?JLabel("姓名:");
tfName?=?new?JTextField();
JLabel?psdLabel?=?new?JLabel("密碼:");
tfPsd?=?new?JTextField();
JLabel?blank?=?new?JLabel("?");
namePanel.add(nameLabel);
namePanel.add(tfName);
namePanel.add(blank);
namePanel.add(psdLabel);
namePanel.add(tfPsd);
GridBagConstraints?s?=?new?GridBagConstraints();
s.fill?=?GridBagConstraints.BOTH;
s.gridwidth?=?1;
s.weightx?=?0;
s.weighty?=?0;
nameLayout.setConstraints(nameLabel,?s);
s.gridwidth?=?0;
s.weightx?=?1;
s.weighty?=?0;
nameLayout.setConstraints(tfName,?s);
s.gridwidth?=?0;
s.weightx?=?4;
s.weighty?=?0;
nameLayout.setConstraints(blank,?s);
s.gridwidth?=?1;
s.weightx?=?0;
s.weighty?=?0;
nameLayout.setConstraints(psdLabel,?s);
s.gridwidth?=?3;
s.weightx?=?1;
s.weighty?=?0;
nameLayout.setConstraints(tfPsd,?s);
FlowLayout?btnLayout?=?new?FlowLayout();
btnLayout.setAlignment(FlowLayout.CENTER);
btnPanel?=?new?JPanel(btnLayout);
btnLogin?=?new?JButton("確定");
btnCancel?=?new?JButton("取消");
btnPanel.add(btnLogin);
btnPanel.add(btnCancel);
btnCancel.addActionListener(this);
btnLogin.addActionListener(this);
mainPanel.add(namePanel);
mainPanel.add(btnPanel);
setContentPane(mainPanel);
tfName.addFocusListener(this);
tfPsd.addFocusListener(this);
pack();
setSize(WIDTH,?HEIGHT);
setLocationRelativeTo(null);
}
@Override
public?void?actionPerformed(ActionEvent?e)?{
Object?source?=?e.getSource();
if(source?==?btnCancel)?{
System.exit(0);
}?else?if(source?==?btnLogin)?{
String?username?=?tfName.getText();
String?password?=?tfPsd.getText();
boolean?success?=?service.login(username,?password);
if(success)?{
warn("成功",?"登錄成功!");
}?else?{
warn("失敗",?"您輸入的用戶名或密碼錯誤?!");
}
}
}
@Override
public?void?focusGained(FocusEvent?arg0)?{
}
@Override
public?void?focusLost(FocusEvent?e)?{
Object?source?=?e.getSource();
if(source?==?tfName)?{
String?username?=?tfName.getText();
try?{
service.matchUsername(username);
}?catch?(LoginException?e1)?{
warn("驗證錯誤",?e1.getMessage());
}
}?else?if(source?==?tfPsd)?{
String?password?=?tfPsd.getText();
try?{
service.matchPassword(password);
}?catch?(LoginException?e1)?{
warn("驗證錯誤",?e1.getMessage());
}
}
}
private?void?warn(String?title,?String?msg)?{
JOptionPane.showMessageDialog(null,?msg,?title,?JOptionPane.INFORMATION_MESSAGE);
}
public?static?void?main(String[]?args)?{
new?LoinWindow().launch();
}
}
然后是模型層:LoginDao
public?class?LoginDao?{
public?boolean?login(String?username,?String?password)?{
if(username.equals("admin")??password.equals("12345"))?{
return?true;
}
return?false;
}
}
LoginService
import?java.util.regex.Pattern;
public?class?LoginService?{
private?static?final?Pattern?LOGIN_PATTERN?=?Pattern.compile("[a-zA-Z]+");
private?static?final?Pattern?PASSWORD_PATTERN?=?Pattern.compile("[1-9]+");
private?LoginDao?dao?=?new?LoginDao();
public?boolean?matchUsername(String?username)?throws?LoginException?{
if(null?==?username?||?username.isEmpty())?{
return?false;
}
if(!LOGIN_PATTERN.matcher(username).matches())?{
throw?new?LoginException("您輸入的用戶名不合法,請輸入英文!");
}
return?true;
}
public?boolean?matchPassword(String?password)?throws?LoginException?{
if(null?==?password?||?password.isEmpty())?{
return?false;
}
if(!PASSWORD_PATTERN.matcher(password).matches())?{
throw?new?LoginException("您輸入的密碼不合法,請輸入數(shù)字!");
}
return?true;
}
public?boolean?login(String?username,?String?password)?{
if(null?==?username?||?username.isEmpty())?{
return?false;
}
if(null?==?password?||?password.isEmpty())?{
return?false;
}
if(!dao.login(username,?password))?{
return?false;
}
return?true;
}
}
LoginException
public?class?LoginException?extends?Exception?{
public?LoginException(String?arg0)?{
super(arg0);
}
}
不知道分層設計思想是不是我想的這樣
實際測試了2種情況:1、建立1W個連接,并發(fā)循環(huán)寫入2、啟動1W個并發(fā),循環(huán)建立連接并寫入第2種情況運行10幾秒就會報錯,無法分配端口!
新的紅包接口開放是微信搖一搖周邊紅包組件接口,包括如下具體接口:申請條件及準備1、認證并且開通了微信支付的微信公眾號(服務號、企業(yè)號、部分媒體及政府機構的訂閱號);2、申請開通微信搖一窯周邊;3、購買ibeacon藍牙基站()微信官方推...
本文標題:搶紅包java代碼實現(xiàn),java自動搶紅包代碼
URL網(wǎng)址:http://jinyejixie.com/article12/hsipdc.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供App設計、外貿建站、品牌網(wǎng)站制作、Google、定制網(wǎng)站、網(wǎng)站收錄
聲明:本網(wǎng)站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經(jīng)允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)