From de0accea7358d6497de530e401007b3497d7f19e Mon Sep 17 00:00:00 2001 From: fdai7460 Date: Wed, 1 Feb 2023 11:41:40 +0100 Subject: [PATCH] Difference --- src/main/java/src/TasksFrame.java | 46 +++++++++++++++++++++++++++ src/test/java/src/TasksFrameTest.java | 18 ++++++++++- 2 files changed, 63 insertions(+), 1 deletion(-) diff --git a/src/main/java/src/TasksFrame.java b/src/main/java/src/TasksFrame.java index b1b5809..0eb67ad 100644 --- a/src/main/java/src/TasksFrame.java +++ b/src/main/java/src/TasksFrame.java @@ -69,6 +69,10 @@ public class TasksFrame extends JFrame { setup5ModList(1, 20); setupLeibnizR(1000); + + setupDiff(); + + } @@ -129,6 +133,48 @@ public class TasksFrame extends JFrame { jPanel.add(jLabel); } + public void setupDiff(){ + JPanel jPanel = setupPanel("Difference"); + + JTextField x = new JTextField(); + x.setBounds(10,50,30,20); + x.setVisible(true); + + JTextField y = new JTextField(); + y.setBounds(50,50,30,20); + y.setVisible(true); + + JTextField result = new JTextField(); + result.setBounds(100,50,30,20); + result.setVisible(true); + + JButton difference = new JButton("Difference"); + difference.setBounds(10,90,100,30); + difference.setVisible(true); + + difference.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + String textx = x.getText(); + String texty = y.getText(); + Integer val_x = Integer.valueOf(textx); + Integer val_y = Integer.valueOf(texty); + Integer res = calcDiff(val_x, val_y); + result.setText(String.valueOf(res)); + } + }); + + jPanel.add(x); + jPanel.add(y); + jPanel.add(result); + jPanel.add(difference); + + } + + public int calcDiff(int a, int b) { + return a-b; + } + private void setupSum() { JPanel jPanel = setupPanel("Summe"); diff --git a/src/test/java/src/TasksFrameTest.java b/src/test/java/src/TasksFrameTest.java index feea7dd..6be620c 100644 --- a/src/test/java/src/TasksFrameTest.java +++ b/src/test/java/src/TasksFrameTest.java @@ -12,4 +12,20 @@ class TasksFrameTest { double x = tasksFrame.setupLeibnizR(100000); assertEquals(Math.PI/4, x, 0.00001, "Die Werte sind unterschiedlich. Soll: 0.785 Ist:" +x); } -} \ No newline at end of file + + @Test + void setupDiff(){ + TasksFrame frame = new TasksFrame(); + int diff = frame.calcDiff(6, 7); + assertEquals(-1, diff); + int diff2 = frame.calcDiff(0,0); + assertEquals(0,diff2); + int diff3 = frame.calcDiff(12, 8); + assertEquals(4, diff3); + } + + + } + + +