filename: Line.java
import java.awt.BasicStroke;
import java.awt.Graphics;
import java.awt.Graphics2D;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
class Surface extends JPanel { //Class Surface
private void doDrawing(Graphics g) {
Graphics2D g2a = (Graphics2D) g; //Line g2a
Graphics2D g2d = (Graphics2D) g; //Line g2d
float[] dash1 = {2f, 0f, 2f}; //Line 2
float[] dash2 = {1f, 1f, 1f}; //Line 3
float[] dash3 = {4f, 0f, 10f}; //Line 4
float[] dash4 = {4f, 4f, 1f}; //Line 5
g2d.drawLine(20, 40, 250, 40);
g2a.setStroke(new BasicStroke(3));
g2a.drawLine(20,240,250,240);
BasicStroke bs1 = new BasicStroke(1, BasicStroke.CAP_BUTT,
BasicStroke.JOIN_ROUND, 10.0f, dash1, 4f);
BasicStroke bs2 = new BasicStroke(1, BasicStroke.CAP_BUTT,
BasicStroke.JOIN_ROUND, 1.0f, dash2, 2f);
BasicStroke bs3 = new BasicStroke(1, BasicStroke.CAP_BUTT,
BasicStroke.JOIN_ROUND, 1.0f, dash3, 2f);
BasicStroke bs4 = new BasicStroke(1, BasicStroke.CAP_BUTT,
BasicStroke.JOIN_ROUND, 1.0f, dash4, 2f);
g2d.setStroke(bs1);
g2d.drawLine(20, 80,250, 80);
g2d.setStroke(bs2);
g2d.drawLine(20, 120, 250, 120);
g2d.setStroke(bs3);
g2d.drawLine(20, 160, 250, 160);
g2d.setStroke(bs4);
g2d.drawLine(20, 200, 250, 200);
}
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
doDrawing(g);
}
}
public class line extends JFrame { //Class Line
public line() {
initUI();
}
private void initUI() {
setTitle("Line Styles");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
add(new Surface());
setSize(280, 280);
setLocationRelativeTo(null);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
line bs = new line();
bs.setVisible(true);
}
});
}
import java.awt.BasicStroke;
import java.awt.Graphics;
import java.awt.Graphics2D;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
class Surface extends JPanel { //Class Surface
private void doDrawing(Graphics g) {
Graphics2D g2a = (Graphics2D) g; //Line g2a
Graphics2D g2d = (Graphics2D) g; //Line g2d
float[] dash1 = {2f, 0f, 2f}; //Line 2
float[] dash2 = {1f, 1f, 1f}; //Line 3
float[] dash3 = {4f, 0f, 10f}; //Line 4
float[] dash4 = {4f, 4f, 1f}; //Line 5
g2d.drawLine(20, 40, 250, 40);
g2a.setStroke(new BasicStroke(3));
g2a.drawLine(20,240,250,240);
BasicStroke bs1 = new BasicStroke(1, BasicStroke.CAP_BUTT,
BasicStroke.JOIN_ROUND, 10.0f, dash1, 4f);
BasicStroke bs2 = new BasicStroke(1, BasicStroke.CAP_BUTT,
BasicStroke.JOIN_ROUND, 1.0f, dash2, 2f);
BasicStroke bs3 = new BasicStroke(1, BasicStroke.CAP_BUTT,
BasicStroke.JOIN_ROUND, 1.0f, dash3, 2f);
BasicStroke bs4 = new BasicStroke(1, BasicStroke.CAP_BUTT,
BasicStroke.JOIN_ROUND, 1.0f, dash4, 2f);
g2d.setStroke(bs1);
g2d.drawLine(20, 80,250, 80);
g2d.setStroke(bs2);
g2d.drawLine(20, 120, 250, 120);
g2d.setStroke(bs3);
g2d.drawLine(20, 160, 250, 160);
g2d.setStroke(bs4);
g2d.drawLine(20, 200, 250, 200);
}
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
doDrawing(g);
}
}
public class line extends JFrame { //Class Line
public line() {
initUI();
}
private void initUI() {
setTitle("Line Styles");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
add(new Surface());
setSize(280, 280);
setLocationRelativeTo(null);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
line bs = new line();
bs.setVisible(true);
}
});
}
Output
No comments:
Post a Comment