Torna indietro   Hardware Upgrade Forum > Software > Programmazione

iPhone 17 Pro: più di uno smartphone. È uno studio di produzione in formato tascabile
iPhone 17 Pro: più di uno smartphone. È uno studio di produzione in formato tascabile
C'è tanta sostanza nel nuovo smartphone della Mela dedicato ai creator digitali. Nuovo telaio in alluminio, sistema di raffreddamento vapor chamber e tre fotocamere da 48 megapixel: non è un semplice smartphone, ma uno studio di produzione digitale on-the-go
Intel Panther Lake: i processori per i notebook del 2026
Intel Panther Lake: i processori per i notebook del 2026
Panther Lake è il nome in codice della prossima generazione di processori Intel Core Ultra, che vedremo al debutto da inizio 2026 nei notebook e nei sistemi desktop più compatti. Nuovi core, nuove GPU e soprattutto una struttura a tile che vede per la prima volta l'utilizzo della tecnologia produttiva Intel 18A: tanta potenza in più, ma senza perdere in efficienza
Intel Xeon 6+: è tempo di Clearwater Forest
Intel Xeon 6+: è tempo di Clearwater Forest
Intel ha annunciato la prossima generazione di processori Xeon dotati di E-Core, quelli per la massima efficienza energetica e densità di elaborazione. Grazie al processo produttivo Intel 18A, i core passano a un massimo di 288 per ogni socket, con aumento della potenza di calcolo e dell'efficienza complessiva.
Tutti gli articoli Tutte le news

Vai al Forum
Rispondi
 
Strumenti
Old 06-05-2007, 20:55   #21
mariade
Senior Member
 
L'Avatar di mariade
 
Iscritto dal: Jun 2005
Città: Swords, Dublino
Messaggi: 642
non lo posto tutto, perche' e' uguale al tuo postato prima, con l'aggiunta del caso 8 e 9.
mariade è offline   Rispondi citando il messaggio o parte di esso
Old 06-05-2007, 21:03   #22
mariade
Senior Member
 
L'Avatar di mariade
 
Iscritto dal: Jun 2005
Città: Swords, Dublino
Messaggi: 642
Forse e' meglio che lo posto tutto:

Codice:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.FileOutputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.EOFException;
import java.io.ObjectOutputStream;
import java.io.ObjectInputStream;
import java.util.NoSuchElementException;

public class ShapeDrawJFrame extends JFrame
{

	private final int SHAPETYPES = 10;
	private int shapeType = 0;
	private String shapeTypes[] = { "Line", "Oval", "Rectangle", "FilledOval", "FilledRectangle", "Arc", "FilledArc", "Poligon", "FilledPolygon", "Polyline" };
	private int numShapes = 0;
	private int XYValues[] = new int[4];
	private int numPoints = 0;
	private int x[] = new int[500];
	private int y[] = new int[500];
	private int count = 1;
	private MyShape[] shapes = new MyShape[100];
	private JComboBox shapesComboBox;
	private JComboBox colorChoice;
	private Container container;
	private JPanel lowerRow;
	private JPanel upperRow;
	private JButton undoButton;
	private JLabel label;
	private Graphics dragGraphics;
	private Color dragColor;
	private int sAngle;
	private int aAngle;
	private String startAngle;
	private String arcAngle;
	private String topAngle;
	private String endAngle;
	private int tAngle = 0;
	private int eAngle = 0;
	private ObjectOutputStream output;
	private ObjectInputStream input;
	private int numCount = 0;

	private final static int
	BLACK = 0,
	RED = 1,            // Some constants to make                           
	GREEN = 2,          // the code more readable.                            
	BLUE = 3,           // These numbers code for                          
	CYAN = 4,           // the different drawing colors.                       
	MAGENTA = 5,
	YELLOW = 6,
	ORANGE = 7,
	PINK = 8,
	GRAY = 9;

	private boolean beingDragged;
	private JButton save, load;
	private JTextField fileName;

	public ShapeDrawJFrame()
	{

		super("Draw Shapes");

		// addMouseListener(handler);
		//     addMouseMotionListener(handler);		
		container = getContentPane();
		container.setBackground(new Color(255, 255, 255));


		lowerRow = new JPanel();
		label = new JLabel("You have select the type of shape to draw:");
		lowerRow.add(label);

		shapesComboBox = new JComboBox(shapeTypes);
		shapesComboBox.setSelectedIndex(0);
		shapesComboBox.addActionListener(
				 new ActionListener()
		{
			public void actionPerformed(ActionEvent event)
			{

				//if the polygon or polyline are chosen reset the numPoints counter
				if (shapesComboBox.getSelectedIndex() == 7 || shapesComboBox.getSelectedIndex() == 8 || shapesComboBox.getSelectedIndex() == 9)
				{
					numPoints = Integer.parseInt(JOptionPane.showInputDialog("Enter the number of the points:"));

				}
			}
		});
		lowerRow.add(shapesComboBox);

		colorChoice = new JComboBox();
		colorChoice.addItem("Black");
		colorChoice.addItem("Red");
		colorChoice.addItem("Green");
		colorChoice.addItem("Blue");
		colorChoice.addItem("Cyan");
		colorChoice.addItem("Magenta");
		colorChoice.addItem("Yellow");
		colorChoice.addItem("Orange");
		colorChoice.addItem("Pink");
		colorChoice.addItem("Gray");
		colorChoice.setBackground(Color.white);
		lowerRow.add(colorChoice);



		undoButton = new JButton("UNDO");
		undoButton.addActionListener(
				 new ActionListener()
		{
			public void actionPerformed(ActionEvent event)
			{

				// puts the current position in the array as null
				for (int count = numShapes + 3; count >= numShapes; count--)
					shapes[count] = null;

				// if the counter is not in the first position decrement it so that the array
				// does not run out
				if (numShapes > 0)
				{
					numShapes--;
				}

				// this sets the polygon shape counter back to zero so that if the undone shape was a polygon
				// the user can draw another


				// refresh the screen
				repaint();
			}
		}
		);

		lowerRow.add(undoButton);


		container.add(lowerRow, BorderLayout.SOUTH);

		MouseHandler handler = new MouseHandler();
		addMouseListener(handler);
		addMouseMotionListener(handler);


		upperRow = new JPanel();
		save = new JButton("  Save ");
		upperRow.add(save);
		save.addActionListener(

			new ActionListener()
		{
			public void actionPerformed(ActionEvent event)
			{
				openOutputFile();
				writeShapes();
				closeFile();


			}
		}
		);


		load = new JButton("  Load ");
		upperRow.add(load);
		load.addActionListener(

			new ActionListener()
		{
			public void actionPerformed(ActionEvent event)
			{
				openInputFile();
				readShapes();
				closeFile();
				repaint();

			}
		}
		);

		fileName = new JTextField(15);
		upperRow.add(fileName);

		container.add(upperRow, BorderLayout.NORTH);

		setSize(600, 600);
		setVisible(true);

	}

	public void paint(Graphics g)
	{
		super.paint(g);
		for (int sp = 0; sp < shapes.length; sp++)
		{
			if (shapes[sp] != null)
			{

				//g.setColor(dragColor);			

				shapes[sp].draw(g);
			}
		}
	}

	public void createShape(int index)
	{

		numShapes++;

		switch (index)
		{
			case 0: shapes[numShapes] = new Line(XYValues, getCurrentColor()); break;
			case 1: shapes[numShapes] = new Oval(XYValues, getCurrentColor()); break;
			case 2: shapes[numShapes] = new Rectangle(XYValues, getCurrentColor()); break;
			case 3: shapes[numShapes] = new FilledOval(XYValues, getCurrentColor()); break;
			case 4: shapes[numShapes] = new FilledRectangle(XYValues, getCurrentColor()); break;
			case 5:

				String startAngle = JOptionPane.showInputDialog("Enter startAngle:");

				int sAngle = Integer.parseInt(startAngle);
				String arcAngle = JOptionPane.showInputDialog("Enter arcAngle:");

				int aAngle = Integer.parseInt(arcAngle);

				if (sAngle >= 0 && aAngle >= 0)
				{

					shapes[numShapes] = new Arc(XYValues, sAngle, aAngle, getCurrentColor()); break;
				}



			case 6:

				String topAngle = JOptionPane.showInputDialog("Enter startAngle:");

				int tAngle = Integer.parseInt(topAngle);
				String endAngle = JOptionPane.showInputDialog("Enter arcAngle:");

				int eAngle = Integer.parseInt(endAngle);

				if (tAngle >= 0 && eAngle >= 0)
				{

					shapes[numShapes] = new FilledArc(XYValues, tAngle, eAngle, getCurrentColor()); break;
				}

			case 7: System.out.println(numPoints);
				shapes[numShapes] = new Polygon(x, y, numPoints, getCurrentColor()); break;

			case 8: System.out.println(numPoints);
				shapes[numShapes] = new FilledPolygon(x, y, numPoints, getCurrentColor()); break;

			case 9: System.out.println(numPoints);
				shapes[numShapes] = new Polyline(x, y, numPoints, getCurrentColor()); break;


		}
	}



	private Color getCurrentColor()
	{
		// Check the colorChoice menu to find the currently               
		// selected color, and return the appropriate color              
		// object.        

		int currentColor = colorChoice.getSelectedIndex();
		Color colorPlot = new Color(0, 0, 0);

		switch (currentColor)
		{

			case 0:
				colorPlot = Color.BLACK;
				break;

			case 1:
				colorPlot = Color.RED;
				break;

			case 2:
				colorPlot = Color.GREEN;
				break;

			case 3:
				colorPlot = Color.BLUE;
				break;

			case 4:
				colorPlot = Color.CYAN;
				break;

			case 5:
				colorPlot = Color.MAGENTA;
				break;

			case 6:
				colorPlot = Color.YELLOW;
				break;

			case 7:
				colorPlot = Color.ORANGE;
				break;

			case 8:
				colorPlot = Color.PINK;
				break;

			case 9:
				colorPlot = Color.GRAY;
				break;

			default:
				colorPlot = Color.BLACK;
				break;
		}

		return colorPlot;

	}


	private class MouseHandler implements MouseMotionListener, MouseListener
	{

		public void mousePressed(MouseEvent event)
		{

			XYValues[0] = event.getX();
			XYValues[1] = event.getY();


			//dragGraphics = container.getGraphics();                               
			//dragColor = getCurrentColor();                               
			//dragGraphics.setColor(dragColor);    

		}


		public void mouseDragged(MouseEvent event)
		{
			XYValues[2] = event.getX();
			XYValues[3] = event.getY();

			if (shapesComboBox.getSelectedIndex() != 5)
			{

				if (shapesComboBox.getSelectedIndex() != 6)
				{

					if (shapesComboBox.getSelectedIndex() != 7)
					{
						if (shapesComboBox.getSelectedIndex() != 8)
						{
							if (shapesComboBox.getSelectedIndex() != 9)
							{


								createShape(shapesComboBox.getSelectedIndex());
								numShapes--;

								repaint();
							}
						}
					}
				}
			}
		}
		

		public void mouseReleased(MouseEvent event)
		{

			XYValues[2] = event.getX();
			XYValues[3] = event.getY();



			//createShape(shapesComboBox.getSelectedIndex());                      

			repaint();
		}



		public void mouseEntered(MouseEvent event) { }


		public void mouseClicked(MouseEvent event)
		{
			if (shapesComboBox.getSelectedIndex() == 7||shapesComboBox.getSelectedIndex() == 8||shapesComboBox.getSelectedIndex() == 9)
			{
				 
				

						if (numCount < (numPoints - 1))
						{
							x[numCount] = event.getX();
							y[numCount] = event.getY();
							//System.out.println(numCount+"  "+x[numCount]);
							// System.out.println("in click " + numCount + numPoints + "  "+ x[numCount] + "   " + y[numCount]);
							//createShape(shapesComboBox.getSelectedIndex());
							//repaint();
							numCount++;
							repaint();
							//if(numCount==numPoints) numCount=0;
						}
						else
						{
							numShapes--;
							x[numCount] = event.getX();
							y[numCount] = event.getY();
							System.out.println("---->" + numCount + "   " + numPoints);
							createShape(shapesComboBox.getSelectedIndex());
							numCount = 0;
							repaint();
						}
					}
			
		}


		public void mouseExited(MouseEvent event) { }


		public void mouseMoved(MouseEvent event) { }


	}

	public void setX(int n, int x)
	{
		if (x < 10)
			this.x[n] = 10;
		else if (x > (getWidth() - 10))
			this.x[n] = (getWidth() - 10);
		else
			this.x[n] = x;
	}


	public void setY(int n, int y)
	{
		if (y < 55)
			this.y[n] = 53;
		else if (y > (getHeight() - 40))
			this.y[n] = (getHeight() - 40);
		else
			this.y[n] = y;
	}

	public int getValX(int n)
	{
		return x[n];
	}

	public int getValY(int n)
	{
		return y[n];
	}



	public void openOutputFile()
	{


		try
		{
			output = new ObjectOutputStream(new FileOutputStream(fileName.getText()));

		}
		catch (IOException ioException)
		{
			System.err.println("error output opening file");

		}

	}


	public void openInputFile()
	{


		try
		{
			input = new ObjectInputStream(new FileInputStream(fileName.getText()));

		}
		catch (IOException ioException)
		{
			System.err.println("error input opening file");

		}

	}


	public void closeFile()
	{
		try
		{

			if (input != null)
				input.close();
			if (output != null)
				output.close();

		}
		catch (IOException ioException)
		{
			System.err.println("error closing file");
			System.exit(1);

		}

	}




	public void writeShapes()
	{
		for (int sp = 0; sp < shapes.length; sp++)
		{
			try
			{
				if (shapes[sp] != null)
				{
					output.writeObject(shapes[sp]);
				}

			}
			catch (IOException ioException)
			{
				System.err.println("error writing to file");
				return;
			}
			catch (NoSuchElementException elementException)
			{
				System.err.println("Invalid Input. Please try again");

			}


		}

	}


	public void readShapes()
	{

		for (int i = 0; i < numShapes; i++) shapes[i] = null;
		numShapes = 0;

		try
		{
			while (true)
			{
				shapes[numShapes] = (MyShape)input.readObject();
				numShapes++;
			}
		}
		catch (EOFException endOfFileException)
		{
			return;

		}
		catch (ClassNotFoundException classNotFoundException)
		{
			System.err.println("unable to create object");

		}
		catch (IOException ioException)
		{
			System.err.println("error during read from file");
		}

	}
thanks!

}
mariade è offline   Rispondi citando il messaggio o parte di esso
Old 06-05-2007, 21:05   #23
MEMon
Senior Member
 
Iscritto dal: Dec 2002
Messaggi: 3359
No tranquilla il problema l'ho già capito, è solo che hai usato un metodo "strano" per fare quello che vuoi fare.

Comunque, ad esempio, prova a commentare
Codice:
     //    else{
                //numShapes--;
                x[numCount]=event.getX();
                y[numCount]=event.getY();
                System.out.println("---->"+numCount+"   "+numPoints);
                createShape(shapesComboBox.getSelectedIndex());
                repaint();
                numCount=0;
             }
numShapes--;
MEMon è offline   Rispondi citando il messaggio o parte di esso
Old 06-05-2007, 21:10   #24
mariade
Senior Member
 
L'Avatar di mariade
 
Iscritto dal: Jun 2005
Città: Swords, Dublino
Messaggi: 642
Quote:
Originariamente inviato da MEMon Guarda i messaggi
No tranquilla il problema l'ho già capito, è solo che hai usato un metodo "strano" per fare quello che vuoi fare.

Comunque, ad esempio, prova a commentare
Codice:
     //    else{
                //numShapes--;
                x[numCount]=event.getX();
                y[numCount]=event.getY();
                System.out.println("---->"+numCount+"   "+numPoints);
                createShape(shapesComboBox.getSelectedIndex());
                repaint();
                numCount=0;
             }
numShapes--;
scusami devo commentare solo quelle due linee di codice che hai postato tu?
mariade è offline   Rispondi citando il messaggio o parte di esso
Old 06-05-2007, 21:13   #25
MEMon
Senior Member
 
Iscritto dal: Dec 2002
Messaggi: 3359
No solo numShapes--;
MEMon è offline   Rispondi citando il messaggio o parte di esso
Old 06-05-2007, 21:15   #26
mariade
Senior Member
 
L'Avatar di mariade
 
Iscritto dal: Jun 2005
Città: Swords, Dublino
Messaggi: 642
Quote:
Originariamente inviato da MEMon Guarda i messaggi
No solo numShapes--;
yessssssssssssss!!!

grazie ancora, ti avro' stancato oggi!
mariade è offline   Rispondi citando il messaggio o parte di esso
Old 06-05-2007, 21:16   #27
MEMon
Senior Member
 
Iscritto dal: Dec 2002
Messaggi: 3359
No ma spe, non funziona ancora, le altre figure non vanno
MEMon è offline   Rispondi citando il messaggio o parte di esso
Old 06-05-2007, 21:23   #28
MEMon
Senior Member
 
Iscritto dal: Dec 2002
Messaggi: 3359
Ecco qui
Codice:
public void mouseReleased (MouseEvent event) {			

XYValues[2] = event.getX();			
XYValues[3] = event.getY(); 
                
if(shapesComboBox.getSelectedIndex()!=7&&shapesComboBox.getSelectedIndex()!=8&&shapesComboBox.getSelectedIndex()!=9) createShape(shapesComboBox.getSelectedIndex());
Oltre a commentare il pezzo di prima fai questo cambiamento.
MEMon è offline   Rispondi citando il messaggio o parte di esso
Old 06-05-2007, 21:27   #29
mariade
Senior Member
 
L'Avatar di mariade
 
Iscritto dal: Jun 2005
Città: Swords, Dublino
Messaggi: 642
Quote:
Originariamente inviato da MEMon Guarda i messaggi
Ecco qui
Codice:
public void mouseReleased (MouseEvent event) {			

XYValues[2] = event.getX();			
XYValues[3] = event.getY(); 
                
if(shapesComboBox.getSelectedIndex()!=7&&shapesComboBox.getSelectedIndex()!=8&&shapesComboBox.getSelectedIndex()!=9) createShape(shapesComboBox.getSelectedIndex());
Oltre a commentare il pezzo di prima fai questo cambiamento.
A me pareva di si', cmq ora vedo come funziona adesso con le tue correzioni. Grazie!
mariade è offline   Rispondi citando il messaggio o parte di esso
Old 06-05-2007, 21:42   #30
mariade
Senior Member
 
L'Avatar di mariade
 
Iscritto dal: Jun 2005
Città: Swords, Dublino
Messaggi: 642
Funzionava anche prima come adesso, cmq grazie tante!
mariade è offline   Rispondi citando il messaggio o parte di esso
 Rispondi


iPhone 17 Pro: più di uno smartphone. È uno studio di produzione in formato tascabile iPhone 17 Pro: più di uno smartphone. &Eg...
Intel Panther Lake: i processori per i notebook del 2026 Intel Panther Lake: i processori per i notebook ...
Intel Xeon 6+: è tempo di Clearwater Forest Intel Xeon 6+: è tempo di Clearwater Fore...
4K a 160Hz o Full HD a 320Hz? Titan Army P2712V, a un prezzo molto basso 4K a 160Hz o Full HD a 320Hz? Titan Army P2712V,...
Recensione Google Pixel Watch 4: basta sollevarlo e si ha Gemini sempre al polso Recensione Google Pixel Watch 4: basta sollevarl...
Le sonde spaziali ESA ExoMars e Mars Exp...
Roscosmos: static fire per i propulsori ...
Alcune partite NBA saranno trasmesse in ...
Intel Core 13000 e 14000 aumentano uffic...
Gemini sta per arrivare in Google Maps: ...
2 minuti per vedere le 27 offerte imperd...
Ray-Ban Meta Display: tecnologia sorpren...
Un mini PC a prezzo stracciato, non cerc...
Al via i coupon nascosti di ottobre: qua...
Ferrari Elettrica si aggiorna solo in of...
Doppio sconto sugli smartphone top Xiaom...
Samsung è sempre più prota...
ChatGPT ha pregiudizi politici? Ecco cos...
Un solo iPhone rubato ha portato alla sc...
Xiaomi 17 Ultra sta arrivando: ecco come...
Chromium
GPU-Z
OCCT
LibreOffice Portable
Opera One Portable
Opera One 106
CCleaner Portable
CCleaner Standard
Cpu-Z
Driver NVIDIA GeForce 546.65 WHQL
SmartFTP
Trillian
Google Chrome Portable
Google Chrome 120
VirtualBox
Tutti gli articoli Tutte le news Tutti i download

Strumenti

Regole
Non Puoi aprire nuove discussioni
Non Puoi rispondere ai messaggi
Non Puoi allegare file
Non Puoi modificare i tuoi messaggi

Il codice vB è On
Le Faccine sono On
Il codice [IMG] è On
Il codice HTML è Off
Vai al Forum


Tutti gli orari sono GMT +1. Ora sono le: 22:08.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Served by www3v