|
| ||||||||||
| Tags: class, java, java class, java classes, java rectangle class, rectangle, rectangle class |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| |||
| |||
| What is the use of Rectangle class in java?
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. |
|
#2
| ||||
| ||||
| 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. |
|
#3
| |||
| |||
| 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);
}
} |
|
#4
| ||||
| ||||
| 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:
|
|
#5
| ||||
| ||||
| 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();
}
} |
|
#6
| ||||
| ||||
| Re: What is the use of Rectangle class in java?
Please go through following various methods of Rectangle class of java:
|
![]() |
|
| Thread Tools | Search this Thread |
| |
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 |