Draw a line
void drawLine(int startX, int startY, int endX, int endY)
drawLine( ) displays a line in the current drawing color that begins at startX,startY and ends at endX,endY
import java.awt.*;
public class DrawLine extends Frame {
public void paint(Graphics g) {
g.drawLine(0, 0, 100, 100);
g.drawLine(0, 100, 100, 0);
g.drawLine(40, 25, 250, 180);
g.drawLine(75, 90, 400, 400);
g.drawLine(20, 150, 400, 40);
g.drawLine(5, 290, 80, 19); }
public static void main(String args[]) {
DrawLine frame = new DrawLine();
frame.setSize(400, 400);
frame.setVisible(true); }}
Here is an example of Java Program to Draw a rectangle in using AWT abstract Windows Toolkit and it's components
if you want to draw a rectangle in output of java programming language use this java program
Draw a Rectangle
import java.awt.*;
public class DrawRectangle extends Frame {
public void paint(Graphics g) {
g.drawRect(10, 10, 60, 50);
g.fillRect(100, 10, 60, 50);
g.drawRoundRect(190, 10, 60, 50, 15, 15);
g.fillRoundRect(70, 90, 140, 100, 30, 40);
}
public static void main(String args[])
{
DrawRectangle frame = new DrawRectangle();
frame.setSize(400, 400);
frame.setVisible(true);
}
}
0 Comments