From 3054032532113c29ab3a02106d41dc43221ef20c Mon Sep 17 00:00:00 2001 From: theitaliandeveloper Date: Thu, 13 Nov 2025 09:24:57 +0100 Subject: [PATCH] Nuovi progetti --- DisegnoPazzo/.gitignore | 30 ++++ DisegnoPazzo/.idea/.gitignore | 8 + DisegnoPazzo/.idea/misc.xml | 6 + DisegnoPazzo/.idea/modules.xml | 8 + DisegnoPazzo/.idea/vcs.xml | 6 + DisegnoPazzo/DisegnoPazzo.iml | 11 ++ DisegnoPazzo/src/CerchioTrascinabile.java | 111 ++++++++++++ SparaBalle/.gitignore | 30 ++++ SparaBalle/.idea/.gitignore | 8 + SparaBalle/.idea/misc.xml | 6 + SparaBalle/.idea/modules.xml | 8 + SparaBalle/.idea/vcs.xml | 6 + SparaBalle/SparaBalle.iml | 11 ++ SparaBalle/src/FallingBalls.java | 202 ++++++++++++++++++++++ 14 files changed, 451 insertions(+) create mode 100644 DisegnoPazzo/.gitignore create mode 100644 DisegnoPazzo/.idea/.gitignore create mode 100644 DisegnoPazzo/.idea/misc.xml create mode 100644 DisegnoPazzo/.idea/modules.xml create mode 100644 DisegnoPazzo/.idea/vcs.xml create mode 100644 DisegnoPazzo/DisegnoPazzo.iml create mode 100644 DisegnoPazzo/src/CerchioTrascinabile.java create mode 100644 SparaBalle/.gitignore create mode 100644 SparaBalle/.idea/.gitignore create mode 100644 SparaBalle/.idea/misc.xml create mode 100644 SparaBalle/.idea/modules.xml create mode 100644 SparaBalle/.idea/vcs.xml create mode 100644 SparaBalle/SparaBalle.iml create mode 100644 SparaBalle/src/FallingBalls.java diff --git a/DisegnoPazzo/.gitignore b/DisegnoPazzo/.gitignore new file mode 100644 index 0000000..13275f1 --- /dev/null +++ b/DisegnoPazzo/.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/DisegnoPazzo/.idea/.gitignore b/DisegnoPazzo/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/DisegnoPazzo/.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/DisegnoPazzo/.idea/misc.xml b/DisegnoPazzo/.idea/misc.xml new file mode 100644 index 0000000..188022c --- /dev/null +++ b/DisegnoPazzo/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/DisegnoPazzo/.idea/modules.xml b/DisegnoPazzo/.idea/modules.xml new file mode 100644 index 0000000..9a601d0 --- /dev/null +++ b/DisegnoPazzo/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/DisegnoPazzo/.idea/vcs.xml b/DisegnoPazzo/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/DisegnoPazzo/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/DisegnoPazzo/DisegnoPazzo.iml b/DisegnoPazzo/DisegnoPazzo.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/DisegnoPazzo/DisegnoPazzo.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/DisegnoPazzo/src/CerchioTrascinabile.java b/DisegnoPazzo/src/CerchioTrascinabile.java new file mode 100644 index 0000000..d588cb0 --- /dev/null +++ b/DisegnoPazzo/src/CerchioTrascinabile.java @@ -0,0 +1,111 @@ +import javax.swing.*; +import java.awt.*; +import java.awt.event.*; +import java.awt.geom.Ellipse2D; + +public class CerchioTrascinabile extends JFrame { + + public CerchioTrascinabile() { + setTitle("Cerchio Trascinabile"); + setSize(600, 500); + setLayout(null); + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + setLocationRelativeTo(null); + PannelloCerchio pannello = new PannelloCerchio(); + JButton btnCancella = new JButton("Cancella"); + btnCancella.addActionListener(e -> pannello.cancellaCerchio()); + JPanel bottomPanel = new JPanel(); + bottomPanel.add(btnCancella); + setLayout(new BorderLayout()); + add(pannello, BorderLayout.CENTER); + add(bottomPanel, BorderLayout.SOUTH); + } + + public static void main(String[] args) { + SwingUtilities.invokeLater(() -> { + new CerchioTrascinabile().setVisible(true); + }); + } +} + +class PannelloCerchio extends JPanel { + private Cerchio cerchio; + private boolean dragging = false; + + public PannelloCerchio() { + setBackground(Color.WHITE); + + addMouseListener(new MouseAdapter() { + @Override + public void mousePressed(MouseEvent e) { + if (cerchio == null) { + cerchio = new Cerchio(e.getX(), e.getY()); + repaint(); + } else if (cerchio.contiene(e.getX(), e.getY())) { + dragging = true; + } + } + + @Override + public void mouseReleased(MouseEvent e) { + dragging = false; + } + }); + + addMouseMotionListener(new MouseMotionAdapter() { + @Override + public void mouseDragged(MouseEvent e) { + if (dragging && cerchio != null) { + cerchio.muovi(e.getX(), e.getY()); + repaint(); + } + } + }); + } + + public void cancellaCerchio() { + cerchio = null; + repaint(); + } + + @Override + protected void paintComponent(Graphics g) { + super.paintComponent(g); + if (cerchio != null) { + Graphics2D g2d = (Graphics2D) g; + g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, + RenderingHints.VALUE_ANTIALIAS_ON); + cerchio.disegna(g2d); + } + } +} + +class Cerchio { + private int x, y; + private static final int RAGGIO = 40; + + public Cerchio(int x, int y) { + this.x = x; + this.y = y; + } + + public void muovi(int nuovoX, int nuovoY) { + this.x = nuovoX; + this.y = nuovoY; + } + + public boolean contiene(int px, int py) { + int dx = px - x; + int dy = py - y; + return dx * dx + dy * dy <= RAGGIO * RAGGIO; + } + + public void disegna(Graphics2D g2d) { + g2d.setColor(new Color(70, 130, 180)); + g2d.fillOval(x - RAGGIO, y - RAGGIO, RAGGIO * 2, RAGGIO * 2); + + g2d.setColor(new Color(30, 90, 140)); + g2d.setStroke(new BasicStroke(2)); + g2d.drawOval(x - RAGGIO, y - RAGGIO, RAGGIO * 2, RAGGIO * 2); + } +} \ No newline at end of file diff --git a/SparaBalle/.gitignore b/SparaBalle/.gitignore new file mode 100644 index 0000000..13275f1 --- /dev/null +++ b/SparaBalle/.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/SparaBalle/.idea/.gitignore b/SparaBalle/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/SparaBalle/.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/SparaBalle/.idea/misc.xml b/SparaBalle/.idea/misc.xml new file mode 100644 index 0000000..188022c --- /dev/null +++ b/SparaBalle/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/SparaBalle/.idea/modules.xml b/SparaBalle/.idea/modules.xml new file mode 100644 index 0000000..940b87e --- /dev/null +++ b/SparaBalle/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/SparaBalle/.idea/vcs.xml b/SparaBalle/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/SparaBalle/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/SparaBalle/SparaBalle.iml b/SparaBalle/SparaBalle.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/SparaBalle/SparaBalle.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/SparaBalle/src/FallingBalls.java b/SparaBalle/src/FallingBalls.java new file mode 100644 index 0000000..dae3dd6 --- /dev/null +++ b/SparaBalle/src/FallingBalls.java @@ -0,0 +1,202 @@ +import javax.swing.*; +import java.awt.*; +import java.awt.event.*; +import java.util.Random; + +class GameObject{ + private static final Random rnd = new Random(); + protected int x, y; + protected int speed; + protected int diam = rnd.nextInt(10, 30); + + GameObject(int maxW) { + reset(maxW); + } + + void reset(int maxW) { + x = rnd.nextInt(Math.max(1, maxW - diam)); + y = rnd.nextInt(50); + speed = 2 + rnd.nextInt(6); + } + + void update(int panelH, int panelW) { + y += speed; + if (y > panelH) reset(panelW); + } + + void draw(Graphics g) { + g.fillOval(x, y, diam, diam); + } +} + +class Pallina extends GameObject{ + public Pallina(int maxW) { + super(maxW); + } +} + +class Astronave extends GameObject{ + + Astronave() { + super(0); + } + + void update(int coordXMouse, int coordYMouse) { + x = coordXMouse; + y = coordYMouse; + } + + void draw(Graphics g) { + g.fillRect(x, y, diam, 50); + } +} + +class Proiettile extends GameObject{ + public Proiettile(int x, int y) { + super(0); + super.x = x; + super.y = y; + speed = -10; + } +} + +class ButtonHandler implements ActionListener{ + + private FallingBalls panel; + private JButton btn; + + public ButtonHandler(FallingBalls panel, JButton btn) { + this.panel = panel; + this.btn = btn; + } + + + + @Override + public void actionPerformed(ActionEvent e) { + panel.paused = !panel.paused; + btn.setText(panel.paused ? "Play" : "Pause"); + } + +} + +public class FallingBalls extends JPanel implements MouseMotionListener, MouseListener { + + static final int N_BALLS = 6; + Pallina[] balls = new Pallina[N_BALLS]; + Astronave astro = new Astronave(); + Proiettile p; + + boolean paused = false; + + public FallingBalls() { + setBounds(0,0,500, 400); + setBackground(Color.WHITE); + + for (int i = 0; i < N_BALLS; i++) + balls[i] = new Pallina(500); + + } + + @Override + protected void paintComponent(Graphics g) { + super.paintComponent(g); + g.setColor(Color.RED); + for (int i=0; i { + panel.paused = !panel.paused; + btn.setText(panel.paused ? "Play" : "Pause"); + }); + */ + + f.add(btn); + + + f.setVisible(true); + + while(true) { + panel.update(); + panel.repaint(); + try { + Thread.sleep(16); + } catch (InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } + + @Override + public void mouseDragged(MouseEvent e) { + // TODO Auto-generated method stub + + } + + @Override + public void mouseMoved(MouseEvent e) { + astro.x = e.getX(); + astro.y = e.getY(); + + } + + @Override + public void mouseClicked(MouseEvent e) { + // TODO Auto-generated method stub + + } + + @Override + public void mousePressed(MouseEvent e) { + p = new Proiettile(e.getX(), e.getY()); + } + + @Override + public void mouseReleased(MouseEvent e) { + // TODO Auto-generated method stub + + } + + @Override + public void mouseEntered(MouseEvent e) { + // TODO Auto-generated method stub + + } + + @Override + public void mouseExited(MouseEvent e) { + // TODO Auto-generated method stub + + } +}