Drawing a curvy lıne [URGENT HELP]

Advertisement
November 30

Hi to all,
I want to draw a curvy line in java. The cuves should be in fixed size. And when mouse draging the curves will be drawn depending on the line length. One curve top, one curve bottom, respectively.
Any suggestions are greatly appriciated.
thanx.
metan.
this is what I want to do
http://img152.imageshack.us/img152/8597/curvylineee9mh.jpg

Advertisement

Replay

Here's an idea.
Double-click to clear surface. Use command line args to show construction lines.
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import java.awt.image.BufferedImage;
import javax.swing.*;
import javax.swing.event.MouseInputAdapter;
public class CurvyLines extends JPanel
    BufferedImage image;
    Ellipse2D.Double circle;
    int direction;
    final int FLIP = 0;
    final int FLOP = 1;
    static final double DIA = 50.0;
    // construction
    static boolean showConstruction = false;
    Point pStart, pEnd;
    Point2D.Double pCenter;
    Line2D.Double line;
    public CurvyLines(boolean showConstruction)
        circle = new Ellipse2D.Double(0, 0, DIA, DIA);
        direction = FLIP;
        addComponentListener(new ComponentAdapter()
            public void componentResized(ComponentEvent e)
                image = null;
                repaint();
        this.showConstruction = showConstruction;
        pStart = pEnd = new Point();
        pCenter = new Point2D.Double();
        line = new Line2D.Double();
    public void flipFlop(Point p1, Point p2)
        Point2D.Double cp = getCenter(p1, p2);
        pStart = p1; pEnd = p2; pCenter = cp;  // construction
        circle.setFrameFromCenter(cp.x, cp.y, cp.x+DIA/2, cp.y+DIA/2);
        Rectangle2D r = circle.getBounds2D();
        double[] angles = getAngles(p1, cp, p2);
        double start = angles[0];
        double extent = angles[1];
        direction = direction == FLIP ? FLOP : FLIP;
        Graphics2D g2 = (Graphics2D)image.getGraphics();
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                            RenderingHints.VALUE_ANTIALIAS_ON);
        g2.setPaint(Color.blue);
        g2.draw(new Arc2D.Double(r, start, extent, Arc2D.OPEN));
        g2.dispose();
        repaint();
    private Point2D.Double getCenter(Point p1, Point p2)
        Point2D.Double p = new Point2D.Double();
        p.x = p1.x + (p2.x - p1.x)/2;
        p.y = p1.y + (p2.y - p1.y)/2;
        return p;
    private double[] getAngles(Point p1, Point2D.Double cp, Point p2)
        double dx, dy;
        if(direction == FLIP)
            dy = p1.y - cp.y;
            dx = p1.x - cp.x;
            line.setLine(cp, p1);   // construction
        else
            dy = p2.y - cp.y;
            dx = p2.x - cp.x;
            line.setLine(cp, p2);
        double theta = Math.atan2(dy, dx);
        if(showConstruction)
            String prefix;
            if(direction == FLIP)
                prefix = "flip ";
            else                   // direction == FLOP
                prefix = "flop ";
            System.out.println(prefix + " = " + Math.toDegrees(theta));
        // Arc2D counts positive in anti-clockwise direction
        // Math.atan2 counts positive in clockwise direction
        double startAngle = -Math.toDegrees(theta);
        double extent = 180.0
        return new double[] { startAngle, extent };
    public void clear()
        Graphics g = image.getGraphics();
        g.fillRect(0,0,getWidth(),getHeight());
        g.dispose();
        repaint();
    protected void paintComponent(Graphics g)
        if(image == null)
            initImage();
        Graphics2D g2 = (Graphics2D)g;
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                            RenderingHints.VALUE_ANTIALIAS_ON);
        g2.drawImage(image, 0, 0, this);
        if(showConstruction)
            g2.setPaint(Color.red);
            g2.draw(circle);
            g2.setPaint(Color.green.darker());
            g2.fill(new Ellipse2D.Double(pStart.x-2, pStart.y-2, 4, 4));
            g2.fill(new Ellipse2D.Double(pEnd.x-2, pEnd.y-2, 4, 4));
            g2.setPaint(Color.blue);
            g2.fill(new Ellipse2D.Double(pCenter.x-2, pCenter.y-2, 4, 4));
            g2.setPaint(Color.cyan);
            g2.draw(line);
    private void initImage()
        int w = getWidth();
        int h = getHeight();
        image = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
        Graphics2D g2 = image.createGraphics();
        g2.setBackground(UIManager.getColor("Panel.background"));
        g2.clearRect(0,0,w,h);
        g2.dispose();
    public static void main(String[] args)
        boolean showConstruction = false;
        if(args.length > 0)
            showConstruction = true;
        CurvyLines curvyLines = new CurvyLines(showConstruction);
        Pen pen = new Pen(curvyLines);
        curvyLines.addMouseListener(pen);
        curvyLines.addMouseMotionListener(pen);
        JFrame f = new JFrame();
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.getContentPane().add(curvyLines);
        f.setSize(400,400);
        f.setLocation(200,200);
        f.setVisible(true);
class Pen extends MouseInputAdapter
    CurvyLines curvyLines;
    Point start;
    public Pen(CurvyLines cl)
        curvyLines = cl;
    public void mousePressed(MouseEvent e)
        start = e.getPoint();
        if(e.getClickCount() > 1)
            curvyLines.clear();
    public void mouseDragged(MouseEvent e)
        Point end = e.getPoint();
        if(start.distance(end) >= CurvyLines.DIA)
            curvyLines.flipFlop(start, end);
            start = end;
}

View 6 Replies

How to convert PO sapscript layout to pdf - need VERY URGENT Help

November 30

Dear All, Requirement: PO sapscript layout after some modifications (say, ZMEDRUCK) has to be converted to pdf. Through me9f user will be able to give ranges of PO numbers and can view the print preview for the po. After that on clicking the print bu

View All Replies

Urgent help need

October 11

hi friends,   Help me how to do this REPORT  ZINTERFACE_SAMPLE. type-pools:SLIS. TABLES:knb1, "Customer Master (Company Code)        kna1,        knvp. "Customer Master Partner Functions TYPES:BEGIN OF T_knb1,       kunnr like knb1-kunnr,      

View All Replies

Implementation Restriction 'DBMS_LOB.READWRITE'  Urgent Help

October 11

*"Implementation Restriction 'DBMS_LOB.READWRITE' Cannot directly access remote package variable or cursor"* Hello, I need urgent help in implementing DBMS_LOB package. I need to write data in LOB object using DBMS_LOB object following code is w

View All Replies

Urgent Help: IOS 7

October 11

Urgent Help: Does anybody know when exactly the new IOS 7 will be released!Sometime in the Fall of this year. Apple has not anounced anything more specific than that as of yet. And seriously, that's "urgent"?Read other 3 answers

View All Replies

Import hangs Urgent help!!

November 30

Hi DBAs, Urgent help!! I am doing full db import with below parameter, it haged for 30 min, please suggest imp "'/ as sysdba' " file=TF3_SINTSTFAPPU1_R1_2007_UAT_260807.dmp log=TF3_SINTSTFAPPU1_R1_2007_UAT_260807_imp.log full=y grants=y commit=y

View All Replies

How to Draw a vertical line in flex

October 11

I was just wondering the simplest way to draw a vertical line , preferably dashed.You could always just use the graphics class of your chart component.  Just access its graphics object, set the line style/thickness, move to the start point, and line

View All Replies

Load XML in intranet ? urgent help please...

November 30

Dear friends, I need urgent help: I have a CAYIN screen (which lets me display evetns, etc) and gives me the option of loading/displaying a FLASH (SWF) file, well, I need this SWF to load some XML data ("texto.xml") but  seems that when the CAYI

View All Replies

Drawing a curved line using the pen tool, dragging the text cursor over the line but will only give me a small area to write in, in-between a circle and a circle with a cross in?

November 30

Drawing a curved line using the pen tool, dragging the text cursor over the line but will only give me a small area to write in, in-between a circle and a circle with a cross in?If you change your tool to the "Direct Selection Tool" (A) then you

View All Replies

Can I draw a k-line graph with jfreechart for a Mac app on 10.8?

November 30

Hi,   I want to draw a k-line graph on mac, and I haven't find a lib better than jfreechart on doing that work until now, so how can I use it in xcode? RegardsI believe this version works in 10.6.8. http://support.apple.com/kb/DL1507Read other 2 answ

View All Replies

Need urgent help!!!! (combine prompt and formula)

October 11

Hi, I am using Oracle Business Intelligence 10.1.3.3.2, and creating some reports from answers. I desperately need to combine prompt and formula on some column. I need to use prompt in my formula on some column. Need urgent help !You can use the pres

View All Replies

Urgent Help in Tranformation

October 11

Hello Urgent Help Required I am extracting Master data from CRM 5.0. Infoobject 0BPARTNER is enhanced to accommodate a attribute called NAS(data is filled). So for every BP no it has NAS no too For The Revenue of Business partner I am extracting from

View All Replies

Urgent Help! Errors in source system(RSM     340)

October 11

Need urgent help. Issue in production. I added fields to the COPA datasource, by changing the operating concern. I recreated the datasource with the same name replicated into BW & ran delta again. The whole procedure worked fine in Dev & Quality b

View All Replies

Urgent help request

October 11

need urgent help with Lightroom can a person from support department help me please?This is user-to-user forum. We can try to help you here, or you can contact Adobe Customer Care here: Contact Customer CareRead other 3 answers

View All Replies

I have Mac mini and there is partition of boot camp but some miss understanding the osx 10.8.2 is deleted and while I m going to recovery mode the portition can not removing and the also cant repaired what I do I need urgent help ???? Please ?????

November 30

I have Mac mini and there is partition of boot camp but some miss understanding the osx 10.8.2 is deleted and while I m going to recovery mode the portition can not removing and the also cant repaired what I do I need urgent help ???? Please ?????Do

View All Replies

Urgent help - Unable to open operator

October 11

Hello Friends, Need urgent help and suggestions... It started since this morning. When we open ODI Dev/Prod instance repositoy operator it gives this message. Error: Corrupted module. Unable to connect. See the license information in the 'About'...'m

View All Replies

Need urgent help! - I accidentally sycn my friend's iphone account to my company's phone. I could not swich back to my own icloud account because of the icloud password i enter was incorrect. My friend does not use this icloud account since age.

November 30

Need urgent help! - I accidentally sync my friend's iphone account to my company's iphone. I could not switch back to my own icloud account because of the icloud password i enter was incorrect. My friend does not use this icloud account since age onl

View All Replies

I want to downgrade my 2011 mac mini server to mac os x, i want to downgrade my 2011 mac mini server to mac os x i have the disks but the mini willl not reboot the apple changing to a circle with a line please help-

November 30

i want to downgrade my 2011 mac mini server to mac os x i have the disks but the mini willl not reboot the apple changing to a circle with a line please help-bpruse,  I may be completely off-track for your issue, but I had a similar situation where I

View All Replies

Updating to MAXDB 7.5.00.29- user logon failed error! Urgent Help

November 30

Hi I am trying to update MaxDB 7.5.00 to MaxDB 7.5.00.29 on WAS 6.40. When I run the update via SDBUPD, I get the error "cannot establish database instance". i have looked in the log files(MaxDBUpdate_install-16.07.2005-16.13.log) and the error

View All Replies

LASERJET M1217 nfw MFP urgent help plz

November 30

HAY GUYS, NEED URGENT HELP!!!!!!!!! My printer M1217 nfw MFP had a problem with the scanner and it was fixed bu updating the firmware and the scanner works fine and offcourse i printed the config. report  befor updating the firmware , the problem is

View All Replies

Tags:

  1. ipad a1396 charging only vibrate no on
  2. PARNR LiVE ViDEo ON
  3. nokia n81 stuck on nokia logo
  4. youtube does not open safari mac kids ç
  5. sapjco3 Connect to SAP gateway failed
  6. how to set program run dat in rffoedi1
  7. principle3go
  8. suitahz
  9. pocket3eq
  10. 2M6M
Copyrights 2019 Fcffair BigData Resource, All rights reserved