Simple pascal's triangle problem

Hi,
I'm new to Java, and I'm trying to make a recursive method that outputs a pascal's triangle, n = 4. based on the choose function: (n,k) =(n-1, k-1) + (n-1,k). I believe there are a lot of errors in my source code, which compiles, but I just can't figure out what I need to do next to get it to actually display the pascal triangle, based on what I have so far. could anyone give me some directions as to how to think through the problem. here's my source code:
public class pascal
     public int choose (int n, int k)
          int result = 0;
          if (n==0 && k==0)
               result = 1; \\base case
          else
               for (int i=0; i<=k; i++)
                    if(i==0 || i==k)
                         result = 1;
                    else
                    result = choose(n-1,i-1) + choose(n-1,i);
          System.out.print(result);
          return result;
     public static void main (String[] args)
          int n = 4;
          int k = n;
          pascal test = new pascal();
          test.choose (n,k);
}

Think of this little recurrence relation a bit more: c(n,k) =c(n-1, k-1) + c(n-1,k).
When n == k, the result equals 1 (one). Those values can be found
on the right diagonal side of the triangle. If k > n, the value has to be
0 (zero). Those values can be found outside the triangle.
Of course n >= 0 and k >= 0. If you put this all together you get:int c(int n, int k) {
   if (k == n) return 1;
   if (k > n) return 0;
   return c(n-1, k-1)+c(n-1, k);
}kind regards,
Jos

Similar Messages

  • Pascal's Triangle Problem

    Hey there guys. I was looking around the forums seeing if there was anything that someone posted simliar to my assignment. While there were SOME similar things, I think mines a bit more specific. Let me just state here that I don't want anyone to just come out and do the assignment for me, nor do I think that anyone would be willing to. Anyways, here's what I am dealing with.
    I am to design a method which uses recursion to print the n-th line of the Pascal's triangle. I have a few ideas in my head about how to make it, but I just can't translate my thoughts into words.
    My first guess is that my method declaration should look something like this:
    public int println(int n)
    }But I'm just at a brainlock. My class really hasn't touched recursion extremely in-depthly expect for what was needed for AP Exam and Binary Search methods. Usually I can figure this stuff out, but ahhh!
    Anyways, any help (aka nudge in the right direction) would be very appreciated.

    A recursive function can be explained as a function defined in terms of itself.
    It is a mathematical concept. Let's take a look at something simple, like fibonacci numbers. Fibonacci numbers are defined in math something like:f(1) = 1
    f(2) = 1
    f(n) = f(n-1) + f(n-2)What this means is that the first two fib numbers are 1 and 1, and every fib number after that is the sum of the two numbers immediately preceeding it. So if we unroll the fibonacci numbers, they are:1 1 2 3 5 8 13 21 34 ...Now we want to implement a method in Java that accepts a single int argument, n, and will return the nth fibonacci number. One way is to do this recursively as such:public int fibonacci(int n) {
        if (n == 1 || n == 2)
            return 1;
        return fibonacci(n - 1) + fibonacci(n - 2);
    }(what we haven't handled is when n < 1, but since this is just to increase understanding of recursion I will omit that)
    What you see is a commonality with all recursive functions, a base case and a recursion step. All recursive methods must have a base case or they will run infinately. Similarly all recursive methods must have a recursion step, for the simple reason that they would not be recursive functions otherwise. Another thing that all recursive functions have in common is that the recursive call is made on some narrower scope (in this case n less 1 and n less 2) resulting in a call drawing ever closer to the base case (not doing so would also result in infinite recursive calls).
    Note: sometimes fibonacci numbers are defined to have the 0th number as 0 and the 1st number as 1, for me that is matter of taste and still results in the same sequence of numbers, with an added 0 at the front.
    In your example, the base case is when n == 1, and the recursion step is the call to fillN with n less 1 (i.e., narrowing the scope). The thing that is different in your example is that the resulting array is being passed around in the recursive calls, this is quite common for accumulating results as the recursion is being wound up (the calls themselves) and even down (when calls return, like in your case).
    You should try tracing out the calls on paper with a reasonably small n, this will better help your understanding. Let me do it with n == 2.fillN(2, a) // a = [0, 0]
    // n is not 1 so we do the recursive call
    fillN(1, a) // a = [0, 0]
    // n is 1 so we do the base case
    array[0] = 1 // a = [1, 0]
    // returning back to the call with n == 2
    // we run through the loop (i begins at n - 1 or 1)
    array[1] += array[0] // a = [1, 1]
    // i becomes 0 which is not > 0 so we exit the loop
    // the recursion has ended and a is now [1, 1]Now you try it with n == 3.
    ps. slightly off-topic, there is a great article by Olivier Danvy and Mayer Goldberg called "There and back again" on the programming pattern of traversing one data structure as recursive calls are being made and traversing a different data structure as the calls are returning (hence, there and back again or TABA). If you're interested you should check it out (Note: they use Scheme in their examples, but that doesn't mean that there's nothing to learn from it if you don't know Scheme):
    http://www.brics.dk/RS/05/3/BRICS-RS-05-3.pdf
    Message was edited by:
    dwg

  • I have an iMac that I purchased back in 2010 and over the past 9 month or less my computer just started shutting down while someone was in the process or working on it.  What could this come from?  Is there a simple solutions to this problem?

    I have an iMac that I purchased back in 2010 and over the past 9 month or less my computer just started shutting down while someone was in the process or working on it.  What could this come from?  Is there a simple solutions to this problem?

    Which model iMac do you have?  http://support.apple.com/kb/HT1758 How to identify iMac models 
    Which OS is currently installed? 
    Check out KB Articles:  http://support.apple.com/kb/HT3964 Intel-based Macs: Resetting the System Management Controller (SMC) and http://support.apple.com/kb/HT1379 Resetting your Mac's PRAM and NVRAM 
    If not of the above works and you have AC, call them.  Let them deal w/it.  Otherwise, take your iMac down to your local AS or an AASP.  Diagnostic testing is FREE! 
    You can also research for a solution on YouTube's "How To" website and iFixit. 

  • Navigation menu indicator triangle problem

    Hi all,
    the navigation menu of my site looks correct in layout mode:
    It still looks correct in preview mode (notice the triangles' position):
    BUT when I go on to Safari, either by previewing it or uploading to my server, the triangles interfere with the text:
    Is there anything I can do about it? This looks awful!
    Thanks a lot!

    No. But it isn’t in Muse’s hand how a browser renders a certain font. You have to use a sort of "security belt".
    The alternative is, you have a layout problem (different font sizes for example in different menu states; using system fonts … …)

  • A triangle problem

    im finishing an assignment for one of my course modules and i'ved hit a problem with part of it.
    i need to be able to compare three values (each the length of one side of a triangle) use this to output the type of triangle to the user
    for example if all three sides are the same, its an equilateral, if only two are the same, its isoceles, and if no sides are the same, its a scalene triangle.
    ive sta here for a long while thinking about how to do it, it anybody could point me in the right direction that would be great
    thanks
    glenn

    i had a class i wrote ages ago that worked out the area of a rectangle. i thought it was sort of similar so i used the old class as a starting point, changing the details where needed.
    public class Triangle
    private int sideA;
    private int sideB;
    private int sideC;
    String type;
    public Triangle( int sideA, int sideB, int sideC)
    this.sideA = sideA;
    this.sideB = sideB;
    this.sideB = sideB;
    public int getsideA()
    return sideA;
    public int getsideB()
    return sideB;
    public int getsideC()
    return sideC;
    public String getType()
    return type;
    }

  • Simple Finder/Parental Controls Problem

    I recently did an erase and install on my eMac and am now having problems with Simple Finder and Parental Controls.
    I have an account set up for my daughter and I want to have Simple Finder running with about a half dozen or so applications for her to use. Prior to the erase-and-install, I had this set up and running fine. But now, even though I select all the programs I want under the Parental Controls preferences, only three show up (Safari, Dictionary, and TextEdit).
    I tried deleting and re-creating the account, repairing permissions, turning around twice and clicking my heels together, etc. with no success.
    Any ideas? Thanks!

    I ran disk utility and repaired the permissions--is that similar to what you suggest?
    When I did a erase-and-install of Leopard, I assume that it ran through a disk inspection and repair routine. But perhaps something more is needed.

  • Some simple yet troubling homework problems

    Hi there, new to the forum and fairly new to Java, and I recently got some homework problems that stumped me. Here are a few questions:
    What is the difference between 2, 2., '2', and "2"?
    True/false:
    Integer.ParseInt( ""+ x ) is the same as x.
    "" + Integer.parseInt(s) is the same as s.
    s.substring ( 0, s.length() ) is the same as s.
    Let x be a positive integer. How do you get the last (lowest order) digit of x using the modulus operator?
    Let x be a positive integer. How do you get the first (highest order) digit of x by converting to a string?
    I think I have a good idea of some of them, but I'm not entirely sure. Any help would be greatly appreciated, thank you. :)

    If its troubling, then it was/is not simple (at least for you). And if you are expecting answers to these questions, forget it. Post your answers, and if they are right we will tell you so. If they are somewhat off, we will guide you to the correct responses. If they are just plain wrong, we will let you know, probably somewhat harshly in some cases, then begin to guide you to the correct responses. This is of course, predicated on you being willing to work with us.

  • Probably a simple answer: easy div problem

    Hello,
    I have a very easy problem but can't find the answer.  3 divs: 1 "wrapper" and 2 inside it (one left column, one right).  I want to get the CSS settings so that the left and right column are both the same length.  Right now they are on auto length and the left column is longer.  I tried to "fill out" the wrapper with the right column by setting the right column to 100% length, but now I realize the "wrapper" div is being shrink-wrapped around the shorter right column and is not stretching it.  I just want both columns to be as long as the (longer) left column.
    Thanks!

    First of all height: 100% doesn't work for divs usually. The height of the browswer window is very hard to fiigure out.
    Second: http://matthewjamestaylor.com/blog/equal-height-columns-2-column.htm
    SOmehow that layout works, and I don't qutie know how although it is a very simple layout.
    Lastly,  I'll bust out the unorthodox, loathed answer that actually is fine unless you want to worry about various screen types or browsing devices: a table.
    First, I will say that it is great that there is new CSS that allows divs to display as tables as Murray, I think, is saying. But with 10% of peple still using IE 6 and 10% using IE 7 (crazy, eh?), I don't think you can do away with support from IE 7 yet, even though we're just about up to 10 now.
    Tables are the intuitive way to solve this if you are not concerned with separating content and organization, which good modern designers are usually concerned with:
    <table class="content">
    <tr>
    <td>first column</td>
    <td>second column</td>
    </tr>
    </table>
    No fuss no muss. But if we can figure out how the two even length columns layout works above, I'd say that's the smart, modern way to deal with this.

  • APEX 4: Theme "Simple Red": "No Label" Problem

    Hi,
    we developed an application in APEX 3 which we currently update and roll out APEX 4.
    Everything works great so far but we have a problem with the new theme we switched to in the app.
    We decided to use "Simple Red" in the next version of the application.
    The main problem with this is that the element labels are shown although the template "No Label" is selected.
    Of course it is possible to change the label from "Whatever" to " " to workaround this bug.
    But because there are many of the labels which shouldn't be shown it would be better to make "No Label" work as aspected.
    Does anyhave have the same problem? How can we resolve that issue?
    Thanks
    Regards
    Daniel

    I found the solution!
    Go in to the template "No Label" and replace the entry on "Before Label" to "<span style="display:none;">" and "After Label" to "</span>".

  • TRIANGLE PROBLEM

    Hi everyone - I am developing various proofs of the pythagora's theorem
    and the following code draws a triangle on screen and the proof follows -
    but i need to know how to drag the triangle such tht 1 angle is always set to 90 degrees.
    i.e. i need to resize the triangle by dragging its vertex points by which the1 angle remains at 90 no matter what the size.
    The proof has got some graphics code hardcoded in it - i.e. LINES AND POLYGONS have been hardcoded
    i need to reconfigure that such that everytime the user increases the size of the triagnle and clicks on next it draws the lines and polygons in the correct area and place
    PLEASE HELP
    the code is as follows
    MAIN CLASS
    import java.awt.BorderLayout;
    import java.awt.Container;
    import java.awt.*;
    import java.awt.event.*;
    import java.text.*;
    import javax.swing.*;
    public class TestProof {
        TestControl control;          // the controls for the visual proof
        TestView view;          // the drawing area to display proof
        // called upon class creation
        public TestProof() {
            view = new TestView();
    view.setBackground(Color.WHITE);
            control = new TestControl(view);
            Frame f = new Frame("Pythagoras");
            f.add(view,"Center");
            f.add(control,"South");
            f.setSize(600,600);
            f.setBackground(Color.lightGray);
            f.addMouseMotionListener(
            new MouseMotionListener() { //anonymous inner class
                //handle mouse drag event
                public void mouseMoved(MouseEvent e) {
                    System.out.println("Mouse  " + e.getX() +","  + e.getY());
                public void mouseDragged(MouseEvent e) {
                    System.out.println("Draggg: x=" + e.getX() + "; y=" + e.getY());
            JMenu File = new JMenu("File");
            JMenuItem Exit = new JMenuItem("Exit");
            Exit.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    ExitActionPerformed(evt);
            JMenuBar menuBar = new JMenuBar();
            menuBar.add(File);
       File.add(Exit);
            f.add(menuBar,"North");
            f.show();
        private JMenuBar getMenuBar() {
            JMenu File = new JMenu("File");
            JMenuItem Exit = new JMenuItem("Exit");
            Exit.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    ExitActionPerformed(evt);
            JMenuBar menuBar = new JMenuBar();
            menuBar.add(File);
                 File.add(Exit);   
            return menuBar;
        private void ExitActionPerformed(java.awt.event.ActionEvent evt) {
            // TODO add your handling code here:
            System.exit(0);
        // for standalone use
        public static void main(String args[]) {
      TestProof TP = new TestProof();
    }Test VIEW
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.geom.*;
    import java.text.*;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    public class TestView extends Canvas {
        int TRANSLUCENT = 1;
        int sequence;          // sequencer that determines what should be drawn
        // notes matter
        int noteX = 100;     // note coordinates
        int noteY = 60;
        int fontSize = 11;     // font size
        int lineSpacing     // space between two consecutive lines
        = fontSize + 2;
        Font noteFaceFont;     // font used to display notes
        // objects matter
        Polygon tri;          // right-angled triangle with sides A, B, and C
        Polygon tri1;
        Polygon sqrA;          // square with side of length A
        Polygon sqrB;          // square with side of length B
        Polygon sqrC;          // square with side of length C
        Polygon parA;          // parallelogram of base A and height A
        Polygon parB;          // parallelogram of base B and height B
        Polygon poly1;
        Polygon poly2;
        Polygon poly3;
        Polygon poly4;
        Polygon poly5;
        Polygon poly6;
        int X0 = 350;          // coordinates of triangle
        int Y0 = 350;
        int A = 90;//60;          // triangle size
        int B = 120;//80;
        int C = 150;//100;
        //CORDS of 2nd triangle
        int X1 = 350;
        int Y1 = 500;
        // notes: three lines per note
        String notes[] = {
            // note 0
            // note 1
            // note 2
            // note 3
            // note 4
            // note 5
            // note 6
            // note 7
            // note 8
            // note 9
            // note 10
            // note 11
            // note 12
            // note 13
            // note 14
        // constructor
        public TestView() {
            addMouseMotionListener(
            new MouseMotionListener() { //anonymous inner class
                //handle mouse drag event
                public void mouseMoved(MouseEvent e) {
                    System.out.println("Mouse  " + e.getX() +","  + e.getY());
                public void mouseDragged(MouseEvent e) {
                    System.out.println("Draggg: x=" + e.getX() + "; y=" + e.getY());
            // set font
            noteFaceFont = new Font("TimesRoman", Font.PLAIN, fontSize);
            // (coordinates specified w.r.t. to P0, unless otherwise specified)
            // create the triangle
            tri = new Polygon();
            tri.addPoint(0, 0);                    // add P0 coordinate
            tri.addPoint(A*A/C, -A*B/C);          // add A3 coordinate
            tri.addPoint(C, 0);                    // add C1 coordinate
            tri.translate(X0, Y0);               // place triangle
            tri1 = new Polygon();
            tri1.addPoint(0,0);                    // add P0 coordinate
            tri1.addPoint(A*A/C +38, +A*B/C);          // add A3 coordinate
            tri1.addPoint(C, 0);                    // add C1 coordinate
            tri1.translate(X1, Y1);
            // create square of side A
            sqrA = new Polygon();
            sqrA.addPoint(0, 0);               // add P0 coordinate
            sqrA.addPoint(-A*B/C, -A*A/C);          // add A1 coordinate
            sqrA.addPoint(-A*(B-A)/C, -A*(A+B)/C);     // add A2 coordinate
            sqrA.addPoint(A*A/C, -A*B/C);          // add A3 coordinate
            sqrA.translate(X0, Y0);               // place square
            // create square of side B
            // warning: the coordinate of this object are specified relative to C1
            sqrB = new Polygon();
            sqrB.addPoint(0, 0);               // add C1 coordinate
            sqrB.addPoint(B*A/C, -B*B/C);          // add B1 coordinate
            sqrB.addPoint(B*(A-B)/C, -B*(A+B)/C);     // add B2 coordinate
            sqrB.addPoint(-B*B/C, -B*A/C);          // add A3 coordinate
            sqrB.translate(X0 + C, Y0);               // place square
            // create square of side C
            sqrC = new Polygon();
            sqrC.addPoint(0, 0);               // add P0 coordinate
            sqrC.addPoint(C, 0);               // add C1 coordinate
            sqrC.addPoint(C, C);               // add C2 coordinate
            sqrC.addPoint(0, C);               // add C3 coordinate
            sqrC.translate(X0, Y0);               // place square
            poly1 = new Polygon();
            poly1.addPoint(405,279);
            poly1.addPoint(413,350);
            poly1.addPoint(432,500);
            poly1.addPoint(442,571);
            poly1.addPoint(500,500);
            poly1.addPoint(500,350);
            poly2 = new Polygon();
            poly2.addPoint(279,297);
            poly2.addPoint(404,280);
            poly2.addPoint(571,254);
            poly2.addPoint(500,350);
            poly2.addPoint(350,350);
            //Polygon 3
            poly3 = new Polygon();
            poly3.addPoint(404,280);
            poly3.addPoint(350,350);
            poly3.addPoint(414,350);
            poly4 = new Polygon();
            poly4.addPoint(350,350);
            poly4.addPoint(350,500);
            poly4.addPoint(442,572);
            poly4.addPoint(433,500);
            poly4.addPoint(414,350);
            poly5 = new Polygon();
            poly5.addPoint(476,183);
            poly5.addPoint(332,225);
            poly5.addPoint(278,295);
            poly5.addPoint(404,279);
            poly5.addPoint(571,254);
            poly6= new Polygon();
            poly6.addPoint(405,278);
            poly6.addPoint(332,224);
            poly6.addPoint(476,182);
            // create parallelogram of height A
            parA = new Polygon();
            parA.addPoint(0, 0);               // add P0 coordinate
            parA.addPoint(0, C);               // add C3 coordinate
            parA.addPoint(A*A/C, C - A*B/C);          // add Q0 coordinate
            parA.addPoint(A*A/C, -A*B/C);          // add A3 coordinate
            parA.translate(X0,Y0);               // place parallelogram
            // create parallelogram of height B
            // warning: the coordinate of this object are specified from C1
            parB = new Polygon();
            parB.addPoint(0, 0);               // add C1 coordinate
            parB.addPoint(-B*B/C, -B*A/C);          // add A3 coordinate
            parB.addPoint(A*A/C - C, C - A*B/C);     // add Q0 coordinate
            parB.addPoint(0, C);               // add C2 coordinate
            parB.translate(X0 + C, Y0);
            // place parallelogram
        // depending on the sequence number we draw certain objects
        public void paint(Graphics gfx) {
            super.paint(gfx);
            Graphics2D g = (Graphics2D) gfx;
            g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
            RenderingHints.VALUE_ANTIALIAS_ON);
            // text first, then objects (and animation)
            // we always output some notes
            g.drawString(notes[3*sequence], noteX, noteY);
            g.drawString(notes[3*sequence + 1], noteX, noteY + lineSpacing);
            g.drawString(notes[3*sequence + 2], noteX, noteY + 2*lineSpacing);
            // the object are drawn in an order so that they are properly overlapped
            if(sequence == 13) {
                g.setColor(Color.green);
                g.fillPolygon(poly1);
                g.fillPolygon(poly2);
                g.fillPolygon(poly3);
                g.fillPolygon(poly4);
                g.fillPolygon(poly5);
                g.setColor(Color.RED);
                g.setColor(Color.GREEN);
                g.drawLine(413,351,433,499);
                g.setColor(Color.white);
                g.fillPolygon(tri);
                g.fillPolygon(tri1);
                g.fillPolygon(poly6);
            if(sequence == 12 ) {
                g.setColor(Color.green);
                g.fillPolygon(poly1);
                g.fillPolygon(poly2);
                g.fillPolygon(poly3);
                g.fillPolygon(poly4);
                g.fillPolygon(poly5);
                g.setColor(Color.BLACK);
            if(sequence == 11){
                g.setColor(Color.green);
                g.fillPolygon(poly1);
                g.fillPolygon(poly3);
                g.fillPolygon(poly4);
                g.setColor(Color.BLACK);
            if(sequence == 8 ){
                g.setColor(Color.green);
                g.fillPolygon(poly5);
                g.setColor(Color.MAGENTA);
                g.drawString("E",578,254);
                g.drawString("D",268,302);
                g.setColor(Color.black);
                g.drawArc(250,150,350,250,320,65);
            else if (sequence == 9 ){
                g.setColor(Color.green);
                g.fillPolygon(poly2);
                g.setColor(Color.MAGENTA);
                g.drawString("E",578,254);
                g.drawString("D",268,302);
                g.setColor(Color.black);
                g.drawArc(250,150,350,250,320,65);
            if( sequence == 10){
                g.setColor(Color.green);
                g.fillPolygon(poly2);
                g.fillPolygon(poly5);
                g.setColor(Color.black);
                g.setColor(Color.MAGENTA);
                g.drawString("E",578,254);
                g.drawString("D",268,302);
                g.setColor(Color.black);
                g.drawArc(250,150,350,250,320,65);
            if(sequence == 7){
                g.setColor(Color.green);
                g.fillPolygon(poly2);
                g.setColor(Color.MAGENTA);
                g.drawString("E",578,254);
                g.drawString("D",268,302);
                g.setColor(Color.black);
            if(sequence == 6){
                g.setColor(Color.yellow);
                g.fillPolygon(poly2);
                g.setColor(Color.green);
                g.fillPolygon(poly3);
                g.setColor(Color.blue);
                g.fillPolygon(poly4);
                g.setColor(Color.black);
                g.drawArc(250,175,350,275,300,65);
                //g.drawArc(250,150,350,250,320,65);
                g.drawLine( 606,309,599,299);
                g.drawLine(592,313, 599,299);
                g.drawString("+90 degrees",605,378);
            if (sequence == 5 ) {
                g.setColor(Color.yellow);
                g.fillPolygon(poly2);
                g.setColor(Color.black);
            if (sequence == 4) {
                g.setColor(Color.YELLOW);
                g.fillPolygon(poly1);
                g.setColor(Color.black);
                g.drawArc(319,310,250,195,89,-35);
                g.drawLine(499,319, 492,312);
                g.drawLine(499,319, 492,325);
                g.drawArc(200,180, 233,238,-120,-60);
                g.drawLine(200,298, 208,309);
                g.drawLine(200,298, 194,313);
                g.drawString("-90 degrees",227,347);
            if (sequence >= 3) {
                g.drawLine(404,279,442,572);
            // draw the squares
            if (sequence >= 2) {
                g.drawLine(278,296,572,254);
            // draw the squares
            if (sequence >= 1) {
                g.drawLine(333,224,476,182);
                g.drawPolygon(tri1);
            // always draw the triangle
            g.drawPolygon(tri);
            g.drawPolygon(sqrA);
            g.drawPolygon(sqrB);
            g.drawPolygon(sqrC);
            g.setColor(Color.MAGENTA);
            g.drawString("C", X0 + C/2 - fontSize/2, Y0 + lineSpacing);
            g.drawString("A",
            X0 + A*A/(2*C) - fontSize*A/B/2,
            Y0 - A*B/(2*C) - lineSpacing*A/B);
            g.drawString("B",
            X0 + C - B*B/(2*C) - fontSize*A/B/2,// the last "-" isn't log.
            Y0 - B*A/(2*C) - lineSpacing*A/B);
        public void redraw(int sequence) {
            this.sequence = sequence;
            repaint();
    }TEST CONTROL
    * TestControl.java
    * Created on 28 February 2005, 11:16
    import java.awt.*;
    import java.awt.event.*;
    import java.text.*;
    import javax.swing.JFrame;
    * @author  Kripa Bhojwani
    public class TestControl extends Panel implements ActionListener {
      TestView view;
      int sequence;                    // event sequence
      // constructor
      public TestControl(TestView view) {
        Button b = null;
        Label label = new Label("A^2 ");
        this.view = view;          // initialize drawble area
        sequence = 0;               // initialize sequence
        b = new Button("Prev");
        b.addActionListener(this);
        add(b);
        b = new Button("Next");
        b.addActionListener(this);
        add(b);
        add(label);
      // exported method
      public void actionPerformed(ActionEvent ev) {
        String label = ev.getActionCommand();
        if (label.equals("Prev")) {
          if (sequence >0) {
         --sequence;
        else {
          if (sequence < 15) {
         ++sequence;
        this.setEnabled(false);          // disable the controls
        view.redraw(sequence);
        this.setEnabled(true);          // enable the controls
    }Please help --- really need to sort this out...
    THANKS

    Cross post http://forum.java.sun.com/thread.jspa?threadID=603432&messageID=3251958#3251958

  • AD/OD Golden Triangle problem

    Hello everyone.
    I am having a weird problem with my AD/OD integration, let me give you some background on what is going on.
    I have a DC running windows 2003, I installed a new version of 10.5.6 server on a brand new Xserve. Initially I installed the standard configuration of the server and then i went into the Advanced server. I checked the DNS, forward and reverse works fine. Basically I am able to login to AD accounts fine, i can point to network home folders, authentication works just like its supposed to except...my MCX preferences are not taking effect. I am trying to push out MCX prefs for each machine, machine group, user and user groups, none of them work. I am also getting a "network account are unavailable" with a yellow dot at start up. I changed some settings in the Directory Access application to see if it will make a difference but it doesn't. Also, when i try to unbind the machine I am getting a message "Could not contact the LDAP server...." I checked the log files and the only thing that seems out of place is "GSSAPI Error: Miscellaneous failure (Server not found in Kerberos database)" I am kind of stuck, i would like to roll this out for production but without the ability to push out mcx settings makes no sense. If anyone could chime in with opinions and hopefully a solution i would greatly appreciate it. Thanks in advance.

    When Macintosh Management started out the trend was to manage on the group. This continued when MCX came along. Now the trend is more towards managing Computer Groups on a location basis. You can then build workgroups on top of that if you need them. Some environments are fine with just management on the Guest computer record.
    Honestly you would find this all child's play if you'd been through the books I referenced... or taken the training courses. It explains everything and tells you how to bring everything together.
    Kerberos probably won't be the problem as it won't block delivery of the MCX settings. They come through LDAP. You really want to learn how to use dscl to see what Mac OS X sees when it reads your LDAP. If dscl sees everything then normally it should be working. If dscl gets stuck somewhere it tells you something is wrong.

  • Simple button re-ordering problem

    I understand that changing the button order on a menu is simple - either use the shortcuts on the canvas, right click the button, etc. But for the life of me, no matter which way I try (including even trying to re-order through the drop-down menu), the button order will not change. What am I missing....?
    Thanks.

    Nope, you can get it to work. Make sure you do not Auto Assign continuously option was checked (when you pulldown make sure there is no check mark)
    Note that if you DO use auto assign now the buttons do get assigned in the order they were created so if you make three buttons in a column, Button 1, then Button 2 then decide to add Button 3 and place it between 1 and 2 auto assigning now will make it 1,2,3 (top, bottom, middle)
    Not sure how many buttons you made, but you can assign them manually in the inspector for left/right/up/down, though sometimes it is easier to delete all the buttons and make them in the order you want (usually that is easier when you are using overlays, if you made buttons in DVD SP, which it sounds like, you may want to just assign them manually)

  • So simple, yet so annoying: problem resizing anchored frame with grab bars

    Asked a question yesterday on how to 'snug' an anchored frame to an image. Got the answer and it works great (Esc-m-p)
    Now... the reason I needed to do this is that when I try to resize a frame with the grab bars, it 'jerks' as I move vertically or horizontally.
    What that means is...
    With borders on, the frame border is a dotted line.
    If I grab the left side of a frame and move my mouse to the right to make the frame smaller, the border doesn't move smoothly -- it jumps a distance of about 1.5 of those dotted lines. Thus I can't always make the frame fit nicely.
    Talked to another Frame user and she said that her's drags smoothly.
    So... am I missing a setting somewhere? Any thoughts would be greatly appreciated.

    ##&*!
    I was working over a VPN when I first experienced the problem... everything was slower than molasses. Set Snap off, did some other work, Frame crashed.
    Setting didn't persist, but everything had taken so long I forgot to check it.
    Gah. Yes, Snap off works wonders when it's *actually* off.

  • DeviceManager, simple but I have problem (Please helllp)

    I'm trying to capture live stream from my pc camera (Intel(r) PC CS120) but capturedevicemanager returns null, here is one of my try
    RGBFormat rgbFormat = new RGBFormat();
    CaptureDeviceInfo cdi;
    cdi = CaptureDeviceManager.getDevice("Intel(r) PC Camera CS120");
    cdi is null after execution of above code
    I tried
    RGBFormat rgbFormat = new RGBFormat();
    Vector videoDevs = CaptureDeviceManager.getDeviceList(rgbFormat);
    but the videoDevs.size returns zero???
    Could you please assist me in what I have to do
    I checked the pc camera format is "RGB 24" ... I'm new to this capture device concept... so I would really appreciate your help...
    Thanx

    Check this out. It could help.
    http://java.sun.com/products/java-media/jmf/2.1.1/solutions/JVidCap.html
    I think it could be caused by the Format problem.
    The sample use the CaptureDeviceManager like this:
    Vector devices;
    CaptureDeviceInfo cdi;
    // Find devices for format
         devices = CaptureDeviceManager.getDeviceList(format);
         if (devices.size() < 1) {
         System.err.println("! No Devices for " + format);
         return null;
         // Pick the first device
         cdi = (CaptureDeviceInfo) devices.elementAt(0);
    Good luck.
    Jim

  • Simple vector transparency - printing problems

    Morning everybody,
    I'm having problems printing a PDF which has been generated from Indesign CS3.  The problem also arises when printing directly from Indesign.  Everything appears OK when on screen.
    I have a background colour, in front of which i have placed an Illustrator CS3 file which is a row of white squares with gaps (transparent) between then.  The squares are white, but I really want them to fade from a hue of the background colour to fully transparent.  To achieve this I have used a gradient feather, going from opacity 50% to opacity 0%.  [See sceenshot]
    My problem is that all the squares show up when I print the file, even the ones which should have an opacity level of 0%.  On the printout the gradient feather is visible (i.e. the squares 'fade out'), but they do not compeltely fade out to fully transparent. 
    Does anyone have any tips? 
    Thanks very much for any help with this. 
    Robin

    Thanks a lot for your reply.
    I don't have a brilliant understanding of colour, but I believe that all the colours in the document are process [see screenshot].
    Turning on overprint preview doesn't change the appearance of the document.  Nor does turning on simulate overprint in acrobat.  In both cases, the appearance of the document on screen is how i want it to print.

Maybe you are looking for

  • Redacting a document - save feature

    I am currently using Adobe Acrobat Pro v. 10.1.8 and have a question about the save feature.  After I have used the redacting tool and applied the changes, I click on save (either File -> Save or the actual save icon on the toolbar) and it automatica

  • Query on ABAP List Viewer and Table Control?

    Hi all, I was trying to solve the exercises in these areas....but was unable to do as some of the concepts were not clear to me as I'm new to this field. So Can any one help me out in giving me the Notes or attachments on the ABAP List Viewer(A.L.V.)

  • Truncation words in SQL seperated by Pipe Symbol

    Hi All, I have a String like this: "6.362636.10|6.362636.10.00.100000|o123456789123|1122334455|PrepaidRecharge|30.00|CC|AMERICANEXPRESS". I need to take each string seperated by pipe symbol and export to seperate columns using SQL. Kindly help me in

  • IPhone Activation Lock Apple ID not mine.

    Hello, I'm going to start out from the beginning, I decided to delete my iCloud account a few days ago for no apparent reason, but I saw that deleting my iCloud account deleted my contacts as well. I tried to restore to an old backup on my PC in iTun

  • I can't see any of the work spaces in iMovie

    Hello, When I'm opening iMovie although I can see and use all the controls in the top panel, none of the work spaces are opening. I've been google-ing the problem for the last half an hour and it seems like a really common problem but I haven't found