Compare commits

...

2 Commits

Author SHA1 Message Date
4ca42b835c Commit 2025-11-06 09:36:30 +01:00
72a5882f3f Commit 2025-11-06 09:36:23 +01:00
14 changed files with 370 additions and 0 deletions

30
Calculator/.gitignore vendored Normal file
View File

@@ -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

8
Calculator/.idea/.gitignore generated vendored Normal file
View File

@@ -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

6
Calculator/.idea/misc.xml generated Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="17" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

8
Calculator/.idea/modules.xml generated Normal file
View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/Calculator.iml" filepath="$PROJECT_DIR$/Calculator.iml" />
</modules>
</component>
</project>

6
Calculator/.idea/vcs.xml generated Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
</component>
</project>

11
Calculator/Calculator.iml Normal file
View File

@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@@ -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);
}
}

30
LePallineMeravigliose/.gitignore vendored Normal file
View File

@@ -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

8
LePallineMeravigliose/.idea/.gitignore generated vendored Normal file
View File

@@ -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

6
LePallineMeravigliose/.idea/misc.xml generated Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="17" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

8
LePallineMeravigliose/.idea/modules.xml generated Normal file
View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/LePallineMeravigliose.iml" filepath="$PROJECT_DIR$/LePallineMeravigliose.iml" />
</modules>
</component>
</project>

6
LePallineMeravigliose/.idea/vcs.xml generated Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
</component>
</project>

View File

@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@@ -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<Ball> 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);
});
}
}