扫二维码与项目经理沟通
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流
在抢红包时有判断啊,如果10个中已抢5个,那么还剩5个,同理,已抢10个,那么就没有了,再有人抢就提示红包已抢完。貌似这个没有任何特殊的技术难点吧。。。。。。
创新互联 - 成都服务器托管,四川服务器租用,成都服务器租用,四川网通托管,绵阳服务器托管,德阳服务器托管,遂宁服务器托管,绵阳服务器托管,四川云主机,成都云主机,西南云主机,成都服务器托管,西南服务器托管,四川/成都大带宽,机柜大带宽、租用·托管,四川老牌IDC服务商
微信可以设置自动收红包转账方法如下: 1、打开你的微信,你就可以看朋友的头像发来的转账消息,请你确认收钱。 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("谢谢参与!");
}
}
}
最基础的 没有异常判断 无限循环输入什么东西
很简单的应用,为了节省字数,代码注释我就不加了
首先是显示层,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("您输入的密码不合法,请输入数字!");
}
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个连接,并发循环写入2、启动1W个并发,循环建立连接并写入第2种情况运行10几秒就会报错,无法分配端口!
新的红包接口开放是微信摇一摇周边红包组件接口,包括如下具体接口:申请条件及准备1、认证并且开通了微信支付的微信公众号(服务号、企业号、部分媒体及政府机构的订阅号);2、申请开通微信摇一窑周边;3、购买ibeacon蓝牙基站()微信官方推...
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流