From 4ca42b835cb10f39a074c2220d557d21e463b394 Mon Sep 17 00:00:00 2001 From: Vichingo455 Date: Thu, 6 Nov 2025 09:36:30 +0100 Subject: [PATCH] Commit --- Calculator/.gitignore | 30 ++++ Calculator/.idea/.gitignore | 8 + Calculator/.idea/misc.xml | 6 + Calculator/.idea/modules.xml | 8 + Calculator/.idea/vcs.xml | 6 + Calculator/src/calc/CalcolatriceMain.java | 79 +++++++++ LePallineMeravigliose/.gitignore | 30 ++++ LePallineMeravigliose/.idea/.gitignore | 8 + LePallineMeravigliose/.idea/misc.xml | 6 + LePallineMeravigliose/.idea/modules.xml | 8 + LePallineMeravigliose/.idea/vcs.xml | 6 + .../src/FallingBallsGUI.java | 153 ++++++++++++++++++ 12 files changed, 348 insertions(+) create mode 100644 Calculator/.gitignore create mode 100644 Calculator/.idea/.gitignore create mode 100644 Calculator/.idea/misc.xml create mode 100644 Calculator/.idea/modules.xml create mode 100644 Calculator/.idea/vcs.xml create mode 100644 Calculator/src/calc/CalcolatriceMain.java create mode 100644 LePallineMeravigliose/.gitignore create mode 100644 LePallineMeravigliose/.idea/.gitignore create mode 100644 LePallineMeravigliose/.idea/misc.xml create mode 100644 LePallineMeravigliose/.idea/modules.xml create mode 100644 LePallineMeravigliose/.idea/vcs.xml create mode 100644 LePallineMeravigliose/src/FallingBallsGUI.java diff --git a/Calculator/.gitignore b/Calculator/.gitignore new file mode 100644 index 0000000..13275f1 --- /dev/null +++ b/Calculator/.gitignore @@ -0,0 +1,30 @@ +### IntelliJ IDEA ### +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ +.kotlin + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/Calculator/.idea/.gitignore b/Calculator/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/Calculator/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/Calculator/.idea/misc.xml b/Calculator/.idea/misc.xml new file mode 100644 index 0000000..07115cd --- /dev/null +++ b/Calculator/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Calculator/.idea/modules.xml b/Calculator/.idea/modules.xml new file mode 100644 index 0000000..b61c8db --- /dev/null +++ b/Calculator/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/Calculator/.idea/vcs.xml b/Calculator/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/Calculator/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Calculator/src/calc/CalcolatriceMain.java b/Calculator/src/calc/CalcolatriceMain.java new file mode 100644 index 0000000..9a4e650 --- /dev/null +++ b/Calculator/src/calc/CalcolatriceMain.java @@ -0,0 +1,79 @@ +package calc; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JTextField; + +class ButtonHandler implements ActionListener { + JTextField tf; + int a,b; + String op; + + public ButtonHandler(JTextField tf) { + this.tf = tf; + } + @Override + public void actionPerformed(ActionEvent e) { + if (e.getActionCommand().equals("+") || e.getActionCommand().equals("-")) { + op = e.getActionCommand(); + a = Integer.parseInt(tf.getText()); + tf.setText(""); + return; + } + if (e.getActionCommand().equals("=")) { + b = Integer.parseInt(tf.getText()); + if(op.equals("+")) tf.setText(""+(a+b)); + if(op.equals("-")) tf.setText(""+(a-b)); + return; + } + tf.setText(tf.getText()+e.getActionCommand()); + } +} + + +// Classe principale con il metodo main +public class CalcolatriceMain { + public static void main(String[] args) { + JFrame f = new JFrame("titolo"); + f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + f.setBounds(100, 100, 300, 500); + f.setLayout(null); + + JTextField tf = new JTextField("0"); + tf.setBounds(10, 10, 240, 80); + f.add(tf); + ButtonHandler bh = new ButtonHandler(tf); + + int x = 10; + int y = 100; + int cont = 1; + + for (int j = 0; j < 3; j++) { + for (int i = 0; i < 3; i++) { + JButton bn = new JButton("" + cont); + bn.setActionCommand("" + cont); + bn.setBounds(x, y, 80, 80); + f.add(bn); + x += 80; + bn.addActionListener(bh); + cont++; + } + y += 80; + x = 10; + } + + String[] etichette = {"+","-","="}; + for (int i = 0; i < 3; i++) { + JButton bn = new JButton(etichette[i]); + bn.setActionCommand(etichette[i]); + bn.setBounds(x, y, 80, 80); + f.add(bn); + x += 80; + bn.addActionListener(bh); + } + + f.setVisible(true); + } +} \ No newline at end of file diff --git a/LePallineMeravigliose/.gitignore b/LePallineMeravigliose/.gitignore new file mode 100644 index 0000000..13275f1 --- /dev/null +++ b/LePallineMeravigliose/.gitignore @@ -0,0 +1,30 @@ +### IntelliJ IDEA ### +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ +.kotlin + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/LePallineMeravigliose/.idea/.gitignore b/LePallineMeravigliose/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/LePallineMeravigliose/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/LePallineMeravigliose/.idea/misc.xml b/LePallineMeravigliose/.idea/misc.xml new file mode 100644 index 0000000..07115cd --- /dev/null +++ b/LePallineMeravigliose/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/LePallineMeravigliose/.idea/modules.xml b/LePallineMeravigliose/.idea/modules.xml new file mode 100644 index 0000000..03df505 --- /dev/null +++ b/LePallineMeravigliose/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/LePallineMeravigliose/.idea/vcs.xml b/LePallineMeravigliose/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/LePallineMeravigliose/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/LePallineMeravigliose/src/FallingBallsGUI.java b/LePallineMeravigliose/src/FallingBallsGUI.java new file mode 100644 index 0000000..06ea9d3 --- /dev/null +++ b/LePallineMeravigliose/src/FallingBallsGUI.java @@ -0,0 +1,153 @@ +import javax.swing.*; +import java.awt.*; +import java.awt.event.*; +import java.util.ArrayList; +import java.util.Random; + +public class FallingBallsGUI extends JFrame { + private ArrayList balls; + private boolean isPlaying = false; + private Timer timer; + private BallPanel ballPanel; + private Random random = new Random(); + + public FallingBallsGUI() { + setTitle("Palline che Cadono"); + setSize(450, 750); + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + setLayout(new BorderLayout()); + setLocationRelativeTo(null); + + // Inizializza le palline + balls = new ArrayList<>(); + Color[] colors = { + new Color(255, 107, 107), + new Color(78, 205, 196), + new Color(69, 183, 209), + new Color(255, 160, 122), + new Color(152, 216, 200), + new Color(247, 220, 111) + }; + + for (int i = 0; i < 6; i++) { + Ball ball = new Ball( + random.nextInt(360) + 20, + random.nextInt(200) * -1 - 20, + 20, + random.nextDouble() * 2 + 1, + colors[i] + ); + balls.add(ball); + } + + // Pannello per disegnare le palline + ballPanel = new BallPanel(); + add(ballPanel, BorderLayout.CENTER); + + // Pannello per il bottone + JPanel buttonPanel = new JPanel(); + buttonPanel.setBackground(new Color(245, 245, 245)); + JButton playPauseButton = new JButton("Play"); + playPauseButton.setFont(new Font("Arial", Font.BOLD, 18)); + playPauseButton.setPreferredSize(new Dimension(150, 50)); + playPauseButton.setBackground(new Color(76, 175, 80)); + playPauseButton.setForeground(Color.WHITE); + playPauseButton.setFocusPainted(false); + + playPauseButton.addActionListener(e -> { + isPlaying = !isPlaying; + if (isPlaying) { + playPauseButton.setText("Pause"); + playPauseButton.setBackground(new Color(244, 67, 54)); + } else { + playPauseButton.setText("Play"); + playPauseButton.setBackground(new Color(76, 175, 80)); + } + }); + + buttonPanel.add(playPauseButton); + add(buttonPanel, BorderLayout.SOUTH); + + // Timer per l'animazione + timer = new Timer(16, e -> { + if (isPlaying) { + for (Ball ball : balls) { + ball.move(); + // Se la pallina esce dal fondo, riposiziona in alto + if (ball.y - ball.radius > ballPanel.getHeight()) { + ball.y = random.nextInt(200) * -1 - 20; + ball.x = random.nextInt(ballPanel.getWidth() - 40) + 20; + ball.speed = random.nextDouble() * 2 + 1; + } + } + } + ballPanel.repaint(); + }); + timer.start(); + } + + // Classe per rappresentare una pallina + class Ball { + double x, y; + int radius; + double speed; + Color color; + + Ball(double x, double y, int radius, double speed, Color color) { + this.x = x; + this.y = y; + this.radius = radius; + this.speed = speed; + this.color = color; + } + + void move() { + y += speed; + } + } + + // Pannello personalizzato per disegnare le palline + class BallPanel extends JPanel { + BallPanel() { + setBackground(new Color(230, 240, 255)); + } + + @Override + protected void paintComponent(Graphics g) { + super.paintComponent(g); + Graphics2D g2d = (Graphics2D) g; + g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, + RenderingHints.VALUE_ANTIALIAS_ON); + + for (Ball ball : balls) { + // Disegna la pallina + g2d.setColor(ball.color); + g2d.fillOval((int)(ball.x - ball.radius), + (int)(ball.y - ball.radius), + ball.radius * 2, + ball.radius * 2); + + // Bordo + g2d.setColor(new Color(0, 0, 0, 50)); + g2d.setStroke(new BasicStroke(2)); + g2d.drawOval((int)(ball.x - ball.radius), + (int)(ball.y - ball.radius), + ball.radius * 2, + ball.radius * 2); + + // Effetto lucido + g2d.setColor(new Color(255, 255, 255, 150)); + g2d.fillOval((int)(ball.x - 7), + (int)(ball.y - 7), + 12, 12); + } + } + } + + public static void main(String[] args) { + SwingUtilities.invokeLater(() -> { + FallingBallsGUI gui = new FallingBallsGUI(); + gui.setVisible(true); + }); + } +} \ No newline at end of file