Nuovi progetti
This commit is contained in:
30
DisegnoPazzo/.gitignore
vendored
Normal file
30
DisegnoPazzo/.gitignore
vendored
Normal 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
DisegnoPazzo/.idea/.gitignore
generated
vendored
Normal file
8
DisegnoPazzo/.idea/.gitignore
generated
vendored
Normal 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
DisegnoPazzo/.idea/misc.xml
generated
Normal file
6
DisegnoPazzo/.idea/misc.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_25" default="true" project-jdk-name="25" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
||||
8
DisegnoPazzo/.idea/modules.xml
generated
Normal file
8
DisegnoPazzo/.idea/modules.xml
generated
Normal file
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/DisegnoPazzo.iml" filepath="$PROJECT_DIR$/DisegnoPazzo.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
6
DisegnoPazzo/.idea/vcs.xml
generated
Normal file
6
DisegnoPazzo/.idea/vcs.xml
generated
Normal 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
DisegnoPazzo/DisegnoPazzo.iml
Normal file
11
DisegnoPazzo/DisegnoPazzo.iml
Normal 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>
|
||||
111
DisegnoPazzo/src/CerchioTrascinabile.java
Normal file
111
DisegnoPazzo/src/CerchioTrascinabile.java
Normal file
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user