Java - ayuda para este programa

 
Vista:

ayuda para este programa

Publicado por andres (1 intervención) el 26/07/2010 05:48:44
necesito cambiar el vector por una pila
agregar un boton para que al final lo imprima
cuando se mande imprimir y en algun espacio no tenga nada imprima guiones
su boton de borrar elemento

import java.applet.Applet;
import java.util.*;
import java.awt.*;

public class SimpleDraw_P extends Applet {
Vector drawnShapes;
Choice shapeChoice;
Choice colorChoice;

/** se crea la interfaz grafica del applet. */
public void init() {
drawnShapes = new Vector();


shapeChoice = new Choice();//la etiqueta que permite seleccionar la figura
shapeChoice.addItem("Circle");//circulo
shapeChoice.addItem("Square");//cuadrado
add(shapeChoice);

colorChoice = new Choice();//etiqueta de colores
colorChoice.addItem("Red");//rojo
colorChoice.addItem("Green");//verde
colorChoice.addItem("Blue");//azul
add(colorChoice);
}

/** Draw all the shapes. */
public void paint(Graphics g) {
Shape s;
int numShapes;

numShapes = drawnShapes.size();
for (int i = 0; i < numShapes; i++) {

s = (Shape)drawnShapes.elementAt(i);

// When the shape draws, circles and squares each invoke their own
// draw method, depending on which shape this is.
s.draw(g);
}
}

/** Create a new shape. */
public boolean mouseUp(Event e, int x, int y) {

Shape s; // This shape will be either a circle or a square.

String shapeString = shapeChoice.getSelectedItem();
String colorString = colorChoice.getSelectedItem();

if (shapeString.equals("Circle"))
s = new Circle();
else
s = new Square();

if (colorString.equals("Red"))
s.color = Color.red;
else if (colorString.equals("Green"))
s.color = Color.green;
else
s.color = Color.blue;

s.x = x;
s.y = y;

drawnShapes.addElement(s);

repaint();

return true;
}

}

/** Shapes provide common characteristics for the circle and square. */
abstract class Shape {
int n = (int) (Math.random()*100);
int shapeRadius = n;

Color color;
int x;
int y;

abstract void draw(Graphics g);
}

/** Draws and maintains circle information. */
class Circle extends Shape {
void draw(Graphics g) {
g.setColor(this.color);
g.fillOval(this.x - shapeRadius, this.y - shapeRadius, shapeRadius * 2, shapeRadius * 2);
}
}

/** Draws and maintains square information. */
class Square extends Shape{
void draw(Graphics g) {
g.setColor(this.color);
g.fillRect(this.x - shapeRadius, this.y - shapeRadius, shapeRadius * 2, shapeRadius * 2);
}
}
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder