import
javax.swing.*;
public class Gradiante
extends JFrame {
public Gradiante(){
super("Gradiante");
this.setLayout(new BoxLayout(this.getContentPane(),BoxLayout.Y_AXIS));
this.setSize(250,
250);
this.setVisible(true);
this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
}
public static void main(String[]
arg){
new Gradiante();
}
public void
paint(Graphics g) {
Graphics2D g2 = (Graphics2D) g;
GradientPaint gp = new
GradientPaint(50,25,Color.blue,50,100,Color.yellow);//gradiante
de color azul y amarillo
g2.setPaint(gp);
Rectangle2D r1 = new
Rectangle2D.Float(75, 50, 100, 50); //rectangulo con gradiante
g2.fill(r1);
Rectangle2D r2 = new
Rectangle2D.Float(75, 110, 100, 50); //rectangulo borde rojo
g2.setColor(Color.RED);
g2.draw(r2);
Rectangle2D r3 = new
Rectangle2D.Float(75, 110, 100, 50); //rectangulo relleno de
color rosa
g2.setColor(Color.PINK);
g2.fillRect(75, 180, 100, 50);
}
}
|
Y el resultado....
No hay comentarios:
Publicar un comentario