Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
How to create LineDraw In Java 
 

This is a simple java program . In this section, you will learn how to create Line Drawing. This program implements a line Drawing component. A java program explains the stroke line i.e. how to make thick and thin line.

 

How to create LineDraw In Java

                         

Introduction

This is a simple java program . In this section, you will learn how to create Line Drawing. This program  implements a line Drawing component. A java program explains the stroke line i.e. how to make thick and thin line. For this we have used  BasicStroke class. This object is passed to the setStroke() method.

Program Description:

First of all, define a class named, LineDraw in program for creating a java AWT Line Drawing component. This program uses the setStroke() method. The stroke describes the pen and brush. It is used for drawing the line. This controls all drawing line attribute. It is a suitable of all line drawing needs. 

BasicStroke(): This is a constructor component. A BasicStroke object is used for several different-different line drawing attributes. The BasicStroke() objects are immutable, So its can be safely cached and shared.

Here is the code of this Program:

import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;

public class LineDraw extends Frame{
  Line2D line1 = new Line2D.Double(00200200);
  Line2D line2 = new Line2D.Double(7080100200);
  Line2D line3 = new Line2D.Double(100150150,150);
  Stroke drawingStroke = new BasicStroke(2);
   public void paint(Graphics g) {
  Graphics2D graph = (Graphics2D)g;
    graph.setStroke(drawingStroke);
    graph.setPaint(Color.green);
    graph.draw(line1);
    graph.setPaint(Color.red);
    graph.draw(line2);
    graph.setPaint(Color.yellow);
    graph.draw(line3);

  }

  public static void main(String args[]) {
    Frame frame = new LineDraw();
    frame.addWindowListener(new WindowAdapter(){
      public void windowClosing(WindowEvent we){
        System.exit(0);
         }
      });
    frame.setSize(300250);
    frame.setVisible(true);
   }
}

Output of this program:

Download this program. 

                         

» View all related tutorials
Related Tags: c class make method sed boolean value ole set oo frame if boo to ram bool argument e il not

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.