Commit fcfbfc10 authored by Beuster's avatar Beuster
Browse files

Merge branch '99-test_issue_3_tim' into 'dev_cpp_code_conversion'

Resolve "test_issue_3_tim"

See merge request !20
parents df41d148 21e812e8
Pipeline #10411 passed with stage
in 2 minutes and 16 seconds
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>test</name>
<name>AngleConverter</name>
<comment></comment>
<projects>
</projects>
......
import java.awt.*;
import javax.swing.*;
public class AngleDrawer extends JFrame {
private static final long serialVersionUID = 1L; // Empfohlene serialVersionUID
private final JTextField gradField;
private final DrawPanel drawPanel;
public AngleDrawer() {
// Fenster konfigurieren
setTitle("Grad-Anzeige auf Kreis");
setSize(400, 400);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(null); // Kein Layout-Manager, manuelle Positionierung
// Eingabefeld und Label
JLabel label = new JLabel("Grad:");
label.setBounds(20, 20, 50, 30); // x, y, Breite, Höhe
add(label);
gradField = new JTextField();
gradField.setBounds(70, 20, 100, 30);
add(gradField);
// Button
JButton drawButton = new JButton("Zeichnen");
drawButton.setBounds(180, 20, 100, 30);
add(drawButton);
// Zeichenbereich
drawPanel = new DrawPanel();
drawPanel.setBounds(20, 70, 350, 280); // Position und Größe des Zeichenbereichs
add(drawPanel);
// Button-Action
drawButton.addActionListener(e -> {
try {
double grad = Double.parseDouble(gradField.getText());
drawPanel.setAngle(grad);
} catch (NumberFormatException ex) {
JOptionPane.showMessageDialog(this, "Bitte eine gültige Gradzahl eingeben.");
}
});
}
private static class DrawPanel extends JPanel {
private static final long serialVersionUID = 1L; // Empfohlene serialVersionUID
private double angle = 0; // Winkel in Grad
public void setAngle(double angle) {
this.angle = angle % 360; // Winkel auf Bereich [0, 360) reduzieren
repaint(); // Neuzeichnen des Panels anfordern
}
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
// Panel-Mitte und Radius berechnen
int width = getWidth();
int height = getHeight();
int radius = Math.min(width, height) / 2 - 10;
int centerX = width / 2;
int centerY = height / 2;
// Kreis zeichnen
g.drawOval(centerX - radius, centerY - radius, radius * 2, radius * 2);
// Pfeil berechnen und zeichnen
double radian = Math.toRadians(angle);
int arrowX = centerX + (int) (radius * Math.cos(radian));
int arrowY = centerY - (int) (radius * Math.sin(radian));
g.drawLine(centerX, centerY, arrowX, arrowY);
// Winkel anzeigen
g.drawString("Grad: " + (int) angle, 10, 20);
}
}
public static void main(String[] args) {
// GUI starten
SwingUtilities.invokeLater(() -> {
AngleDrawer frame = new AngleDrawer();
frame.setVisible(true);
});
}
}
......@@ -6,7 +6,7 @@ public class JavaMenu
{
public static void main(String[] args)
{
System.out.println("Hallo, bitte gebe deinen Namen ein: ");
System.out.println("Hallo, bitte gebe deinen Nachnamen und Vornamen ein: ");
String name = System.console().readLine();
......
!SESSION 2024-11-24 19:29:34.785 -----------------------------------------------
eclipse.buildId=4.33.0.20240905-0613
java.version=23
java.vendor=Eclipse Adoptium
BootLoader constants: OS=macosx, ARCH=aarch64, WS=cocoa, NL=de_DE
Framework arguments: -product org.eclipse.epp.package.java.product -keyring /Users/jessica/.eclipse_keyring
Command-line arguments: -os macosx -ws cocoa -arch aarch64 -product org.eclipse.epp.package.java.product -keyring /Users/jessica/.eclipse_keyring
!ENTRY ch.qos.logback.classic 1 0 2024-11-24 19:29:35.853
!MESSAGE Activated before the state location was initialized. Retry after the state location is initialized.
!ENTRY ch.qos.logback.classic 1 0 2024-11-24 19:30:06.041
!MESSAGE Logback config file: /Users/jessica/Documents/UDigiT-Doctor2dev_cpp_code_conversion/test/.metadata/.plugins/org.eclipse.m2e.logback/logback.2.6.1.20240411-1122.xml
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=22
org.eclipse.jdt.core.compiler.compliance=22
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=22
package test;
import java.util.Scanner;
public class test {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Gib die erste Zahl ein:");
double zahl1 = scanner.nextDouble();
System.out.println("Gib die zweite Zahl ein:");
double zahl2 = scanner.nextDouble();
System.out.println("Wähle eine Operation (+, -, *, /):");
char operator = scanner.next().charAt(0);
double ergebnis;
switch (operator) {
case '+':
ergebnis = zahl1 + zahl2;
break;
case '-':
ergebnis = zahl1 - zahl2;
break;
case '*':
ergebnis = zahl1 * zahl2;
break;
case '/':
if (zahl2 != 0) {
ergebnis = zahl1 / zahl2;
} else {
System.out.println("Division durch Null ist nicht erlaubt.");
return;
}
break;
default:
System.out.println("Ungültiger Operator.");
return;
}
System.out.println("Das Ergebnis ist: " + ergebnis);
}
}
Supports Markdown
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