Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



What is the use of Rectangle class in java?

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 06-03-2010
Member
 
Join Date: Jan 2010
Posts: 99
What is the use of Rectangle class in java?
  

Hi friends,

I just completed core java programming and started advanced java programming. For me the advanced java seems very tough than core java. In which I am not getting the use of Rectangle class. If you posses good knowledge about the Rectangle class of java programming, then please let me know that. I would greatly appreciate you help over Rectangle class.

Reply With Quote
  #2  
Old 06-03-2010
Member
 
Join Date: Apr 2008
Posts: 1,947
Re: What is the use of Rectangle class in java?

A Rectangle class specifies an area in a coordinate space that is enclosed by the Rectangle object's top-left point (x, y) in the coordinate space, its width, and its height.A Rectangle object's width and height are public fields. The constructors that create a Rectangle, and the methods that can modify one, do not prevent setting a negative value for width or height. A Rectangle whose width or height is negative is considered empty.
Reply With Quote
  #3  
Old 06-03-2010
Member
 
Join Date: May 2008
Posts: 2,007
Re: What is the use of Rectangle class in java?

Following java code will depict you about the use of Rectangle class:
Code:
java.awt.Rectangle;
import javax.swing.JComponent;

class RectDemo 
{
  public void paint(Graphics g)
 {
    g.drawRect (20, 20, 200, 200);  
  }
}
public class DrawRect 
{
  public static void main(String[] agh) 
{
    JFrame window1 = new JFrame();
    window1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    window1.setBounds(40, 40, 300, 300);
    window1.getContentPane().add(new RectDemo());
    window1.setVisible(true);
  }
}
Reply With Quote
  #4  
Old 06-03-2010
Member
 
Join Date: Apr 2008
Posts: 2,000
Re: What is the use of Rectangle class in java?

Hello friend,

Before using Rectangle class, you should be aware about below it's constructors:
  • Rectangle(Rectangle rct)
  • Rectangle(Point pt, Dimension dm)
  • Rectangle(Point pt)
  • Rectangle(int xn, int yn, int width1, int height1)
  • Rectangle(int width1, int height1)
Reply With Quote
  #5  
Old 06-03-2010
Member
 
Join Date: May 2008
Posts: 2,291
Re: What is the use of Rectangle class in java?

Hi,

I suggest you to study following example of Rectangle class:
Code:
import java.awt.Graphics2D;
import java.awt.Rectangle;

public class RectangleTP extends JApplet {
  final static BasicStroke stroke1 = new BasicStroke(2.0f);
  public void init() {
    setBackground(Color.blue);
    setForeground(Color.blue);
  }
  public void paint(Graphics g) {
    Graphics2D g02 = (Graphics2D) g;
    g02.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
        RenderingHints.VALUE_ANTIALIAS_ON);
    g02.setPaint(Color.gray);
    int x = 5;
    int y = 7;
    g02.setStroke(stroke);
    g02.draw(new Rectangle2D.Double(x, y, 200, 200));
    g02.drawString("Rectangle2D", x, 250);
  }
  public static void main(String sko[]) {
    JFrame f1 = new JFrame("");
    f1.addWindowListener(new WindowAdapter() {
      public void windowClosing(WindowEvent e) {
        System.exit(0);
      }    }
    JApplet applet = new RectangleDemo2D();
    f1.getContentPane().add("Center", applet);
    f1.setSize(new Dimension(400, 300));
    f1.show();
  }
}
Reply With Quote
  #6  
Old 06-03-2010
Member
 
Join Date: Oct 2005
Posts: 2,389
Re: What is the use of Rectangle class in java?

Please go through following various methods of Rectangle class of java:
  1. translate(int ak, int bk)
  2. setSize(int wd, int ht)
  3. setRect(double ak, double bk, double wd, double ht)
  4. setLocation(int ak, int bk)
  5. resize(int wd, int ht
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "What is the use of Rectangle class in java?"
Thread Thread Starter Forum Replies Last Post
Converting java class to java bean class Ucchal Software Development 6 09-08-2010 10:24 AM
How to use Event class of java? Protectors Software Development 5 25-02-2010 07:15 AM
SwingUtilities class of java Owen Fernandes Software Development 5 12-02-2010 07:23 AM
What is wrapper class in java? Owen Fernandes Software Development 5 30-01-2010 07:40 AM
Java Programming Language Basics: Reflection Basics and Class Class mayuri_gunjan Guides & Tutorials 6 29-08-2005 12:04 AM


All times are GMT +5.5. The time now is 04:30 AM.