class DrawingPanel extends JPanel{
//global variables for this class
float[] dash1 = { 10f, 10f}; //Even # parameters are 10pixels dash, 10 pixels space
//1 parameter: 10pixels line, 10 pixels space.
//3 parameters: the lines follow this pattern, then the spaces follow this pattern too
//(float width, int cap, int join, float miterlimit, float[] dash, float dash_phase)
BasicStroke bs1 = new BasicStroke(3, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND, 1.0f, dash1, 0);
DrawingPanel(){
this.setBackground(new Color(0,0,0,20));
this.setPreferredSize(new Dimension(panW, panH)); //How to specify the size of a JPanel (see notes)
}
@Override
public void paintComponent(Graphics g) {
//paint the background
super.paintComponent(g);
//get Graphics2D object for more advanced graphics
Graphics2D g2 = (Graphics2D) g;
//turn on antialiasing
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
//make solid lines 3 pixels wide
g2.setStroke(new BasicStroke(3));
g2.drawLine(20, 40, 250, 40);
g2.setStroke(bs1);
g2.drawLine(20, 80, 250, 80);