From ea085e0631d73cb99ad9918021578bff8b0285f0 Mon Sep 17 00:00:00 2001 From: fdai6040 Date: Thu, 2 Feb 2023 12:39:26 +0100 Subject: [PATCH] kgV Function added --- src/main/java/src/TasksFrame.java | 46 +++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/src/main/java/src/TasksFrame.java b/src/main/java/src/TasksFrame.java index ed4f91f..f01a0b0 100644 --- a/src/main/java/src/TasksFrame.java +++ b/src/main/java/src/TasksFrame.java @@ -79,6 +79,52 @@ public class TasksFrame extends JFrame { setupQuersumme(); + setupKgV(); + + } + + private void setupKgV() { + JPanel jPanel = setupPanel("kgV"); + + JButton button = new JButton("kgV"); + button.setVisible(true); + button.setBounds(10, 65, 100, 30); + + JTextField a = new JTextField(); + a.setBounds(10, 40, 30, 20); + a.setVisible(true); + + JTextField b = new JTextField(); + b.setBounds(50, 40, 30, 20); + b.setVisible(true); + + JLabel jLabel = new JLabel(); + jLabel.setVisible(true); + jLabel.setBounds(10,90,60,30); + + jPanel.add(button); + jPanel.add(a); + jPanel.add(b); + jPanel.add(jLabel); + + button.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); + int res = kgV(val_a, val_b); + jLabel.setText(String.valueOf(res)); + } + }); + + + } + + public int kgV(int a, int b) { + int kgV= (a*b)/ggt(a,b); + return kgV; } private void setupQuersumme() {