作業部屋の使い方を試しています。
(empty log message)
| @@ -50,8 +50,18 @@ | ||
| 50 | 50 | jLabel3.setText("Result"); |
| 51 | 51 | |
| 52 | 52 | jButton1.setText("Clear"); |
| 53 | + jButton1.addActionListener(new java.awt.event.ActionListener() { | |
| 54 | + public void actionPerformed(java.awt.event.ActionEvent evt) { | |
| 55 | + jButton1ActionPerformed(evt); | |
| 56 | + } | |
| 57 | + }); | |
| 53 | 58 | |
| 54 | 59 | jButton2.setText("Add"); |
| 60 | + jButton2.addActionListener(new java.awt.event.ActionListener() { | |
| 61 | + public void actionPerformed(java.awt.event.ActionEvent evt) { | |
| 62 | + jButton2ActionPerformed(evt); | |
| 63 | + } | |
| 64 | + }); | |
| 55 | 65 | |
| 56 | 66 | javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); |
| 57 | 67 | jPanel1.setLayout(jPanel1Layout); |
| @@ -102,6 +112,11 @@ | ||
| 102 | 112 | ); |
| 103 | 113 | |
| 104 | 114 | jButton3.setText("Exit"); |
| 115 | + jButton3.addActionListener(new java.awt.event.ActionListener() { | |
| 116 | + public void actionPerformed(java.awt.event.ActionEvent evt) { | |
| 117 | + jButton3ActionPerformed(evt); | |
| 118 | + } | |
| 119 | + }); | |
| 105 | 120 | |
| 106 | 121 | javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); |
| 107 | 122 | getContentPane().setLayout(layout); |
| @@ -122,6 +137,30 @@ | ||
| 122 | 137 | pack(); |
| 123 | 138 | }// </editor-fold>//GEN-END:initComponents |
| 124 | 139 | |
| 140 | + private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed | |
| 141 | + System.exit(0); | |
| 142 | + }//GEN-LAST:event_jButton3ActionPerformed | |
| 143 | + | |
| 144 | + private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed | |
| 145 | + jTextField1.setText(""); | |
| 146 | + jTextField2.setText(""); | |
| 147 | + jTextField3.setText(""); | |
| 148 | + }//GEN-LAST:event_jButton1ActionPerformed | |
| 149 | + | |
| 150 | + private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed | |
| 151 | + // First we define float variables. | |
| 152 | + float num1, num2, result; | |
| 153 | + // We have to parse the text to a type float. | |
| 154 | + num1 = Float.parseFloat(jTextField1.getText()); | |
| 155 | + num2 = Float.parseFloat(jTextField2.getText()); | |
| 156 | + // Now we can perform the addition. | |
| 157 | + result = num1+num2; | |
| 158 | + // We will now pass the value of result to jTextField3. | |
| 159 | + // At the same time, we are going to | |
| 160 | + // change the value of result from a float to a string. | |
| 161 | + jTextField3.setText(String.valueOf(result)); | |
| 162 | + }//GEN-LAST:event_jButton2ActionPerformed | |
| 163 | + | |
| 125 | 164 | /** |
| 126 | 165 | * @param args the command line arguments |
| 127 | 166 | */ |