Drawing line from thin to thick

I need to draw a line where some segments of the line is thicker than the rest.
I can draw the lines, but I need some kind of smooth transition from thin line to thick and the other way around. I'm using generalpath and stroke to draw the lines.
What is the best (easiest) way to do this?

Check out following code if it works for you. I've used b-spline approach to generate the shape of the path. You just need to specify control points and width at them.
import java.awt.*;
import java.awt.geom.*;
import javax.swing.*;
public class FloatWidthPath {
    Point2D[] pnts1;
    Point2D[] pnts2;
    CurvedPath cp1;
    CurvedPath cp2;
    public class CurvedPath {
        Point2D[] cPoints;
        double[] params;
        CubicCurve2D[] curves;
        public CurvedPath(Point2D[] pnts) {
            this.cPoints = pnts;
            double s = 0.75;
            double [] curSeg = new double[2];
            curves = new CubicCurve2D[cPoints.length-1];
            params = new double[cPoints.length];
            for (int i = 0; i < cPoints.length-1; i++){
                curves[i] = new CubicCurve2D.Double(
                    getCP(i+1).getX(), getCP(i+1).getY(),
                    -s*getCP(i).getX()/3 + getCP(i+1).getX() +
                    s*getCP(i+2).getX()/3,
                    -s*getCP(i).getY()/3 + getCP(i+1).getY() +
                    s*getCP(i+2).getY()/3,
                    s*getCP(i+1).getX()/3 + getCP(i+2).getX() -
                    s*getCP(i+3).getX()/3,
                    s*getCP(i+1).getY()/3 + getCP(i+2).getY() -
                    s*getCP(i+3).getY()/3,
                    getCP(i+2).getX(), getCP(i+2).getY());
        Point2D getCP(int i) {
            if (i == 0) {
                return new Point2D.Double(
                    -0.5*cPoints[0].getX() + 1.5*cPoints[1].getX(),
                    -0.5*cPoints[0].getY() + 1.5*cPoints[1].getY());
            } else if (i == cPoints.length+1) {
                int l = cPoints.length;
                return new Point2D.Double(
                    -0.5*cPoints[l - 1].getX() + 1.5*cPoints[l - 2].getX(),
                    -0.5*cPoints[l - 1].getY() + 1.5*cPoints[l - 2].getY());
            return cPoints[i-1];
        public CubicCurve2D getCurve(int i) {
            return curves;
public Path2D getPath2D() {
Path2D.Double result = new Path2D.Double();
result.moveTo(cPoints[0].getX(), cPoints[0].getY());
int i = 0;
while (i < curves.length) {
result.append(curves[i], true);
i++;
return result;
public FloatWidthPath(Point2D[] pnts, double[] width) {
pnts1 = new Point2D[pnts.length];
pnts2 = new Point2D[pnts.length];
double dx = 0;
double dy = 0;
double l = 0;
for (int i = 0; i < pnts.length - 1; i++) {
dx = pnts[i + 1].getX() - pnts[i].getX();
dy = pnts[i + 1].getY() - pnts[i].getY();
l = Math.sqrt(dx*dx + dy*dy);
double dx1 = (dx*width[i])/l;
double dy1 = (dy*width[i])/l;
pnts1[i] = new Point2D.Double(pnts[i].getX()- dy1, pnts[i].getY() + dx1);
pnts2[i] = new Point2D.Double(pnts[i].getX()+ dy1, pnts[i].getY() - dx1);
int i = pnts.length - 1;
double dx1 = (dx*width[width.length - 1])/l;
double dy1 = (dy*width[width.length - 1])/l;
pnts1[i] = new Point2D.Double(pnts[i].getX()- dy1, pnts[i].getY() + dx1);
pnts2[i] = new Point2D.Double(pnts[i].getX()+ dy1, pnts[i].getY() - dx1);
for (i = 0; i < (pnts2.length >> 1); i++) {
Point2D tmp = pnts2[i];
pnts2[i] = pnts2[pnts2.length - i - 1];
pnts2[pnts2.length - i - 1] = tmp;
cp1 = new CurvedPath(pnts1);
cp2 = new CurvedPath(pnts2);
public Path2D getPath2D() {
Path2D.Double result = new Path2D.Double();
result.append(cp1.getPath2D(), false);
result.append(cp2.getPath2D(), true);
result.closePath();
return result;
public static void showPath(String frameName, Point2D[] pnts,
double [] width) {
JFrame frame = new JFrame(frameName);
final Point2D[] shownPnts = pnts;
final double [] showWidth = width;
frame.getContentPane().add(new JPanel() {
public void paint(Graphics g) {
Graphics2D g2d = (Graphics2D)g;
FloatWidthPath cp = new FloatWidthPath(shownPnts, showWidth);
g2d.fill(cp.getPath2D());
frame.setPreferredSize(new Dimension(100,100));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
public static void main(String[] args) {
showPath("CurvedPath demo", new Point2D[]{
new Point2D.Double(10,10),
new Point2D.Double(100,30),
new Point2D.Double(100,100),
new Point2D.Double(10,120),
}, new double [] {3, 4, 20, 8});

Similar Messages

  • Drawing line from existing one without joining

    How can I draw a line from the endpoint of an existing line (snap to grid is on), without the lines being joined?  Joining causes two problems for me:
    1. The arrowhead at the end of the existing line moves to the end of the joined line, whereas I want the arrowhead in the middle of the combined line.
    2. Even without entering isolation mode the new line gets joined to a line which belong to a group, thus becoming part of that group as well. This defies the use of grouping to create logically connected units.
    TIA
    Steven

    JETalmage wrote:
     ...Worst-of-class Bezier drawing interface. The Pen Tool has absolutely no business affecting pre-existing unselected paths by default. The Pen Tool is not a selection tool, and it violates the entire meaning of something's being selected.
    JET
    while I agree in principle, on practice when clicking on end points with the pen tool most of the time I do want the paths to join but a lot of other times I do not. So, the best practical solution at least for me would be just holding the Spacebar when clicking on an end point to prevent joining without the need to click away and then drag in place. And they should make this an option in the Preferences for those who want to hold Spacebar only when joining.
    The bigger problem is that with overlapping points and edges, Illustrator uses the stacking order and not the selected object when auto joining or adding points which is actually not practical in any case. For example if there are several lines starting at the same point, not the selected but the topmost line will be joined and with overlapping edges adding a point is impossible if the selected edge is not on the top.

  • Draw non-joined lines from endpoint of existing lines

    I asked on the general AI forum how to draw lines from existing line endpoints without the two being joined, and I got the answer that you can't. So I think this calls for a feature request: give the user the possibility to draw a line at the endpoint of a pre-existing line without joining the two. Up till now the current functionality has two drawbacks for me:
    1. It makes creating the following pulse diagram a PITA:
    When I draw a line starting from the arrowhead the arrowhead moves to the new endpoint. Here I had to draw the new line elsewhere on my page and drag it over the arrow.
    2. If you draw a line to the end of an existing line in a group it gets automatically joined to it, and thus becomes part of that group, even when you're not working in isolation mode. Again I have to draw my line at another place on the page and drag it to the grouped object afterwards.
    So, feature request: allow lines sharing a common end- and start point without being joined.

    This is not the ability of usual flex classes. You should explore on how the 3D coordinates system of Flex works, and learn some classes usability, such as Matrix3D, for example.

  • Begginner: Drawing lines in xcode

    I have some experience in other languages (flash actionscript and visual basic), and love to fizzle around with quartz composer. I normally use programming as a way to prototype and test some ideas and pet projects, and as another mean to express myself, but I am feeling that I will have to learn new things in order to grow. I never used xcode, though..
    I want to be able to open xcode and draw a small program that draw lines from A to B.
    I don't care at this point where A and B are, i just plan to draw the lines. If possible in such a way that opens me possibilities of rendering those lines with multiple filters as one do using quartz composer.
    Where do I start?
    thanks.

    You have to subclass NSView and implement drawRect: with something like
    [NSBezierPath strokeLineFromPoint:p1 toPoint:p2]

  • I would like to cut and paste information from a word file onto a pdf file, as well as draw lines onto the pdf file.  How can I accomplish that task?  Is there software I can purchase?

    I would like to cut and paste information from a word file onto a pdf file, as well as draw lines onto the pdf file.  How can I accomplish that task?  Is there software I can purchase?

    Hi jgallu7382,
    The latter is easily accomplished using the Drawing Markup tools, which are available in both the free Adobe Reader, and in Acrobat. Copying/pasting text into the PDF is something that you could do using the editing tools that are available only in Acrobat. Note, however, that Acrobat isn't intended to be a text-editing application, so editing there won't be as robust as in an application designed specifically for that purpose. (It's also worth mentioning that you won't be able to alter a PDF if it has document permissions applied that would prevent you from doing so.)
    I hope that answers your questions.
    Best,
    Sara

  • Is there a way to draw a straight line from one point to another?

    Is there a way of drawing a straight line from one point to another please?

    Yes.  First click on this icon:
    Now select the line drawing icon:
    Now press a shift key and drag your mouse on the image to draw a straight line.
    These instructions are for Windows system so you need to adapt the method for Macs.  I can't afford to by an Apple Mac!!!!!
    Good luck.

  • Draw a Line From any Point A To any Point B Dynamically Using AS3

    I am trying to make an anmation where there are several locations(say A,B,C,D,......) made on a  map. If a person clicks on one location A and then another location B, I wanted to draw a dotted line from point A (from  destination of the plane) to point B(to destination of the plane)  using AS3. Please help me........

    Here is a quick and dirty timeline code that does it (class is below):
    var line:Shape;
    var lineGraphics:Graphics;
    var clickSwitch:int = 0;
    var mousePositions:Array = [];
    var conversion:Number = 180 / Math.PI;
    init();
    function init():void {
         drawBackground();
         line = new Shape();
         addChild(line);
         lineGraphics = line.graphics;
         stage.addEventListener(MouseEvent.CLICK, onClick);
    function onClick(e:MouseEvent):void
         clickSwitch = 1 - clickSwitch;
         mousePositions[clickSwitch] = new Point(mouseX, mouseY);
         if (clickSwitch == 0) {
              drawLine();
         else {
              removeLine();
    function removeLine():void
         lineGraphics.clear();
         line.rotation = 0;
    function drawLine():void
         lineGraphics.lineStyle(1, 0xff0000);
         lineGraphics.moveTo(0, 0);
         var dotDistance:Number = 2;
         var nextX:Number = dotDistance;
         while (line.width < Point.distance(mousePositions[0], mousePositions[1])) {
              lineGraphics.lineTo(nextX, 0);
              nextX += dotDistance;
              lineGraphics.moveTo(nextX, 0);
              nextX += dotDistance;
         line.rotation =  conversion * Math.atan2(mousePositions[0].y - mousePositions[1].y, mousePositions[0].x - mousePositions[1].x);
         line.x = mousePositions[1].x;
         line.y = mousePositions[1].y;
    function drawBackground():void
         var s:Shape = new Shape();
         var g:Graphics = s.graphics;
         g.beginFill(0xC0C0C0);
         g.drawRect(0, 0, stage.stageWidth, stage.stageHeight);
         g.endFill();
         addChild(s);
    Class:
    package
         import flash.display.Graphics;
         import flash.display.Shape;
         import flash.display.Sprite;
         import flash.events.MouseEvent;
         import flash.geom.Point;
         public class DottedLine extends Sprite
              private var line:Shape;
              private var lineGraphics:Graphics;
              private var clickSwitch:int = 0;
              private var mousePositions:Array = [];
              private var conversion:Number = 180 / Math.PI;
              public function DottedLine()
                   init();
              private function init():void {
                   drawBackground();
                   line = new Shape();
                   addChild(line);
                   lineGraphics = line.graphics;
                   stage.addEventListener(MouseEvent.CLICK, onClick);
              private function onClick(e:MouseEvent):void
                   clickSwitch = 1 - clickSwitch;
                   mousePositions[clickSwitch] = new Point(mouseX, mouseY);
                   if (clickSwitch == 0) drawLine();
                   else removeLine();
              private function removeLine():void
                   lineGraphics.clear();
                   line.rotation = 0;
              private function drawLine():void
                   lineGraphics.lineStyle(1, 0xff0000);
                   lineGraphics.moveTo(0, 0);
                   var dotDistance:Number = 2;
                   var nextX:Number = dotDistance;
                   while (line.width < Point.distance(mousePositions[0], mousePositions[1])) {
                        lineGraphics.lineTo(nextX, 0);
                        nextX += dotDistance;
                        lineGraphics.moveTo(nextX, 0);
                        nextX += dotDistance;
                   line.rotation =  conversion * Math.atan2(mousePositions[0].y - mousePositions[1].y, mousePositions[0].x - mousePositions[1].x);
                   line.x = mousePositions[1].x;
                   line.y = mousePositions[1].y;
              private function drawBackground():void
                   var s:Shape = new Shape();
                   var g:Graphics = s.graphics;
                   g.beginFill(0xC0C0C0);
                   g.drawRect(0, 0, stage.stageWidth, stage.stageHeight);
                   g.endFill();
                   addChild(s);

  • How to see my code drawing a line from one point to another

    hi, im wondering if you could help me.
    i am working on my project which is to visualise travelling salesman heuristics.
    i have managed to make my first heuristic work, but my problem is that when i clicked the run button on my GUI,
    the output is already a complete tour with all the edges already drawn, but what i want is to see how it solves or draw the lines from one vertex to another just by clickin the run button once.
    would be great if you could advice me of what method or technique i need to use to see my application solving the tour or drawing the edges.
    below is my cofe for drawing the edges from one point to another
      void drawLineNNh(Graphics g){
             Graphics2D g2 = (Graphics2D) g;
             g2.setColor(Color.blue);
             int i = 0;
             if (P == null) return;
             else
                 for(i=0; i<P.getSize(); i++)
                 Line2D.Double drawLine = new Line2D.Double(P.x_coor[nnH.seen]+5, P.y_coor[nnH.seen[i]]+5, P.x_coor[nnH.seen[i+1]]+5,P.y_coor[nnH.seen[i+1]]+5);
    Line2D.Double drawLastEdge = new Line2D.Double(P.x_coor[nnH.seen[P.getSize()-1]]+5, P.y_coor[nnH.seen[P.getSize()-1]]+5, P.x_coor[0]+5,P.y_coor[0]+5);
    g2.drawString( " Total Distance : " + nnH.totalDistance , 10, 300);
    g2.draw(drawLine);
    g2.draw(drawLastEdge);
    public void setNNh(Points p)
    nnH = new NNheuristic(p);
    useNNh = true;
    public void paint(Graphics g)
    frame(g);
    drawpoints(g);
    if(useNNh)
    drawLineNNh(g);
    below is my code for calling the above method to draw edges, actionlistererun.addActionListener(new ActionListener()
    public void actionPerformed(ActionEvent e) {
    if (e.getActionCommand().equals("Run")) {
    if (chooseHeur.getSelectedItem()=="Nearest-Neighbour")
    System.out.println(chooseHeur.getSelectedItem());
    //points = new Points(toInt((String)chooseNum.getSelectedItem()));
    //PlotArea.set(points);
    PlotArea.setNNh(points);
    PlotArea.repaint();

    I AM USING SWING.
    HERE IS MY CODE, HOPEFULLY ENOUGH TO UNDERSTAND THE PROBLEM.
    class Plot extends Panel{
         public static int num;
         NNheuristic nnH;
         Closest_insertion CI;
         Points P;
         public static boolean useNNh= false;
         boolean useCI=false;
         boolean triangleDrawn = false;
         boolean CIupdate;
         void drawpoints (Graphics g)
             Graphics2D g2 = (Graphics2D) g;
             Graphics2D g3 = (Graphics2D) g;
             int i=1;
             g2.setColor(Color.red);
                    if (P==null) return;
                    else
                    while (i<P.getSize())
                         Ellipse2D.Double vertices = new Ellipse2D.Double(P.x_coor,P.y_coor[i],10,10);
    g2.fill(vertices);
    i++;
    g3.setColor(Color.MAGENTA);
    Ellipse2D.Double initial = new Ellipse2D.Double(P.x_coor[0],P.y_coor[0],10,10);
    g3.fill(initial);
    System.out.println("No. of Vertices: " + P.getSize());
    for(int k = 0; k < P.getSize(); k++)
    System.out.println("x coordinate: " + P.x_coor[k] + ", " + "y coordinate :" + P.y_coor[k] );
    // System.out.println("next:"+ P.x_coor[k+1]);
    triangleDrawn = false;
    void drawLineNNh(Graphics g){
    Graphics2D g2 = (Graphics2D) g;
    g2.setColor(Color.blue);
    int i = 0;
    if (P == null) return;
    else
    for(i=0; i<P.getSize(); i++)
    Line2D.Double drawLine = new Line2D.Double(P.x_coor[nnH.seen[i]]+5, P.y_coor[nnH.seen[i]]+5, P.x_coor[nnH.seen[i+1]]+5,P.y_coor[nnH.seen[i+1]]+5);
    Line2D.Double drawLastEdge = new Line2D.Double(P.x_coor[nnH.seen[P.getSize()-1]]+5, P.y_coor[nnH.seen[P.getSize()-1]]+5, P.x_coor[0]+5,P.y_coor[0]+5);
    g2.drawString( " Total Distance : " + nnH.totalDistance , 10, 300);
    g2.draw(drawLine);
    g2.draw(drawLastEdge);
    public void set (Points p)
    P=p;
    useNNh = false;
    useCI = false;
    public void setNNh(Points p)
    nnH = new NNheuristic(p);
    useNNh = true;
    void frame (Graphics g)
    g.setColor(Color.white);
              g.fillRect(0,0,size().width,size().height);
              g.setColor(Color.green);
              g.drawRect(0,0,579,280);
    public void paint(Graphics g)
    frame(g);
    drawpoints(g);
    if(useNNh)
    drawLineNNh(g);
    else if(useCI)
    if(!CIupdate)
    drawTriCI(g);
    else
    drawRestCI(g);
    // drawLineNNh(g);
    public void clear ()
         // remove the points and the graph.
    P=null;
    triangleDrawn = false;
    code of my GUIpublic class TSP extends JFrame{
    JButton run;
    ...................codes...........
    TSP() {
    ...............................codes...........
    run = new JButton ("Run");
    run.setPreferredSize(new Dimension(113,30));
    run.addActionListener(new ActionListener()
    public void actionPerformed(ActionEvent e) {
    if (e.getActionCommand().equals("Run")) {
    if (chooseHeur.getSelectedItem()=="Nearest-Neighbour")
    System.out.println(chooseHeur.getSelectedItem());
    //points = new Points(toInt((String)chooseNum.getSelectedItem()));
    //PlotArea.set(points);
    PlotArea.setNNh(points);
    PlotArea.repaint();
    else if(chooseHeur.getSelectedItem()=="Closest-Insertion")
    PlotArea.setC_I(points);
    PlotArea.repaint();
    pane2.add(run);

  • I have lines from the top on the screen to the bottom the right one acts like the cursor now I have a transparent white line down the center of the screen about 1/8 inch thick.  Anyone know what is causing this?

    I have lines from the top of the screen to the bottom 4 lines.  They are the size of the cursor and the one on the right acts like the cursor.  Blinks.  The other day I brought compuer up and I have a white transparent line right down the center of the screen about 1/8 inch thick.  Does anyone know what is cauing this?  Also computer is running slow.

    Post a screen shot if you can by pressing cmd+shift+4 for only a certain section or cmd+shift+3 for a full screen shot.

  • Is there a way to draw lines of variable thickness in JAVA ?

    Is there a way to draw lines of variable thickness in JAVA ?

    use fillRect(int i ,int j ,int length ,int width) method in java.awt.Graphics class.
    in this specify width integer to u r need
    if u need code for this just feel free to ask for the code in this thread

  • Drawing a line from one nested MC to another

    I'm using the Drawing API to draw a line from one MC nested
    within two levels of parent MCs to another similarly-nested MC. Can
    someone tell me how to get the X,Y coordinates of both points?

    Try this:
    var objPointA:Object = new Object()
    var objPointB:Object = new Object()
    objPointA.x = grandparentA_mc.parentA_mc.childA_mc._x;
    objPointA.y = grandparentA_mc.parentA_mc.childA_mc._y;
    objPointB.x = grandparentB_mc.parentB_mc.childB_mc._x;
    objPointB.y = grandparentB_mc.parentB_mc.childB_mc._y;
    grandparentA_mc.parentA_mc.localToGlobal(objPointA);
    grandparentB_mc.parentB_mc.localToGlobal(objPointB);
    var lineHolder = _root.createEmptyMovieClip("lineHolder", 1);
    lineHolder.lineStyle(1, clr, 100);
    lineHolder.moveTo(objPointA.x, objPointA.y);
    lineHolder.lineTo(objPointB.x, objPointB.y);
    Remove '_spamkiller_' to mail

  • Reading a Random Line from a Text File

    Hello,
    I have a program that reads from a text file words. I currently have a text file around 800KB of words. The problem is, if I try to load this into an arraylist so I can use it in my application, it takes wayy long to load. I was wondering if there was a way to just read a random line from the text file.
    Here is my code, and the text file that the program reads from is called 'wordFile'
    import java.awt.*;
    import java.awt.geom.*;
    import javax.swing.*;
    import java.awt.event.*;
    import java.io.*;
    import java.util.*;
    public class WordColor extends JFrame{
         public WordColor(){
              super("WordColor");
              setSize(1000,500);
              setVisible(true);
              add(new WordPanel());
         public static void main(String[]r){
              JFrame f = new WordColor();
    class WordPanel extends JPanel implements KeyListener{
         private Graphics2D pane;
         private Image img;
         private char[]characterList;
         private CharacterPosition[]positions;
         private int charcounter = 0;
         private String initialWord;
         private File wordFile = new File("C:\\Documents and Settings\\My Documents\\Java\\projects\\WordColorWords.txt");
         private FontMetrics fm;
         private javax.swing.Timer timer;
         public final static int START = 20;
         public final static int delay = 10;
         public final static int BOTTOMLINE = 375;
         public final static int buffer = 15;
         public final static int distance = 4;
         public final static Color[] colors = new Color[]{Color.red,Color.blue,Color.green,Color.yellow,Color.cyan,
                                                                          Color.magenta,Color.orange,Color.pink};
         public static String[] words;
         public static int descent;
         public static int YAXIS = 75;
         public static int SIZE = 72;
         public WordPanel(){
              words = readWords();
              setLayout(new BorderLayout());
              initialWord = getWord();
              characterList = new char[initialWord.length()];
              for (int i=0; i<initialWord.length();i++){
                   characterList[i] = initialWord.charAt(i);
              setFocusable(true);
              addKeyListener(this);
              timer = new javax.swing.Timer(delay,new ActionListener(){
                   public void actionPerformed(ActionEvent evt){
                        YAXIS += 1;
                        drawWords();
                        if (YAXIS + descent - buffer >= BOTTOMLINE) lose();
                        if (allColorsOn()) win();
         public void paintComponent(Graphics g){
              super.paintComponent(g);
              if (img == null){
                   img = createImage(getWidth(),getHeight());
                   pane = (Graphics2D)img.getGraphics();
                   pane.setColor(Color.white);
                   pane.fillRect(0,0,getWidth(),getHeight());
                   pane.setFont(new Font("Arial",Font.BOLD,SIZE));
                   pane.setColor(Color.black);
                   drawThickLine(pane,getWidth(),5);
                   fm = g.getFontMetrics(new Font("Arial",Font.BOLD,SIZE));
                   descent = fm.getDescent();
                   distributePositions();
                   drawWords();
                   timer.start();
              g.drawImage(img,0,0,this);
         private void distributePositions(){
              int xaxis = START;
              positions = new CharacterPosition[characterList.length];
              int counter = 0;
              for (char c: characterList){
                   CharacterPosition cp = new CharacterPosition(c,xaxis, Color.black);
                   positions[counter] = cp;
                   counter++;
                   xaxis += fm.charWidth(c)+distance;
         private void drawThickLine(Graphics2D pane, int width, int thickness){
              pane.setColor(Color.black);
              for (int j = BOTTOMLINE;j<BOTTOMLINE+1+thickness;j++){
                   pane.drawLine(0,j,width,j);
         private void drawWords(){
              pane.setColor(Color.white);
              pane.fillRect(0,0,getWidth(),getHeight());
              drawThickLine(pane,getWidth(),5);
              for (CharacterPosition cp: positions){
                   int x = cp.getX();
                   char print = cp.getChar();
                   pane.setColor(cp.getColor());
                   pane.drawString(""+print,x,YAXIS);
              repaint();
         private boolean allColorsOn(){
              for (CharacterPosition cp: positions){
                   if (cp.getColor() == Color.black) return false;
              return true;
         private Color randomColor(){
              int rand = (int)(Math.random()*colors.length);
              return colors[rand];
         private void restart(){
              charcounter = 0;
              for (CharacterPosition cp: positions){
                   cp.setColor(Color.black);
         private void win(){
              timer.stop();
              newWord();
         private void newWord(){
              pane.setColor(Color.white);
              pane.fillRect(0,0,getWidth(),getHeight());
              repaint();
              drawThickLine(pane,getWidth(),5);
              YAXIS = 75;
              initialWord = getWord();
              characterList = new char[initialWord.length()];
              for (int i=0; i<initialWord.length();i++){
                   characterList[i] = initialWord.charAt(i);
              distributePositions();
              charcounter = 0;
              drawWords();
              timer.start();
         private void lose(){
              timer.stop();
              pane.setColor(Color.white);
              pane.fillRect(0,0,getWidth(),getHeight());
              pane.setColor(Color.red);
              pane.drawString("Sorry, You Lose!",50,150);
              repaint();
              removeKeyListener(this);
              final JPanel p1 = new JPanel();
              JButton again = new JButton("Play Again?");
              p1.add(again);
              add(p1,"South");
              p1.setBackground(Color.white);
              validate();
              again.addActionListener(new ActionListener(){
                   public void actionPerformed(ActionEvent evt){
                        remove(p1);
                        addKeyListener(WordPanel.this);
                        newWord();
         private String getWord(){
              int rand = (int)(Math.random()*words.length);
              return words[rand];
         private String[] readWords(){
              ArrayList<String> arr = new ArrayList<String>();
              try{
                   BufferedReader buff = new BufferedReader(new FileReader(wordFile));
                   try{
                        String line = null;
                        while (( line = buff.readLine()) != null){
                             line = line.toUpperCase();
                             arr.add(line);
                   finally{
                        buff.close();
              catch(Exception e){e.printStackTrace();}
              Object[] objects = arr.toArray();
              String[] words = new String[objects.length];
              int count = 0;
              for (Object o: objects){
                   words[count] = (String)o;
                   count++;
              return words;
         public void keyPressed(KeyEvent evt){
              char tempchar = evt.getKeyChar();
              String character = ""+tempchar;
              if (character.equalsIgnoreCase(""+positions[charcounter].getChar())){
                   positions[charcounter].setColor(randomColor());
                   charcounter++;
              else if (evt.isShiftDown()){
                   evt.consume();
              else{
                   restart();
              drawWords();
         public void keyTyped(KeyEvent evt){}
         public void keyReleased(KeyEvent evt){}
    class CharacterPosition{
         private int xaxis;
         private char character;
         private Color color;
         public CharacterPosition(char c, int x, Color col){
              xaxis = x;
              character = c;
              color = col;
         public int getX(){
              return xaxis;
         public char getChar(){
              return character;
         public Color getColor(){
              return color;
         public void setColor(Color c){
              color = c;
    }

    I thought that maybe serializing the ArrayList might be faster than creating the ArrayList by iterating over each line in the text file. But alas, I was wrong. Here's my code anyway:
    class WordList extends ArrayList<String>{
      long updated;
    WordList readWordList(File file) throws Exception{
      WordList list = new WordList();
      BufferedReader in = new BufferedReader(new FileReader(file));
      String line = null;
      while ((line = in.readLine()) != null){
        list.add(line);
      in.close();
      list.updated = file.lastModified();
      return list;
    WordList wordList;
    File datFile = new File("words.dat");
    File txtFile = new File("input.txt");
    if (datFile.exists()){
      ObjectInputStream input = new ObjectInputStream(new FileInputStream(datFile));
      wordList = (WordList)input.readObject();
      if (wordList.updated < txtFile.lastModified()){
        //if the text file has been updated, re-read it
        wordList = readWordList(txtFile);
        ObjectOutputStream output = new ObjectOutputStream(new FileOutputStream(datFile));
        output.writeObject(wordList);
        output.close();
    } else {
      //serialized list does not exist--create it
      wordList = readWordList(txtFile);
      ObjectOutputStream output = new ObjectOutputStream(new FileOutputStream(datFile));
      output.writeObject(wordList);
      output.close();
    }The text file contained one random sequence of letters per line. For example:
    hwnuu
    nhpgaucah
    zfbylzt
    hwnc
    gicgwkhStats:
    Text file size: 892K
    Serialized file size: 1.1MB
    Time to read from text file: 795ms
    Time to read from serialized file: 1216ms

  • Differences between Oracle JDBC Thin and Thick Drivers

    If any body is looking for this information...
    ============================================================
    I have a question concerning the Oracle JDBC thin vs. thick drivers
    and how they might affect operations from an application perspective.
    We're in a Solais 8/Oracle 8.1.7.2 environment. We have several
    applications on several servers connecting to the Oracle database.
    For redundancy, we're looking into setting up TAF (transparent
    application failover). Currently, some of our apps use the Oracle
    <B>JDBC thin</B> drivers to talk to the database, with a connection
    string that like this:
    <B> jdbc:oracle:thin:@host:port:ORACLE_SID </B>
    In a disaster recovery mode, where we would switch the database
    from one server to another, the host name in the above string
    would become invalid. That means we have to shut down our application
    servers and restart them with an updated string.
    Using the Oracle <B>OCI (thick)</B> driver though, allows us to connect
    to a Net8 service instead of a specific server:
    <B> jdbc:oracle:oci8:@NET8_SERVICE_NAME </B>
    Coupled with the FAILOVER=ON option configured in Net8, it is
    then possible to direct a connection from the first server to
    the failover database on another server. This is exactly what
    we would like to do.
    My question is, from an application perspective, how is the Oracle
    thick driver different from the thin driver? If everything
    else is "equal" (i.e. the thick driver is compatible with the
    app servers) would there be something within the the thick/OCI
    driver that could limit functionality vs. the thin driver?
    My understand, which obviously is sketchy, is that the thick
    driver is a superset of the thin driver. If this is the case,
    and for example if all database connections were handled through
    a configuration file with the above OCI connection string, then
    theoretically the thick driver should work.
    ============================================================
    <B>
    In the case with the Oracle, they provide a thin driver that is a 100% Java driver for client-side use without the need of an Oracle installation (maybe that's why we need to input server name and port number of the database server). This is platform indipendent, and has good performance and some features.
    The OCI driver on the other hand is not java, require Oracle installation, platform dependent, performance is faster, and has a complete list of all the features.
    </B>
    ========================================================
    I hope this is what you expect.
    JDBC OCI client-side driver: This is a JDBC Type 2 driver that uses Java native methods to call entrypoints in an underlying C library. That C library, called OCI (Oracle Call Interface), interacts with an Oracle database. <B>The JDBC OCI driver requires an Oracle (7.3.4 or above) client installation (including SQL*Net v2.3 or above) and all other dependent files.</B> The use of native methods makes the JDBC OCI driver platform specific. Oracle supports Solaris, Windows, and many other platforms. This means that the Oracle JDBC OCI driver is not appropriate for Java applets, because it depends on a C library to be preinstalled.
    JDBC Thin client-side driver: This is a JDBC Type 4 driver that uses Java to connect directly to Oracle. It emulates Oracle's SQL*Net Net8 and TTC adapters using its own TCP/IP based Java socket implementation. <B>The JDBC Thin driver does not require Oracle client software to be installed, but does require the server to be configured with a TCP/IP listener. Because it is written entirely in Java, this driver is platform-independent.</B> The JDBC Thin driver can be downloaded into any browser as part of a Java application. (Note that if running in a client browser, that browser must allow the applet to open a Java socket connection back to the server.
    JDBC Thin server-side driver: This is another JDBC Type 4 driver that uses Java to connect directly to Oracle. This driver is used internally by the JServer within the Oracle server. This driver offers the same functionality as the client-side JDBC Thin driver (above), but runs inside an Oracle database and is used to access remote databases. Because it is written entirely in Java, this driver is platform-independent. There is no difference in your code between using the Thin driver from a client application or from inside a server.
    ======================================================
    How does one connect with the JDBC Thin Driver?
    The the JDBC thin driver provides the only way to access Oracle from the Web (applets). It is smaller and faster than the OCI drivers, and doesn't require a pre-installed version of the JDBC drivers.
    import java.sql.*;
    class dbAccess {
    public static void main (String args []) throws SQLException
    DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver());
    Connection conn = DriverManager.getConnection
    ("jdbc:oracle:thin:@qit-uq-cbiw:1526:orcl", "scott", "tiger");
    // @machineName:port:SID, userid, password
    Statement stmt = conn.createStatement();
    ResultSet rset = stmt.executeQuery("select BANNER from SYS.V_$VERSION");
    while (rset.next())
    System.out.println (rset.getString(1)); // Print col 1
    stmt.close();
    How does one connect with the JDBC OCI Driver?
    One must have Net8 (SQL*Net) installed and working before attempting to use one of the OCI drivers.
    import java.sql.*;
    class dbAccess {
    public static void main (String args []) throws SQLException
    try {
    Class.forName ("oracle.jdbc.driver.OracleDriver");
    } catch (ClassNotFoundException e) {
    e.printStackTrace();
    Connection conn = DriverManager.getConnection
    ("jdbc:oracle:oci8:@qit-uq-cbiw_orcl", "scott", "tiger");
    // or oci7 @TNSNames_Entry, userid, password
    Statement stmt = conn.createStatement();
    ResultSet rset = stmt.executeQuery("select BANNER from SYS.V_$VERSION");
    while (rset.next())
    System.out.println (rset.getString(1)); // Print col 1
    stmt.close();
    =================================================================

    Wow, not sure what your question was, but there sure was a lot of information there...
    There really is only one case where failover occurs, and it would not normally be in a disaster recovery situation, where you define disaster recovery as the obliteration of your current server farm, network and concievably the operational support staff. This would require a rebuild of your server, network etc and isn't something done with software.
    Fail over is normally used for high availablity that would take over in case of hardware server failure, or when your support staff wants to do maintenance on the primary server.
    Using the thin and thick driver should have ZERO affect on a failover. Transparent failover will make the secondary server the same IP as the primary, therefore the hostname will still point to the appropriate server. If you are doing this wrong, then you will have to point all your applications to a new IP address. This should be something that you tell your management is UNACCEPTABLE in a fail-over situation, since it is almost sure to fail to fail-over.
    You point out that you are providing the TNSNAME, rather than the HOSTNAME when using the thick driver. That's true within your application, but that name is resolved to either a HOSTNAME, or IP ADDRESS before it is sent to the appropriate Oracle server/instance. It is resolved using either a NAME server (same as DNS server but for Oracle), or by looking at a TNSNAMES file. Since the TNSNAMES files profilerate like rabbits within an organization you don't want a fail over that will make you find and switch all the entries, so you must come up with a fail over that does not require it.
    So, the application should not be concerned with either the hostname, or the IP address changing during fail over. That makes use of the thin or thick client acceptable for fail over.
    Don't know if this will help, but this shows the communication points.
    THIN DRIVER
    client --> dns --> server/port --> SID
    THICK DRIVER
    client --> names server --> dns --> server/port --> SID
    client --> tnsnames     --> dns --> server/port --> SID

  • Drawing line on PDF - not working in Acro 8 and 9

    I have code in a simple Acrobat plugin that draws a line from the point where the mouse button was pressed to the current mouse pointer position, refreshing the lines position as long as the mouse button is being held down. The code works fine in Acrobat 6 and 7, but appears to do nothing in Acrobat 8 and 9 (the code is being called, but no line is drawn). Any insights would be most appreciated. The code is copied below - the first function simply converts the User space point to windows screen coordinates, and the clickProc function is called by an AVAppRegisterForPageViewClicks notification.
    Thanks in advance!
    void AVPageViewUserPointToScreen(AVPageView pageView, ASFixedPoint *src, POINT *dest)
    ASFixedMatrix matrix;
    ASFixedPoint fp;
    AVPageViewGetPageToDevMatrix(pageView, &matrix);
    ASFixedMatrixTransform(&fp, &matrix, src);
    dest->x = FixedTruncToInt16(fp.h);
    dest->y = FixedTruncToInt16(fp.v);
    ACCB1 ASBool ACCB2 clickProc(AVPageView pageView, AVDevCoord x, AVDevCoord y, AVFlagBits16 flags, AVTCount clickNo, void *data)
    ASFixedPoint fpStart, fpEnd;
    POINT drawStart, drawEnd;
    AVDevCoord x0, y0;
    WinPort winPort;
    LOGPEN pen;
    POINT width;
    //store the start point in user space
    AVPageViewDevicePointToPage(pageView, x, y, &fpStart);
    //Get the starting point in screen coordinates
    AVPageViewUserPointToScreen(pageView, &fpStart, &drawStart);
    drawEnd.x = drawStart.x;
    drawEnd.y = drawStart.y;
    winPort = (WinPort)AVPageViewAcquireMachinePort(pageView);
    pen.lopnStyle = PS_SOLID;
    pen.lopnColor = RGB(128, 128, 128);
    width.x = 1;
    pen.lopnWidth = width;
    HPEN hPen = CreatePenIndirect(&pen);
    SelectObject(winPort->hDC, hPen);
    SetROP2(winPort->hDC, R2_NOT);
    while (AVSysMouseIsStillDown())
    AVPageViewGetMousePosition(pageView, &x0, &y0);
    //erase the previous line
    MoveToEx(winPort->hDC, drawStart.x, drawStart.y, NULL);
    LineTo(winPort->hDC, drawEnd.x, drawEnd.y);
    //store the new end point in user coordinates
    AVPageViewDevicePointToPage(pageView, x0, y0, &fpEnd);
    //Get the new end point in screen coordinates
    AVPageViewUserPointToScreen(pageView, &fpEnd, &drawEnd);
    //draw the NEW line
    MoveToEx(winPort->hDC, drawStart.x, drawStart.y, NULL);
    LineTo(winPort->hDC, drawEnd.x, drawEnd.y);
    return TRUE;

    Hmm...
    I don't see anything obvious that would have changed in Acrobat 8 and later. We did change from 16->32 bit coordinates back in Acrobat 7 - but you say the code works fine there, yes?
    If you are still having problems, I would recommend filing a formal support request with developer support.

  • Draw line in illustrator cs2

    hi,
    i am new to adobe illustrator cs2.
    is there any other method to draw line other than s
    setEntirePath().
    thanks in advance,

    Hello David,
    It sounds to me like you're witnessing the double edged sword of an incredibly sharp display. The contrast and clarity of LCD displays makes it very easy to see razor-thin lines with ultra fine definition, but this comes at a cost.
    Font smoothing (a.k.a. font aliasing) is one example of where most LCDs are so sharp that most people prefer to have their text "fuzzed" up a little bit.
    A one pixel wide diagonal line is another example that you've discovered - the display is so sharp that there is no blurring around the "steps" of the line. You can see every change in gradient, because as sharp as your CRT might've been, it was blurring the line just slightly - enough to enhance the illusion that your diagonal line was a line rather than a series of adjacent "steps". No software package that I know of has bothered to implement "line smoothing" yet, probably because you need the detail for accuracy when putting lines together.
    Sort of related to this, big screen HDTV plasma and LCD monitors look amazing in the store when tuned to an HD station, but most people would be floored if they say how grainy and pixelated a standard cable signal looks on the same display. It's literally like watching an old VHS tape, because the display is so sharp it resolves detail that is invisible on a "lesser" display.
    Neat human trick: get used to working with your LCD, and then go back to the CRT if you have a chance. How does the CRT look? I thought I needed glasses the first time I switched back!
    -Shawn

Maybe you are looking for

  • Performance

    Hi gurus, I got some performance related doubts. 1. In a "select" statement if I change the order of columns will it lower the performance ? eg: select posnr vbeln matnr from vbap... 2. How much percentage of performance will be suffering if I use "i

  • Brand New IMAC 27 overheats

    Greetings to all from Chicago! Just purchased a brand new IMAC (27 inch, 2.93GHZ QUAD-CORE INTELCORE I7, 8GB 1333MHZ DDR3 SDRAM - 2X4GB, ATI RADEON HD 5750 1GB GDDR5). Previously had 24 Inch MAC (plastic on the back which is the point of my compariso

  • How to save all records in the Tabular form page temoprarily

    Hi All, I am very new for HTML DB. I created 5 tabular form using HTML DB Wizard. I want that whenever I open any tabular form page and click the add row button in that page then I should add as many record as we need but it should not save in the da

  • Sending email's outside SAP with grids

    Hi guys, I already use the function "SO_DOCUMENT_SEND_API1" to send emails outside SAP, but i need to insert text in to a table, format color's, letter sizes, etc Can i send a email in html format using this function? Can you tell me if this function

  • Battery info very inaccurate...

    I know apple said the battery display was approximate but it will be 100% straight off the charger and I will play ~30 secs. of video and stop. the battery bar is down to like 80% and then after about 2 mins. it goes back up to 100%. It really needs