大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
提倡独立完成作业,培养独立思考能力。
创新互联公司专注于中大型企业的网站设计制作、成都网站制作和网站改版、网站营销服务,追求商业策划与数据分析、创意艺术与技术开发的融合,累计客户近千家,服务满意度达97%。帮助广大客户顺利对接上互联网浪潮,准确优选出符合自己需要的互联网运用,我们将一直专注品牌网站建设和互联网程序开发,在前进的路上,与客户一起成长!
思路:可以新建一个银行卡类BankCard,内部属性包含一个私有的不可变常量卡号cardNo,私有的可变量密码password,私有的可变量余额cardBalance。
参考代码如下:(仅供参考)
代码与你的电脑系统不兼容。
建议你用PHP的来做。
win7 64位。
import javax.swing.JOptionPane;
/**
*
* @author __USER__
*/
public class test extends javax.swing.JFrame {
/** Creates new form test */
public test() {
initComponents();
}
//GEN-BEGIN:initComponents
// editor-fold defaultstate="collapsed" desc="Generated Code"
private void initComponents() {
jButton1 = new javax.swing.JButton();
jLabel1 = new javax.swing.JLabel();
jTextField1 = new javax.swing.JTextField();
jTextField2 = new javax.swing.JTextField();
jLabel2 = new javax.swing.JLabel();
jTextField3 = new javax.swing.JTextField();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
jTextField4 = new javax.swing.JTextField();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jButton1.setText("\u5f00\u59cb\u6d4b\u8bd5");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jLabel1.setText("\u8bf7\u8f93\u5165\u6d4b\u8bd5\u6b21\u6570\uff1a");
jTextField2.setEditable(false);
jLabel2.setText("\u6362\u5361\u80dc\u5229\u6b21\u6570\uff1a");
jTextField3.setEditable(false);
jLabel3.setText("\u4e0d\u6362\u80dc\u5229\u6b21\u6570\uff1a");
jLabel4.setText("\u603b\u8017\u65f6\uff08\u79d2\uff09\uff1a");
jTextField4.setEditable(false);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(
getContentPane());
getContentPane().setLayout(layout);
layout
.setHorizontalGroup(layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
layout
.createSequentialGroup()
.addGap(84, 84, 84)
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
layout
.createSequentialGroup()
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
layout
.createSequentialGroup()
.addComponent(
jLabel3)
.addGap(
26,
26,
26)
.addComponent(
jTextField3,
javax.swing.GroupLayout.DEFAULT_SIZE,
153,
Short.MAX_VALUE))
.addGroup(
layout
.createSequentialGroup()
.addComponent(
jLabel2)
.addGap(
26,
26,
26)
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(
jTextField4,
javax.swing.GroupLayout.PREFERRED_SIZE,
97,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(
jTextField2,
javax.swing.GroupLayout.DEFAULT_SIZE,
153,
Short.MAX_VALUE))))
.addGap(
119,
119,
119))
.addGroup(
layout
.createSequentialGroup()
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(
jLabel4)
.addComponent(
jLabel1))
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(
jTextField1,
javax.swing.GroupLayout.PREFERRED_SIZE,
117,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(
18,
18,
18)
.addComponent(
jButton1)
.addContainerGap()))));
layout
.setVerticalGroup(layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
javax.swing.GroupLayout.Alignment.TRAILING,
layout
.createSequentialGroup()
.addGap(52, 52, 52)
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel4)
.addComponent(
jTextField4,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(28, 28, 28)
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(
jLabel2,
javax.swing.GroupLayout.PREFERRED_SIZE,
20,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(
jTextField2,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(32, 32, 32)
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(
jLabel3,
javax.swing.GroupLayout.PREFERRED_SIZE,
20,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(
jTextField3,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED,
67, Short.MAX_VALUE)
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(
jLabel1,
javax.swing.GroupLayout.PREFERRED_SIZE,
20,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(
jTextField1,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton1))
.addGap(76, 76, 76)));
pack();
}// /editor-fold
//GEN-END:initComponents
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
long time = System.currentTimeMillis();
String number = jTextField1.getText();
if (number.matches("^[1-9]{1}\\d*$")) {
long count1 = 0;
long count2 = 0;
int[] cards = { 0, 0, 1 };
long times = Long.parseLong(number);
for (long i = 0L; i times; i++) {
int random = (int) (Math.random() * 3);
//表示第一次抽取的牌
int card1 = cards[random];
count1 += card1;
//表示第二次如果换牌之后的牌
int card2 = Math.abs(card1 - 1);
count2 += card2;
}
time = System.currentTimeMillis() - time;
jTextField2.setText("" + count2);
jTextField3.setText("" + count1);
jTextField4.setText("" + time/1000.0);
} else {
JOptionPane.showMessageDialog(null, "输入有误!");
}
}
/**
* @param args
* the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new test().setVisible(true);
}
});
}
//GEN-BEGIN:variables
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JTextField jTextField1;
private javax.swing.JTextField jTextField2;
private javax.swing.JTextField jTextField3;
private javax.swing.JTextField jTextField4;
// End of variables declaration//GEN-END:variables
}