ciao!
sto cercando di replicare il programma paint proposto sul sito ma appena ho importato il codice da voi proposto ho iniziato ad avere una miriade di errori ho provato a modificarlo + e + volte ma ho ancora degli errori(oltre al fatto che mi dice che il main non esiste )
vi prego datemi una mano l'errore che ho ora è questo)
dove ho segnato mi da errore.... e non capisco perchè
sto cercando di replicare il programma paint proposto sul sito ma appena ho importato il codice da voi proposto ho iniziato ad avere una miriade di errori ho provato a modificarlo + e + volte ma ho ancora degli errori(oltre al fatto che mi dice che il main non esiste )
vi prego datemi una mano l'errore che ho ora è questo)
Codice:
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;
import java.awt.geom.Line2D;
import java.awt.geom.Line2D.Double;
import java.util.Stack;
public class PaintFinestra extends JFrame
{
private Color [] color = {Color.black,Color.blue,Color.cyan,Color.DARK_GRAY,
Color.gray,Color.green,Color.LIGHT_GRAY,Color.magenta,Color.orange,Color.pink,
Color.white};
private Pulsante[] controllo;
private JPanel pannelloBottoni;
private PaintPannello pannelloprincipale;
private JComboBox stroke;
private Color coloreStringa;
public Integer spessore;
public PaintFinestra(String title)
{
super(title);
spessore = 1;
pannelloBottoni = new JPanel();
controllo = new Pulsante[11];
stroke = new JComboBox();
stroke.addItem(new Spessore(1));
stroke.addItem(new Spessore(2));
stroke.addItem(new Spessore(3));
stroke.addItem(new Spessore(4));
stroke.addItem(new Spessore(5));
stroke.addItem(new Spessore(6));
stroke.addItem(new Spessore(7));
stroke.addItem(new Spessore(8));
stroke.addItem(new Spessore(9));
stroke.addItem(new Spessore(10));
stroke.addActionListener(new Spessorizza());
for (int i = 0; i < 11; ++i)
{
controllo[i] = new Pulsante(color[i]);
pannelloBottoni.add(controllo[i]);
controllo[i].addActionListener(new GestionePulsanti());
}
pannelloprincipale = new PaintPannello();
this.add(pannelloBottoni,BorderLayout.SOUTH);
this.add(pannelloprincipale, BorderLayout.CENTER);
this.add(stroke,BorderLayout.NORTH);
}
public class Spessorizza implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
spessore = ((Spessore)stroke.getSelectedItem()).pixel;
}
}
class GestionePulsanti implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
Pulsante source = (Pulsante)event.getSource();
coloreStringa = source.color;
}
}
public class PaintPannello extends JPanel
{
private float lastX, lastY;
private Stack lines;
private boolean richiestaRepaint;
public class Linea
{
public Line2D linea;
public Integer stroke;
public Color color;
}
public PaintPannello()
{
super();
lines = new Stack();
richiestaRepaint = false;
setLayout(new BorderLayout());
this.addMouseListener(new HandleMouseClicked());
this.addMouseMotionListener(new HandleMouseDragged());
}
private class HandleMouseClicked extends MouseAdapter
{
public void mousePressed(MouseEvent e)
{
lastX = e.getX();
lastY = e.getY();
}
}
private class HandleMouseDragged extends MouseMotionAdapter
{
public void mouseDragged(MouseEvent e)
{
int x = e.getX();
int y = e.getY();
Linea temp = new Linea();
temp.linea = new Line2D.Double(lastX,lastY,x,y);
temp.color = coloreStringa;
temp.stroke = spessore;
lines.add(temp);
lastX = x;
lastY = y;
richiestaRepaint = true;
repaint();
}
}
public void paintComponent(Graphics g)
{
Graphics2D g2 = (Graphics2D)g;
if (richiestaRepaint)
{
richiestaRepaint = false;
Linea temp1 = new Linea();
temp1 =(PaintFinestra.PaintPannello.Linea) lines.lastElement();
g2.setPaint(temp1.color);
g2.setStroke(new BasicStroke(temp1.stroke));
g2.draw(temp1.linea);
}
else
{
for ([COLOR="Red"]Linea line : lines[/COLOR])
{
g2.setPaint(line.color);
g2.setStroke(new BasicStroke(line.stroke));
g2.draw(line.linea);
}
}
}
}
}
dove ho segnato mi da errore.... e non capisco perchè