How To Draw A Horizontal Line In Java Applet
The simplest shape that you tin can draw with Graphics class is a line. The drawLine() method of the Graphics class is used to describe a line with current color betwixt 2 points. This method takes the following grade
void drawLine(int x1, int y1, int x2, int y2)
The DrawLine method tin can exist used for cartoon straight lines between two points (x1, y1) and (x2, y2) data. Following case DrawLine shows how to Draw a Line on Applet window using drawLine method of Graphics class.
To draw a point at (ten, y) nosotros could write: g.drawLine (x, y, x, y); The point thus drawn using the current colour of the graphics context, which can exist changed using the setColor method.
For case, the statement g.drawLine (20, 100, xc, 100) volition draw a straight line from the coordinate point (twenty, 100) to (90, 100) as shown in Figure
import coffee.applet.Applet;
import java.awt.*;
import java.awt.event.*;
public course DrawLine extends Applet
{
public static void main(Cord[] args)
{
Frame drawLineApplet = new Frame("Describe Line in Applet Window Instance");
drawLineApplet.setSize(350, 250);
Applet DrawLine = new DrawLine();
drawLineApplet.add(DrawLine);
drawLineApplet.setVisible(truthful);
drawLineApplet.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent eastward) {Arrangement.leave(0); }
});
}
public void paint(Graphics g)
{
// Now nosotros tell g to alter the font
g.setFont(new Font("Arial",Font.Assuming,14));
//Syntax: drawString(String str, int xBaselineLeft, int yBaselineLeft);
g.drawString("This is Depict Line Example", 100, lxx);
// draws a Line
1000.setColor(Color.blue); // At present we tell g to change the colour
//Syntax For:- drawLine(int x1, int y1, int x2, int y2);
k.drawLine(ninety, 135, ninety, 180);
thou.setColor(Color.green); // At present we tell one thousand to alter the color
g.drawLine(0, 0, 100, 100);
}
}
Source: https://ecomputernotes.com/java/awt-and-applets/draw-line-in-applet-window
Posted by: leehure1986.blogspot.com

0 Response to "How To Draw A Horizontal Line In Java Applet"
Post a Comment