Results 1 to 5 of 5

Thread: Shape interface of java

  1. #1
    Join Date
    Jan 2010
    Posts
    42

    Shape interface of java

    Hi All,

    I am new to the programming field of java. In there are some concepts of java which are very complicated to use. The 'Shape interface' is one of them. I have referred lots of advanced java books, but nothing was helpful. If you posses sound knowledge regarding the Shape interface, then please try to share it with me. Your any help over Shape interface would be greatly appreciated.

  2. #2
    Join Date
    Apr 2008
    Posts
    1,948

    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.

  3. #3
    Join Date
    May 2008
    Posts
    2,012

    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)

  4. #4
    Join Date
    Apr 2008
    Posts
    2,005

    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'.

  5. #5
    Join Date
    May 2008
    Posts
    2,297

    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);
      }
      
    }

Similar Threads

  1. what is interface in java
    By Ansari Bros in forum Software Development
    Replies: 4
    Last Post: 10-01-2011, 10:07 AM
  2. SpinnerModel interface of java
    By Gadin in forum Software Development
    Replies: 5
    Last Post: 23-02-2010, 12:56 PM
  3. Action Interface of java
    By Protectors in forum Software Development
    Replies: 5
    Last Post: 23-02-2010, 08:19 AM
  4. ButtonModel interface of java
    By Gokul20 in forum Software Development
    Replies: 5
    Last Post: 22-02-2010, 12:48 PM
  5. Changing the Cursor shape in Java
    By rashmi_ay in forum Software Development
    Replies: 4
    Last Post: 30-11-2009, 10:58 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,669,572,103.95286 seconds with 17 queries