Re: Shape interface of java
The Shape interface provides definitions for objects that represent some form of geometric shape. The Shape is described by a PathIterator object, which can express the outline of the Shape as well as a rule for determining how the outline divides the 2D plane into interior and exterior points. Each Shape object provides callbacks to get the bounding box of the geometry, determine whether points or rectangles lie partly or entirely within the interior of the Shape, and retrieve a PathIterator object that describes the trajectory path of the Shape outline.
Re: Shape interface of java
Hi,
Please go through below given some methods of Shape interface of java:
- intersects(Rectangle2D rt)
- intersects(double xg, double yg, double wg, double hg)
- getPathIterator(AffineTransform ats, double fs)
- getPathIterator(AffineTransform ats)
- contains(Rectangle2D rt)
Re: Shape interface of java
As per the name suggest the 'Shape interface' is related to the geometric shape. This interface related to the geometrical points which are completely inside the shape boundary. This Shape interface comprises various methods to handle the various shapes. The output shape is depends upon the inputted parameters of the Shape interface methods. It implements various interfaces such as 'RectangularShape'.
Re: Shape interface of java
Following example of java will demonstrates you the working of Shape interface:
Code:
import javax.swing.JFrame;
import javax.swing.JPanel;
public class CombiningShapesDM implements Shape {
private Shape mShapeOne, mShapeTwo;
private JComboBox mOptions;
public CombiningShapes() {
mShapeOne = new Ellipse2D.Double(50, 30, 80, 80);
setBackground(Color.white);
setLayout(new BorderLayout());
JPanel cltrT = new JPanel();
mOptions = new JComboBox(new String[] { "outline", "add",
"intersection", "subtract", "exclusive or" });
mOptions.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent ie) {
repaint();
} }
cltrT.add(mOptions);
add(cltrT, BorderLayout.SOUTH);
}
public void paintComponent(Graphics g) {
Graphics2D g2 = (Graphics2D) g;
String option = (String) mOptions.getSelectedItem();
if (option.equals("outline")) {
g2.draw(mShapeOne);
return;
}
Area areaOne1 = new Area(mShapeOne);
if (option.equals("add"))
areaOne.add(areaTwo);
else if (option.equals("intersection"))
areaOne.intersect(areaTwo1);
g02.setPaint(Color.black);
g02.draw(areaOne1);
}
public static void main(String[] airgs) {
JFrame f01 = new JFrame();
f01.add(new CombiningShapes());
f01.setSize(230, 220);
}
}