From 7bddcb73882f937bd05e58fa5acd7e166310e696 Mon Sep 17 00:00:00 2001 From: fdai6040 Date: Tue, 7 Feb 2023 12:52:20 +0100 Subject: [PATCH] new Task "Kreisumfang" to unsere kleine Tasks Frame added --- src/main/java/src/TasksFrame.java | 47 +++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/src/main/java/src/TasksFrame.java b/src/main/java/src/TasksFrame.java index b8d47bb..d9a315d 100644 --- a/src/main/java/src/TasksFrame.java +++ b/src/main/java/src/TasksFrame.java @@ -98,6 +98,8 @@ public class TasksFrame extends JFrame { setupRoundSum(); setupExponent(); + + setupKreisUmfang(); setupUmrechnen(); @@ -108,6 +110,51 @@ public class TasksFrame extends JFrame { } + private void setupKreisUmfang() { + + JPanel jPanel = setupPanel("Kreisumfang"); + + JButton button = new JButton("calculate"); + button.setVisible(true); + button.setBounds(10, 65, 100, 30); + button.setBackground(Color.BLUE); + + JTextField jTextField = new JTextField(); + jTextField.setVisible(true); + jTextField.setBounds( 10, 40, 30, 20); + jTextField.setFont(new java.awt.Font("Arial", Font.BOLD, 12)); + + + + JLabel jLabel = new JLabel(); + jLabel.setVisible(true); + jLabel.setBounds(10, 90, 60, 30); + + + jPanel.add(button); + jPanel.add(jTextField); + jPanel.add(jLabel); + + button.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + String text = jTextField.getText(); + Double val = Double.valueOf(text); + double res = Double.valueOf(kreisUmfang(val)); + jLabel.setText(String.valueOf(res)); + } + }); + } + + private double kreisUmfang(double radius) { + + double result = 2 * Math.PI * radius; + double roundOff = Math.round(result * 100.0) / 100.0; + return roundOff; + } + + + private void setupDurchschnitt() { JPanel jPanel = setupPanel("Durchschnitt");