Grafika

Kody źródłowe z odcinka

package pl.am.swing.ramka8;

import javax.swing.*;
import java.awt.*;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Line2D;

public class FiguryComponent extends JComponent {
    @Override
    protected void paintComponent(Graphics g) {
        Graphics2D graphics2D = (Graphics2D) g;

        graphics2D.drawString("Hello world", 0, 20);


        Point point1 = new Point(100, 100);
        Point point2 = new Point(300, 300);

        Dimension dimension = new Dimension(200, 200);

        graphics2D.setPaint(Color.PINK);
        Rectangle rectangle = new Rectangle(point1, dimension);
        graphics2D.fill(rectangle);
        graphics2D.draw(rectangle);

        graphics2D.setPaint(new Color(189, 63, 21));

        Ellipse2D ellipse2D = new Ellipse2D.Float();
        ellipse2D.setFrame(rectangle);
        graphics2D.fill(ellipse2D);

        graphics2D.setPaint(Color.BLACK);
        graphics2D.draw(ellipse2D);


        Line2D line2D = new Line2D.Float(point1, point2);
        graphics2D.setPaint(Color.YELLOW);
        graphics2D.draw(line2D);

        Image image = new ImageIcon("logo.png").getImage();
        graphics2D.drawImage(image, 300, 0, null);
    }
}

Dodaj komentarz

Twój adres e-mail nie zostanie opublikowany. Wymagane pola są oznaczone *