Results 1 to 5 of 5
  1. #1
    shkelqa is offline Member
    Join Date
    May 2008
    Posts
    3
    Rep Power
    0

    Default solution for my project

    I need to help me in my project:
    :):):)

    Write a 3D Bézier surface editor. Display the control points of the surface as square dots. Allow the user to select and move a control point with mouse operations and update the surface accordingly.

    :):):)

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Hi shelqa,

    Welcome to our community. :)

    Before post again here please read FAQ page of our community. And at the same time, please keep in mind that no one here in our community wants just give a code. What we do is, giving helping hand to anyone who stuck with anything related to Java.

  3. #3
    shkelqa is offline Member
    Join Date
    May 2008
    Posts
    3
    Rep Power
    0

    Default repost

    Quote Originally Posted by Eranga View Post
    Hi shelqa,

    Welcome to our community. :)

    Before post again here please read FAQ page of our community. And at the same time, please keep in mind that no one here in our community wants just give a code. What we do is, giving helping hand to anyone who stuck with anything related to Java.



    This is code:

    import java.awt.*;
    import java.awt.geom.*;
    import java.awt.event.*;
    import java.util.*;
    import javax.swing.*;
    public class BSpline extends JApplet {
    public static void main(String s[]) {
    JFrame frame = new JFrame();
    frame.setTitle("B-Spline");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);
    JApplet applet = new BSpline();
    applet.init();
    frame.getContentPane().add(applet);
    frame.pack();
    frame.setVisible(true);
    }
    public void init() {
    JPanel panel = new BSplinePanel();
    getContentPane().add(panel);
    }
    }

    class BSplinePanel extends JPanel
    implements MouseListener, MouseMotionListener {
    Vector points = null;
    boolean completed = true;
    public BSplinePanel() {
    setPreferredSize(new Dimension(640, 480));
    setBackground(Color.white);
    addMouseListener(this);
    addMouseMotionListener(this);
    points = new Vector();
    }
    public void paintComponent(Graphics g) {
    super.paintComponent(g);
    Graphics2D g2 = (Graphics2D)g;
    Point p0 = null;
    Point p1 = null;
    Point p2 = null;
    Point p3 = null;
    float x1, y1, x2, y2, x3, y3, x4, y4;
    Iterator it = points.iterator();
    if (it.hasNext()) {
    p1 = (Point)(it.next());
    }
    while (it.hasNext()) {
    p2 = (Point)(it.next());
    g2.drawLine(p1.x, p1.y, p2.x, p2.y);
    p1 = p2;
    }

    GeneralPath spline = new GeneralPath();
    int n = points.size();
    if (n == 0) return;
    p1 = (Point)points.get(0);
    spline.moveTo(p1.x, p1.y);
    g2.drawRect(p1.x-3, p1.y-3, 6, 6);
    p1 = (Point)points.get(1);
    p2 = (Point)points.get(2);
    p3 = (Point)points.get(3);
    x1 = p1.x;
    y1 = p1.y;
    x2 = (p1.x + p2.x)/2.0f;
    y2 = (p1.y + p2.y)/2.0f;
    x4 = (2.0f*p2.x+p3.x)/3.0f;
    y4 = (2.0f*p2.y+p3.y)/3.0f;
    x3 = (x2+x4)/2.0f;
    y3 = (y2+y4)/2.0f;
    spline.curveTo(x1, y1, x2, y2, x3, y3);
    g2.drawRect((int)x1-3, (int)y1-3, 6, 6);
    g2.drawRect((int)x2-3, (int)y2-3, 6, 6);
    g2.drawRect((int)x3-3, (int)y3-3, 6, 6);
    for (int i = 2; i < n - 4; i++) {
    p1 = p2;
    p2 = p3;
    p3 = (Point)points.get(i+2);
    x1 = x4;
    y1 = y4;
    x2 = (p1.x+2.0f*p2.x)/3.0f;
    y2 = (p1.y+2.0f*p2.y)/3.0f;
    x4 = (2.0f*p2.x+p3.x)/3.0f;
    y4 = (2.0f*p2.y+p3.y)/3.0f;
    x3 = (x2+x4)/2.0f;
    y3 = (y2+y4)/2.0f;
    spline.curveTo(x1,y1,x2,y2,x3,y3);
    g2.drawRect((int)x1-3, (int)y1-3, 6, 6);
    g2.drawRect((int)x2-3, (int)y2-3, 6, 6);
    g2.drawRect((int)x3-3, (int)y3-3, 6, 6);
    }
    p1 = p2;
    p2 = p3;
    p3 = (Point)points.get(n-2);
    x1 = x4;
    y1 = y4;
    x2 = (p1.x+2.0f*p2.x)/3.0f;
    y2 = (p1.y+2.0f*p2.y)/3.0f;
    x4 = (p2.x+p3.x)/2.0f;
    y4 = (p2.y+p3.y)/2.0f;
    x3 = (x2+x4)/2.0f;
    y3 = (y2+y4)/2.0f;
    spline.curveTo(x1,y1,x2,y2,x3,y3);
    g2.drawRect((int)x1-3, (int)y1-3, 6, 6);
    g2.drawRect((int)x2-3, (int)y2-3, 6, 6);
    g2.drawRect((int)x3-3, (int)y3-3, 6, 6);
    p2 = p3;
    p3 = (Point)points.get(n-1);
    x1 = x4;
    y1 = y4;
    x2 = p2.x;
    y2 = p2.y;
    x3 = p3.x;
    y3 = p3.y;
    spline.curveTo(x1,y1,x2,y2,x3,y3);
    g2.drawRect((int)x1-3, (int)y1-3, 6, 6);
    g2.drawRect((int)x2-3, (int)y2-3, 6, 6);
    g2.drawRect((int)x3-3, (int)y3-3, 6, 6);
    g2.draw(spline);
    }
    public void mouseClicked(MouseEvent ev) {
    }
    public void mouseEntered(MouseEvent ev) {
    }
    public void mouseExited(MouseEvent ev) {
    }
    public void mousePressed(MouseEvent ev) {
    Graphics g = getGraphics();
    if (completed) {
    points.clear();
    completed = false;
    }
    if (ev.getClickCount() == 1) {
    Point p =ev.getPoint();
    points.add(p);
    g.fillOval(p.x-3, p.y-3, 6, 6);
    }
    }
    public void mouseReleased(MouseEvent ev) {
    if (ev.getClickCount() > 1) {
    completed = true;
    repaint();
    }
    }
    public void mouseMoved(MouseEvent ev) {
    }
    public void mouseDragged(MouseEvent ev) {
    }
    }

    and I need to modify to write my project
    By SHKELQA

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  5. #5
    shkelqa is offline Member
    Join Date
    May 2008
    Posts
    3
    Rep Power
    0

    Default From Shkelqim about Bezier

    I upload four codes with java that you can help me in my project
    My project is:
    Write a 3D Bézier surface editor. Display the control points of the surface as square dots. Allow the user to select and move a control point with mouse operations and update the surface accordingly
    and before need to modify codes in attach at complete
    Attached Files Attached Files
    Last edited by shkelqa; 05-28-2008 at 10:44 PM.

Similar Threads

  1. Help Finding Compiler error solution please
    By jamesr2b in forum New To Java
    Replies: 5
    Last Post: 04-30-2009, 06:07 AM
  2. solution for my project
    By themburu in forum Java Applets
    Replies: 4
    Last Post: 05-21-2008, 01:03 PM
  3. Please need solution
    By prithvi in forum New To Java
    Replies: 4
    Last Post: 04-22-2008, 01:27 PM
  4. Simple serverless chat solution
    By goodjonx in forum Networking
    Replies: 3
    Last Post: 01-07-2008, 03:25 PM
  5. Replies: 1
    Last Post: 06-15-2007, 04:42 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •