Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package figuras;
- import java.awt.*;
- import java.awt.geom.*;
- import javax.swing.JFrame;
- import javax.swing.JPanel;
- /**
- *
- * @author Rafa
- */
- public class Figuras2D extends JPanel{
- public void paintComponent(Graphics g){
- super.paintComponent(g);
- Graphics2D g2d = (Graphics2D) g; //convierte g en graphics2D
- //dibuja rectรกngulo en 2D
- //g2d.setPaint(Color.cyan); //Color del rectangulo
- g2d.setStroke(new BasicStroke(20.0f)); //Establece el ancho de la linea
- g2d.setPaint(new GradientPaint(80, 100, Color.CYAN, 8, 20, Color.BLACK, true)); //gradiente
- g2d.draw(new Rectangle2D.Double(45, 45, 399, 378));
- //dibuja un elipse en 2D azul
- g2d.setPaint(new GradientPaint(80, 10, Color.DARK_GRAY, 8, 2, Color.pink, true));
- g2d.fill(new Ellipse2D.Double(58, 58, 370, 350));
- //dibuja un circulo con relleno gradiente grande
- g2d.setPaint(new GradientPaint(80, 100, Color.GREEN, 8, 200, Color.black, true));
- g2d.fill(new Ellipse2D.Double(128, 98, 220, 270));
- //dibuja linea
- g2d.setStroke(new BasicStroke(30.0f)); //grosor de la linea blanca
- g2d.setPaint(new GradientPaint(80, 100, Color.orange, 8, 20, Color.BLACK, true)); //gradiente
- g2d.draw(new Line2D.Double(55, 55, 350, 350));
- //Dibuja arco negro
- g2d.setPaint(Color.BLACK);
- g2d.setStroke(new BasicStroke(15.0f)); //grosor del arco negro
- g2d.draw(new CubicCurve2D.Double(50, 60, 100, 800, 500, 50, 300, 200));
- }
- public static void main(String[] args) {
- //crea el frame para el objeto Figuras
- JFrame frame = new JFrame("Figuras 2D");
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- //crea objeto Figuras
- Figuras2D figuras2D = new Figuras2D();
- frame.add(figuras2D);
- frame.setSize(500, 500);
- frame.setVisible(true);
- frame.setLocationRelativeTo(null); //centra el panel
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement