Java AWT BasicStroke class

Description

Java AWT BasicStroke class


import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.Rectangle2D;

import javax.swing.JFrame;
import javax.swing.JPanel;

public class Main extends JPanel {
  @Override//w w  w. j a v  a  2  s .  c  o m
  public void paintComponent(Graphics g) {
    super.paintComponent(g);
    Graphics2D g2d = (Graphics2D) g; // cast g to Graphics2D

    // draw 2D rectangle in red
    g2d.setPaint(Color.RED);
    g2d.setStroke(new BasicStroke(10.0f));
    g2d.draw(new Rectangle2D.Double(80, 30, 65, 100));
  }
  public static void main(String[] args) {
    JFrame frame = new JFrame("Drawing 2D shapes");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Main Main = new Main();
    frame.add(Main);
    frame.setSize(425, 200);
    frame.setVisible(true);
  }
}



PreviousNext

Related