);
jButton1.setText(\
jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } });
jButton2.setText(\
jButton2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton2ActionPerformed(evt); } });
jButton3.setText(\
jButton3.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton3ActionPerformed(evt); } });
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup() .addContainerGap() .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(jPanel1Layout.createSequentialGroup() .addGap(50, 50, 50)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(jPanel1Layout.createSequentialGroup() .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
16
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(52, 52, 52)
.addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 318, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(0, 66, Short.MAX_VALUE))) .addContainerGap()) );
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addGap(26, 26, 26)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton1) .addComponent(jButton2) .addComponent(jButton3))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGap(7, 7, 7)) );
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) );
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
17
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) );
pack();
}// /**数据的输入:
* 程序开始时,程序初始化文本框的内容为“0”,点击数字按钮,
* if语句判断,若文本框数据非0,则当下按的数字键对应的数字,作为字符串接入之前数据尾部,
* else,文本框显示当下按的数字键所对应的数字。 */
private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here:
if(flag == false&&!jTextField1.getText().equals(\ jTextField1.setText(jTextField1.getText()+\ else
jTextField1.setText(\ flag = false;
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here:
//if语句判定当前字符串是否为空,若不为空,则将字符串长度减1之后,再赋值给原字符串;否则,将0复制给原字符串。 String s = jTextField1.getText(); if(!s.equals(\
s = s.substring(0,s.length()-1); if(s.equals(\ s = \
jTextField1.setText(s);
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: //复位操作
jTextField1.setText(\ d1 = 0; d2 = 0; op = \ flag = false;
}
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
18
// TODO add your handling code here: //清零操作
jTextField1.setText(\
}
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here:
if(flag == false&&!jTextField1.getText().equals(\ jTextField1.setText(jTextField1.getText()+\ else
jTextField1.setText(\ flag = false;
}
private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here:
if(flag == false&&!jTextField1.getText().equals(\ jTextField1.setText(jTextField1.getText()+\ else
jTextField1.setText(\ flag = false;
}
private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here:
if(flag == false&&!jTextField1.getText().equals(\ jTextField1.setText(jTextField1.getText()+\ else
jTextField1.setText(\ flag = false;
}
private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here:
if(flag == false&&!jTextField1.getText().equals(\ jTextField1.setText(jTextField1.getText()+\ else
jTextField1.setText(\ flag = false;
}
private void jButton9ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here:
if(flag == false&&!jTextField1.getText().equals(\
19
jTextField1.setText(jTextField1.getText()+\ else
jTextField1.setText(\ flag = false;
}
private void jButton10ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here:
if(flag == false&&!jTextField1.getText().equals(\ jTextField1.setText(jTextField1.getText()+\ else
jTextField1.setText(\ flag = false;
}
private void jButton11ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here:
if(flag == false&&!jTextField1.getText().equals(\ jTextField1.setText(jTextField1.getText()+\ else
jTextField1.setText(\ flag = false;
}
private void jButton12ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here:
if(flag == false&&!jTextField1.getText().equals(\ jTextField1.setText(jTextField1.getText()+\ else
jTextField1.setText(\ flag = false;
}
private void jButton13ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here:
if(flag == false&&!jTextField1.getText().equals(\ jTextField1.setText(jTextField1.getText()+\ else
jTextField1.setText(\ flag = false;
}
private void jButton15ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here:
20