Results 1 to 5 of 5
Thread: solution for my project
- 05-27-2008, 12:31 AM #1
Member
- Join Date
- May 2008
- Posts
- 3
- Rep Power
- 0
- 05-27-2008, 04:48 AM #2
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
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.
- 05-27-2008, 11:25 PM #3
Member
- Join Date
- May 2008
- Posts
- 3
- Rep Power
- 0
repost
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
- 05-28-2008, 03:53 AM #4
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
You mean wants to add you name there?
- 05-28-2008, 10:31 PM #5
Member
- Join Date
- May 2008
- Posts
- 3
- Rep Power
- 0
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 completeLast edited by shkelqa; 05-28-2008 at 10:44 PM.
Similar Threads
-
Help Finding Compiler error solution please
By jamesr2b in forum New To JavaReplies: 5Last Post: 04-30-2009, 06:07 AM -
solution for my project
By themburu in forum Java AppletsReplies: 4Last Post: 05-21-2008, 01:03 PM -
Please need solution
By prithvi in forum New To JavaReplies: 4Last Post: 04-22-2008, 01:27 PM -
Simple serverless chat solution
By goodjonx in forum NetworkingReplies: 3Last Post: 01-07-2008, 03:25 PM -
Friends could u plz give me solution 4 this
By Saritha in forum JDBCReplies: 1Last Post: 06-15-2007, 04:42 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks