diff --git a/src/main/java/src/TasksFrame.java b/src/main/java/src/TasksFrame.java index 2fc7fb0..615f647 100644 --- a/src/main/java/src/TasksFrame.java +++ b/src/main/java/src/TasksFrame.java @@ -17,13 +17,13 @@ public class TasksFrame extends JFrame { super("Unsere kleinen Tasks"); setVisible(true); - setBounds(810,200, 300, 600); - setPreferredSize(new Dimension(300, 600)); + setBounds(810,200, 400, 600); + setPreferredSize(new Dimension(400, 600)); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setResizable(false); JPanel root = new JPanel(); - root.setBounds(0, 0, 300, 600); + root.setBounds(0, 0, 400, 600); root.setVisible(true); setContentPane(root); @@ -34,7 +34,7 @@ public class TasksFrame extends JFrame { container.setLayout(new BoxLayout(container, BoxLayout.Y_AXIS)); jScrollPane = new JScrollPane(container, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); - jScrollPane.setPreferredSize(new Dimension(300, 600)); + jScrollPane.setPreferredSize(new Dimension(400, 600)); root.add(jScrollPane); } @@ -51,7 +51,7 @@ public class TasksFrame extends JFrame { JLabel jLabel = new JLabel(header); jLabel.setVisible(true); - jLabel.setBounds(3, 3, 160, 20); + jLabel.setBounds(3, 3, 300, 20); panel.add(jLabel); @@ -66,6 +66,8 @@ public class TasksFrame extends JFrame { setupDiff(); + setupArea(); + setupSumFromTo(); setup5ModList(1, 20); @@ -207,6 +209,64 @@ public class TasksFrame extends JFrame { return a-b; } + public void setupArea() + { + JPanel jPanel = setupPanel("Area and perimeter of a Rectangle:"); + + JLabel jL1 = new JLabel(); + jL1.setText("Side a:"); + jL1.setVisible(true); + jL1.setBounds(0,20,50,30); + + JLabel jL2 = new JLabel(); + jL2.setText("Side b:"); + jL2.setVisible(true); + jL2.setBounds(0,40,50,30); + + JTextField a = new JTextField(); + a.setVisible(true); + a.setBounds(50,25,30,20); + + JTextField b = new JTextField(); + b.setVisible(true); + b.setBounds(50,45,30,20); + + JButton area = new JButton("Calculate area"); + area.setVisible(true); + area.setBounds(0, 80, 180,30); + + JTextField areaRes = new JTextField(); + areaRes.setBounds(200,80,30,20 ); + areaRes.setVisible(true); + + area.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + String texta = a.getText(); + String textb = b.getText(); + Integer val_a = Integer.valueOf(texta); + Integer val_b = Integer.valueOf(textb); + Integer res = calcArea(val_a, val_b); + areaRes.setText(String.valueOf(res)); + } + }); + + jPanel.add(jL1); + jPanel.add(jL2); + jPanel.add(a); + jPanel.add(b); + jPanel.add(area); + jPanel.add(areaRes); + + } + + public int calcArea(int a, int b) + { + int area = a * b; + return area; + } + + public void setupSumFromTo(){ @@ -294,4 +354,6 @@ public class TasksFrame extends JFrame { return sum; } + + } diff --git a/src/test/java/src/TasksFrameTest.java b/src/test/java/src/TasksFrameTest.java index ebe61ca..953a426 100644 --- a/src/test/java/src/TasksFrameTest.java +++ b/src/test/java/src/TasksFrameTest.java @@ -7,14 +7,16 @@ import static org.junit.jupiter.api.Assertions.*; class TasksFrameTest { @Test - void setupLeibnizR() { + void setupLeibnizR() + { TasksFrame tasksFrame = new TasksFrame(); double x = tasksFrame.setupLeibnizR(100000); assertEquals(Math.PI/4, x, 0.00001, "Die Werte sind unterschiedlich. Soll: 0.785 Ist:" +x); } @Test - void setupDiff(){ + void setupDiff() + { TasksFrame frame = new TasksFrame(); int diff = frame.calcDiff(6, 7); assertEquals(-1, diff); @@ -25,7 +27,8 @@ class TasksFrameTest { } @Test - void setupSumm(){ + void setupSumm() + { TasksFrame frame = new TasksFrame(); int sum1 = frame.calcSumm(23, 11); assertEquals(34, sum1); @@ -36,7 +39,8 @@ class TasksFrameTest { } @Test - void setupSumFromTo(){ + void setupSumFromTo() + { TasksFrame frame = new TasksFrame(); int p1= frame.sumCalc(1,5); assertEquals(15,p1); @@ -46,6 +50,17 @@ class TasksFrameTest { assertEquals(3,p3); } + @Test + void setupArea() + { + TasksFrame tasksFrame = new TasksFrame(); + int p1 = tasksFrame.calcArea(3,5); + assertEquals(15, p1); + int p2= tasksFrame.calcArea(0,7); + assertEquals(0,p2); + + } + }