Line dashes style 2 : Line « 2D Graphics GUI « Java






Line dashes style 2

    

import java.awt.BasicStroke;
import java.awt.Graphics;
import java.awt.Graphics2D;

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

public class LinesDashes2 extends JPanel {

  public void paintComponent(Graphics g) {
    super.paintComponent(g);

    Graphics2D g2d = (Graphics2D) g;
    g2d.drawLine(20, 40, 250, 40);
    float[] dash2 = { 1f, 1f, 1f };

    BasicStroke bs2 = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND, 1.0f, dash2,2f);
    g2d.setStroke(bs2);
    g2d.drawLine(20, 20, 250, 20);
  }

  public static void main(String[] args) {
    LinesDashes2 lines = new LinesDashes2();
    JFrame frame = new JFrame("Lines");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.add(lines);
    frame.setSize(280, 270);
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);

  }
}

   
    
    
    
  








Related examples in the same category

1.Drawing a Line using Java 2D Graphics API
2.Line StylesLine Styles
3.Dash style line
4.Lines Dashes style 3
5.Line Dash Style 4
6.Program to draw gridsProgram to draw grids
7.Xsplinefun displays colorful moving splines in a window
8.Draw a point: use a drawLine() method
9.A line is drawn using two points
10.Line-graph drawable
11.Draw Dashed
12.Draw Optimized Line
13.Draw with Line2D.Double and Ellipse2D.Double