Commit f928dec0 by Patryk Czarnik

kalkualtor - wiele działań

parent d852f3a8
......@@ -57,7 +57,7 @@
<Component id="jButton1" pref="72" max="32767" attributes="0"/>
<Component id="jTextField3" max="32767" attributes="0"/>
</Group>
<EmptySpace max="32767" attributes="0"/>
<EmptySpace pref="14" max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
......@@ -107,6 +107,9 @@
</Property>
<Property name="text" type="java.lang.String" value="Oblicz"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jButton1ActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JTextField" name="jTextField3">
<Properties>
......
......@@ -43,6 +43,11 @@ public class OknoKalkulatora extends javax.swing.JFrame {
jButton1.setFont(new java.awt.Font("Arial", 0, 32)); // NOI18N
jButton1.setText("Oblicz");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jTextField3.setFont(new java.awt.Font("Arial", 0, 32)); // NOI18N
jTextField3.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
......@@ -78,7 +83,7 @@ public class OknoKalkulatora extends javax.swing.JFrame {
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, 72, Short.MAX_VALUE)
.addComponent(jTextField3))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addContainerGap(14, Short.MAX_VALUE))
);
pack();
......@@ -88,6 +93,22 @@ public class OknoKalkulatora extends javax.swing.JFrame {
// TODO add your handling code here:
}//GEN-LAST:event_jComboBox1ActionPerformed
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
long liczba1 = Long.parseLong(jTextField1.getText());
long liczba2 = Long.parseLong(jTextField2.getText());
String operacja = (String)jComboBox1.getSelectedItem();
// String operacja = jComboBox1.getItemAt(jComboBox1.getSelectedIndex());
long wynik = switch(operacja) {
case "+" -> liczba1 + liczba2;
case "-" -> liczba1 - liczba2;
case "*" -> liczba1 * liczba2;
case "/" -> liczba1 / liczba2;
default -> 0;
};
jTextField3.setText(String.valueOf(wynik));
}//GEN-LAST:event_jButton1ActionPerformed
/**
* @param args the command line arguments
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment