Pythagoras integer sides triangle

Absolute beginner needs tips!!
I need to make a program that gives me triangles with only integer numbers using a2+b2=c2.
Here's my code, it works but it gives me double results as you can see. How can I improve, just using code I already now? (loop statements, conditions etc..)
Thanks for any tips
// Ex. 5.21 Pythagorian triples
public class Pythagorian
public static void main( String args[] )
int a = 0;
int b = 0;
int c = 0;
for( a = 1 ; a <= 9 ; a++ )
for( b = 1 ; b <= 9 ; b++ )
for ( c = 1 ; c <= 100 ; c ++)
if ((c*c)==(a*a + b*b))
System.out.printf( "A is %d and B is%d and C is %d\n" , a , b, c);
} // end b
} // end a
} // end main
} // end class

I assume you are getting both:
3 4 5
and
4 3 5
Make your 'b' loop only process numbers that are equal or greater than 'a' ('equal' won't give you a Pythagorean triple, anyway, so you could probably skip it).

Similar Messages

  • Histogram triangles

    I think, these triagles are getting colors according to the color distribution of the images.
    The white triangles are represents for the clipping.
    What about the other colors? I mean, as an example, when the highlight triangle is getting the yellow color? And when the shadow side triangle is getting its blue color? is it possible to read the color intensity thru this triagle colors? is it possible to correct the color precisely by looking this triangle colors.

    salute.....
    Brilliant answer...
    Thousands of people are interested to read and comment about anything bad about Lirghroom... They won't sleep before at least read it once.
    Look at here....are they seen this question? 10 of them, 15 of them.  Interesting is (this subject) it never talked anyone at any books or any video tutorials.  I have fully read almost all books about Lightroom, I have seen many video tutorials. Almost I have prepared to do the ACE exam for the LIghtroom.. waiting for the lightroom 3 ACE..
    One of my questions: is it possible to read the color intensity thru this triangle colors?
    (100% agreed with you. my question is not clear)
    What I mean is: the highlight triangle is getting yellow color.  as you already said, the red and green channels were clipped.
    I know very well how to clear the clippings without touching the integrity of the image. My question is, under HSL module, should we able to do anything with the red and green tabs before starting the traditional remedies to correct the subject clipping"
    I would like to take this opportunity to tell all the Lr fans about a good book that is not a traditional one. It will open for you a different experience.
    If you carefully go thru the provided 20 .dng files and follow his way with Lightrom you will master the software. Thru first five chapters he shared all his vision and voice (he said, he took 20 years of shooting to get his vision). It is a poetry... if you read it more you will get it more and more...(first 5 chapters).
    I did not read his first two books, Within the frame and VisionMongers. What I mean, this is not a hidden agenda to sell his book. There is no connection between me and the said author.  All Lightroom books are made by painful efforts and that are created with vast knowledge. But some times some one will better than others.  It is not a Lightroom tutor. As he said, inside the book, if you want to study the software please go and by Mr Kelby's Lightroom book. I sincerely recommend to buy this book to all those who wants to Lr one step ahead than usual. Let me salute for Mr. David duChemin.
    Book: VISOIN & VOICE
    Author: David duChemin

  • Pythagorean triples complex squares

    While working on a math problem recently that involved Pythagorean Triples I spotted a connection with the complex numbers that I had never noticed previously. It is a trivial observation and I was surprised that in my many years as a mathematician I had never heard anyone mention this little fact. I am curious if this little fact is well known to others and I just happened to miss it or if it really is unknown to most folks.
    A Pythagorean triple is a set of three integers like 3,4,5 that make a right triangle with integer sides. Being a right triangle the numbers fit the Pythagorean theorem, a^2 + b^2 = c^2 and sho nuff 9 + 16 = 25
    Euclid has a proof that is presented in the Elements that all Pythagorean triples can be generated from two integers s, and t by means of these formulae
    a = 2st
    b = s^2 - t^2
    c = s^2 + t^2
    It is fairly easy to use algebra to square a and b using those formulae and see that these numbers do in fact form a Pythagorean triple. It is only slightly more difficult to go the other way and show that all triples are of this form.
    So all of this is ancient history - known to Euclid.
    Now let us take a complex number, c = a + bi. Let it be a complex integer, meaning that a and b are actually integers. Viewed from the complex plane, the complex number c represents a little right triangle, one leg is the real part, one leg is the imaginary part and the hypotenuse is the norm of the complex number c i.e.
    |c| = sqrt(a^2 + b^2)
    Clearly because of the square root sign the norm of c is not necessarily an integer and thus the triangle a,b,c is not necessarily a Pythagorean triple. However just square the complex number c
    (a + bi)*(a + bi) = (a^2 - b^2) + (2ab)i
    Notice anything about the form of a perfect square in the complex plane and Euclid's characterization of a Pythagorean triple? One leg is a difference of squares the other is twice the product of the two numbers.
    They are one and the same. The Pythagorean triples are just exactly the perfect squares in the complex plane.
    So for example (2 + i) is not a square and is not a Pythagorean triple. Its norm is sqrt(5). but if you square it, you get (3 + 4i) whose norm is 5.
    That is the observation. Nothing difficult. Perfectly obvious. Every mathematician from Euclid on knows about right triangles and everyone since Gauss has been able to multiply two complex integers. It is about as easy as math gets. I was astonished that in years as a working mathematician I had never noticed this nor heard anyone mention this simple fact.
    Yes, I know - you're thinking that the reason this never came up in conversation is because this observation is totally irrelevant and practically useless, but that has never stopped mathematics. Just ask any mathematician to tell you about paracompact Hausdorff spaces and listen to an amazing tirade of irrelevant and practically useless information.
    The Pythagorean triples are just the perfect squares in the complex plane.
    Just for grins Google 'Pythagorean triples "complex squares"' to see a Google search that returns but a single result. Hole in one. except that it is not about the result that I just mentioned.
    I make no claim that any of this is original, I am only flabbergasted at my ignorance and am casting out to see if I was just asleep the day they covered this in high school or if this really is a rather obscure and little known even if trivial observation.
    There is nothing left to say but to ask the survey questions
    1) Did you know this before you read it here?
    2) If you did know it, was it shown to you or did you discover it yourself?
    Enjoy!

    You are so correct Jos, you can have a common prime root in the legs. Euclid's formula was for the primitive triples.
    I had run into a triple in a problem that I was playing with, remembered that there was a characterization in Euclid and while skimming it noticed that it looked exactly like a squared complex number. This would explain the lack of finding this fact noted on the various math sites - the mere fact that it isn't really true.
    The connection to the complex plane is real but as you say the complex squares are the pirmitive triples not all of them.
    Of course, if I were a good mathematician I would pretend that I knew that all along and in a disgusted tone utter, "Do you take me for some kind of fool? Obviously I meant 'primitive' because it isn't true otherwise."
    These days I am closer to fool than to a good mathematician.
    I am very glad that you pointed this out. The problem I was working on required triples and I was about to limit my considerations to just the primitive ones when in fact a non-primitive one could do.
    Domo arigato gozaimashita!

  • Adding a JPanel from one class to another Class (which extends JFrame)

    Hi everyone,
    So hopefully I go about this right, and I can figure out what I'm doing wrong here. As an exercise, I'm trying to write a Tic-Tac-Toe (TTT) game. However, in the end it will be adaptable for different variations of TTT, so it's broken up some. I have a TTTGame.java, and TTTSquareFrame.java, and some others that aren't relavent.
    So, TTTGame:import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import joshPack.jUtil.*;
    public class TTTGame extends JFrame
         private Integer sides = 3;
         private TTTSquareFrame mainSquare;
         private TTTGame newGame;
         private Container contents;
         private JPanel mainSquarePanel, addPanel;
         public static void main(String [] args)
              TTTGame newGame = new TTTGame();
              newGame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         public TTTGame()
              super("Tic-Tac-Toe");
              contents = getContentPane();
              contents.setLayout(new FlowLayout());
              addPanel = startSimple();
              if(!addPanel.isValid())
                   System.out.println("Something's wrong");
              contents.add(addPanel);
              setSize(300, 300);
              setVisible(true);
         public JPanel startSimple()
              mainSquare = new TTTSquareFrame(sides);
              mainSquarePanel = mainSquare.createPanel(sides);
              return mainSquarePanel;
    }and TTTSquareFrame:import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import joshPack.jUtil.Misc;
    public class TTTSquareFrame
         private JPanel squarePanel;
         private JButton [] squares;
         private int square, index;
         public TTTSquareFrame()
              System.out.println("Use a constructor that passes an integer specifying the size of the square please.");
              System.exit(0);
         public TTTSquareFrame(int size)
         public JPanel createPanel(int size)
              square = (int)Math.pow(size, 2);
              squarePanel = new JPanel();
              squarePanel.setLayout(new GridLayout(3,3));
              squares = new JButton[square];
              System.out.println(MIN_SIZE.toString());
              for(int i = 0; i < square; i++)
                   squares[i] = new JButton();
                   squares.setRolloverEnabled(false);
                   squares[i].addActionListener(bh);
                   //squares[i].setMinimumSize(MIN_SIZE);
                   squares[i].setVisible(true);
                   squarePanel.add(squares[i]);
              squarePanel.setSize(100, 100);
              squarePanel.setVisible(true);
              return squarePanel;
    }I've successfully added panels to JFrame within the same class, and this is the first time I'm modularizing the code this way. The issue is that the frame comes up blank, and I get the message "Something's wrong" and it says the addPanel is invalid. Originally, the panel creation was in the constructor for TTTSquareFrame, and I just added the mainSquare (from TTTGame class) to the content pane, when that didn't work, I tried going about it this way. Not exactly sure why I wouldn't be able to add the panel from another class, any help is greatly appreciated.
    I did try and cut out code that wasn't needed, if it's still too much let me know and I can try and whittle it down more. Thanks.

    Yea, sorry 'bout that, I just cut out the parts of the files that weren't relevant but forgot to compile it just to make sure I hadn't left any remnants of what I had removed. For whatever it's worth, I have no idea what changed, but something did and it is working now. Thanks for your help, maybe next time I'll post an actual question that doesn't somehow magically solve itself.
    EDIT: Actually, sorry, I've got the panel working now, but it's tiny. I've set the minimum size, and I've set the size of the panel, so...why won't it respond to that? It almost looks like it's being compressed into the top of the panel, but I'm not sure why.
    I've compressed the code into:
    TTTGame.java:
    import java.awt.*;
    import javax.swing.*;
    public class TTTGame extends JFrame
         private Integer sides = 3;
         private TTTSquareFrame mainSquare;
         private TTTGame newGame;
         private Container contents;
         private JPanel mainSquarePanel, addPanel;
         public static void main(String [] args)
              TTTGame newGame = new TTTGame();
              newGame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         public TTTGame()
              super("Tic-Tac-Toe");
              contents = getContentPane();
              contents.setLayout(new FlowLayout());
              mainSquare = new TTTSquareFrame(sides.intValue());
              contents.add(mainSquare);
              setSize(400, 400);
              setVisible(true);
    }TTTSquareFrame.java
    import java.awt.*;
    import javax.swing.*;
    public class TTTSquareFrame extends JPanel
         private JButton [] squares;
         private int square, index;
         private final Dimension testSize = new Dimension(50, 50);
         public TTTSquareFrame(int size)
              super();
              square = (int)Math.pow(size, 2);
              super.setLayout(new GridLayout(size, size));
              squares = new JButton[square];
              for(int i = 0; i < square; i++)
                   squares[i] = new JButton();
                   squares.setMinimumSize(testSize);
                   squares[i].setVisible(true);
                   super.add(squares[i]);
              setSize(200, 200);
              setVisible(true);
    I've made sure the buttons are smaller than the size of the panel, and the panel is smaller than the frame, so...
    Message was edited by:
    macman104

  • Action method called in standalone OC4j but not OAS

    I am setting up a test environment on Solaris x86 machine and have run into an odd issue concerning an action method being called which seems to be an issue for Oracle Application Server (OAS) but not an issue for stand alone OC4J.
    The application is using Java 5, Spring 2.5, Java Servlet 2.3, Struts 2, iBatis 2.2, Sitemesh, and Display Tag to name some of the parts that are in play.
    The platform is a Sun Fire X2100 server running Solaris 10 OS (64-bit). The application server version is 10.1.3 (Solaris x86, 64-bit) connecting to Oracle database server 10.2.0.2.0 (Solaris x86, 32-bit). The stand alone OC4J that I used for comparison was 10.1.3.4.0 (also run under the same Solaris machine but not while the application server was running).
    Going from one JSP that contains a list of items ("authority ids" in this case) to another JSP which displays detailed information about one item (chosen by clicking on a hyperlink in the list), it appears that the setter action method (which sets the 'sid' property) does not get called under OAS so the page displays empty fields. Same code running under the stand alone OC4J, the setter method does get called and the fields are populated on the details page. In both cases, both deployments are hitting the same database and the data is successfully retrieved from the database (into the action class). In both cases, the parameter that is set by this action method is present in the URL for the detail page.
    Snippet of code from the JSP that loads the authority ID list (and passes the sid in the URL):
    <display:table name="authorityIdList" cellspacing="0" cellpadding="0" requestURI=""
        defaultsort="1" id="authorityIdTypes" pagesize="25" class="table" export="true">
        <s:url id="editurl" action="editAuthorityId" includeContext="false">
          <s:param name="redirectUrl" value="%{returnUrl}"/>
        </s:url>
        <display:column property="fieldName" escapeXml="true" sortable="true" titleKey="authorityIdType.fieldName"; style="width: 34%" url="${editurl}"
          media="html csv xml excel pdf" paramId="sid" paramProperty="sid"/>Snippet from the authority ID detail form where the sid should be populated:
    <tr style="display: none"><td>
          <s:hidden key="sid"/>
            <s:hidden name="redirectUrl"/>
        </td></tr>Snippet from the action class that contains the setter for the sid property:
      public Integer getSid() {
            return sid;
      public void setSid(Integer sid) {
            this.sid = sid;
      }Snippet from the resulting html page for the list includes the sid for each item in the list.
    <td style="width: 34%">DODAAC</td>
    <td style="width: 25%">DODAAC</td></tr>
    <tr class="even">
    <td style="width: 34%">DODAAN</td>
    <td style="width: 25%">DODAAN</td></tr></tbody></table>Under the stand alone OC4J, the setter method is called, so the sid is populated (and the item detail data from the action is retrieved and displayed).
    Snippet from the resulting detail html page from the stand alone OC4J:
        <tr style="display: none"><td>
             <input type="hidden" name="sid" value="1" id="saveAuthorityId_sid"/>
            <input type="hidden" name="redirectUrl" value="http://system01:8888/MyApp/admin/authorityIdTypes.html"; id="saveAuthorityId_redirectUrl"/>
        </td>Notice that the sid value as well as the redirectUrl value are populated under standalone OC4J.
    Under OAS, the setter method is not called, so the sid is not set (and none of the other item detail fields are populated).
    Snippet from the resulting detail html page from OAS:
       <tr style="display: none"><td>
             <input type="hidden" name="sid" value="" id="saveAuthorityId_ sid"/>
            <input type="hidden" name="redirectUrl" value="" id="saveAuthorityId_redirectUrl"/>
        </td>Notice that the sid value as well as the redirectUrl value are empty under OAS.
    Any ideas on what I need to change in OAS configuration to make this work under OAS (if this is a configuration issue)?

    I found another case that may be clearer.
    A confirmation page on the application server shows that the redirect url is not being populated:
    <form id="confirmation" name="confirmation" onsubmit="return true;" action="/MyApp/admin/confirmation.html" method="post"><table class="wwFormTable">
         <input type="hidden" name="redirectUrl" value="" id="confirmation_redirectUrl"/>
       <tr>
        <td colspan="2"><div align="right"><input type="submit" id="confirmation_continue" name="method:proceed" value="Continue"/>
    </div></td>
    </tr>
    </table></form>Same code running on the standalone OC4j does populate the redirect URL:
    <form id="confirmation" name="confirmation" onsubmit="return true;" action="/MyApp/admin/confirmation.html" method="post"><table class="wwFormTable">
         <input type="hidden" name="redirectUrl" value="http://system01:8888/MyApp/admin/users.html" id="confirmation_redirectUrl"/>
       <tr>
        <td colspan="2"><div align="right"><input type="submit" id="confirmation_continue" name="method:proceed" value="Continue"/>
    </div></td>
    </tr>
    </table></form>So it appears that the application server is having problems passing parameters to pages.
    I have been digging through Oracle documentation, but I haven't found any clues on how to fix the issue.
    Any help would be appreciated.
    Thanks,
    - David

  • Development of Hibernate Artifacts

    Sir
    I have made use of MySql databse profile to interact with databse.
    I m making use of Hibernate to deal with databse.
    the problem is that when i m generating Hibernate artifacts, in Mapping file & Pojo classes there doesn't exist any relation b/w 2 tables. (i.e, one to many or vice-versa) but for oracle profile it is working fine.
    sql query used for tables
    create table student(sid integer primary key,sname varchar(10),age integer);
    create table studaddress(studaddr integer,sid integer references student(sid),state varchar(10));
    In Pojo classes there is no method with name setStudent (in Studaddress.java ) &
    In Pojo classes there is no method with name setStudaddresses (in Student.java )
    Its my first Query to u .
    Hope u will respond

    you did something wrong with the mysql setup.
    if you can't find a bug report on hibernate that relates to your problem, i'd assume that you made a mistake. if you're just learning, it's more likely that you've misunderstood something.
    can't tell unless you post more artifacts.
    perhaps best to take up with the hibernate forum.
    %

  • Read the name of a parent node of a (static) Tree UI in WebDynPro Abap

    hi Experts,
    I have a tree control UI that has two levels of nodes from the Root node. Year & Month. Inside the Month Node there is always only one leaf that is called Current Schedule. User clicks on Current Schedule to view the Current Schedule. This could be any month's Current Schedule of the User's choice.
    Thus, I need to know which month's current schedule is chosen by the user. My tree UI is an adaptation from WDT_TREE example from Std SAP example programs. For the chosen month to be known, I have to go up in the context node hierarchy by one level? (something like, get_parent of) from the current leaf. I am not sure how would i do it. Any pointers would be greatly helpful. I tried to pick up ideas from couple of tutorials and bunch of forum posts but I did not get anywhere.
    The key to my requirement is just going up one level in the tree and get to know the 'name' of that node. That will tell me the Month of the User's choice.
    Thanks in advance for your helpful answers/pointers

    Thanks Bala Duvvuri,
    Could you please elaborate a bit more on your tip. I am a fledgling OO abapper not 'really' knowing as much OO as I should ..!!
    By the way,I found out, I could apply the same OnAction method in the WDT_TREE example shown at the final leaf level to the node level as well to read the text of Month Node. It worked out and it meets my purpose with a rider..!
    In order to get this Month node text for the selected 'Current Schedule' leaf, User have to click on the Month Node that opens the Current Schedule Leaf. If they clicked on the triangle beside the node, it still opens the Month Node to reveal the Current Schedule leaf, but the Month name wont be captured until User expressly clicked on Month Node first or the Folder Icon associated with it..!!
    In other words, User cannot click on the left side triangle;  if they did to reach the Current Schdule, the program wont work properly. This is no good, though i could talk my way through with the User to accept this. But technically i know it is possible to know the month name from a given Current Schedule leaf in the tree,though dont know how ..!!
    Your bit more detailed reply would help me implement the more elegant solution than pushing the user to accept what i did.
    As I await your reply i shall try to pick up from your tip.
    In the meanwhile my tree has grown ..!! to have two more nodes, in which the contents need to be dynamically populated. Guess I am in for a long haul with the Tree UI
    Looking to hear more. Thanks heaps again.

  • Some basic PL/SQL quesions

    Hi,
    I am new to Oracle world and I need some helps:
    I need to run a lengthly ctx_ddl.sync_index procedure in our 10g R2 production environment, and I want to start the procedure at night and kill the session early in the morning next day.
    I am having trouble in writing the PL/SQL procedure to kill the session that is running the sync index:
    Here is my try:
    CREATE OR REPLACE PROCEDURE KILL_SESSION
    AS
    MYSID INTEGER; //SID OF THE SESSION CALLING THIS PROCEDURE
    KILLSID INTEGER; //SID OF THE SESSION THAT IS RUNNING THE SYNC INDEX
    KILLSERIAL INTEGER; //SERIAL# OF THE SESSION THAT IS RUNNING THE SYNC INDEX
    BEGIN
    SELECT DISTINCT(SID) INTO MYSID FROM MY V$MYSTAT;
    ^ ^^^ V$MYSTAT COMPILATION ERROR - NO SUCH TABLE OR VIEW
    SELECT SID INTO KILLSID, SERIAL# INTO KILLSERIAL FROM V$SESSION WHERE SID NOT IN (MYSID) AND OSUSER='SYS_ADMINISTRATOR';
    ^ ^^^ V$SESSION COMPILATION ERROR - NO SUCH TABLE OR VIEW
    ALTER SYSTEM KILL SESSION 'KILLSID, KILLSERIAL';
    ^^^^^^^ CAN I USE VARIABLE NAME INSIDE A SINGLE QUOTE??????
    END KILL_SESSION;
    Any help is appreciated !

    Hi,
    Welcome to the forum!
    When you post code on this site, make sure it is formatted, and type these 6 characters
    &#123;code&#125;
    (small letters only, inside curly brackets) before and after formatted text, to preserve spacing.
    When you post error messages, cut and paste the entire message. Somethimes, the message number and the line/cloumn number are helpful.
    Vg is right: there's something fundamentally flawed with a job that you have to kill.
    Can you sub-divide the job, and do a different part each night?
    A KILL procedure is handy in any case. As Vg said, you (the procedure owner) have to have privileges granted directly to you. Roles don't count inside stored procedures, so merely having a role that lets you query the data dictionary views is not enough.
    Also, you may need privileges granted on the actual V_$ views, rather than the V$ synonyms. (That is, V$MYSTAT, without an underscore, is just a public synonym for the view SYS.V_$MYSTAT, with an underscore in its name. You want to GRANT SELECT ON V_$MYSTAT to proc_owner;)

  • Dynamically adding a row in a table in JSF

    Hi All,
    I am searching for a control in JSF using which I can dynamically add more than one row in a table. Currently I am handling this in javasript where I have to click on the "Add Row" button to add one more row at the bottom of the table. I want to get rid of javascript.
    If anyone knows about such control then please help me.
    Thanks in advance.
    Regards,
    Saket

    hello Saketh,
    here is the code for Create Delete Update code where a row is added for every button click..and the JSF code is at the bottom.. today u r blessed with ocean. :-) have fun!!
    package redrose;
    import net.sf.hibernate.Session;
    import net.sf.hibernate.Transaction;
    import net.sf.hibernate.Query;
    import javax.faces.model.DataModel;
    import javax.faces.model.ListDataModel;
    public class RowEntry {
         private DataModel datamodel = null;
         static Integer sid;
         private Medata mdobject = null;
         private Medata nm=null;
          * @return Returns the newMdobject.
         public Medata getNm() {
              nm = new Medata();
              return nm;
          * @param newMdobject The newMdobject to set.
         public void setNm(Medata newMdobject) {
              this.nm = newMdobject;
          * @return Returns the mdobject.
         public Medata getMdobject() {
              return mdobject;
          * @param mdobject The mdobject to set.
         public void setMdobject(Medata mdobject) {
              this.mdobject = mdobject;
         public DataModel getDatamodel()
              datamodel = new ListDataModel();
              Session hibSession;     
              try{
                   hibSession = HibernateSessionFactory.currentSession();
                   Query q = hibSession.createQuery("FROM Medata");                    
                   q.setMaxResults(9999);
                   datamodel.setWrappedData(q.list());
              catch(Exception ex){
                    System.err.println("%%%% Error GetData %%%%");
                    ex.printStackTrace();
              return datamodel;
          * Inserting a new Record by reading from Client
         public void insertEntry()
                  Transaction tx = null;
                   Session session = null;
                   try{
                        session = HibernateSessionFactory.currentSession();
                        tx = session.beginTransaction();
                        Medata     dbmedata = new Medata();
                             dbmedata.setEmploy(nm.getEmploy());
                             session.save(dbmedata);
                        tx.commit();
                        session.close();
                   catch(Exception ex){
                        System.err.println("%%%% Modify Data %%%%");
                        ex.printStackTrace();
          * Modify data
         public void updateEntry()
              int a =0;
             if (this.datamodel == null) return;
             Medata mdupdate = (Medata) this.datamodel.getRowData();
             if (mdupdate == null ) return;
              Transaction tx = null;
              Session session = null;
              try{
                   session = HibernateSessionFactory.currentSession();
                   tx = session.beginTransaction();
                   Medata dbmedata = (Medata) session.load(Medata.class,mdupdate.getId());
                   if (dbmedata != null){ // we have to update the record
                        dbmedata.setEmploy(mdupdate.getEmploy());
                        session.update(dbmedata);
                   else // we have to insert the record
                        dbmedata = new Medata();
                        dbmedata.setEmploy(mdupdate.getEmploy());
                        session.save(dbmedata);
                   tx.commit();
                   session.close();
              catch(Exception ex){
                   System.err.println("%%%% Modify Data %%%%");
                   ex.printStackTrace();
          * Delete Data
         public void removeEntry()
             if (this.datamodel == null) return;
             Medata mdupdate = (Medata) this.datamodel.getRowData();
              Transaction tx = null;
              Session session = null;
              try{
                   session = HibernateSessionFactory.currentSession();
                   tx = session.beginTransaction();
                   Medata dbmedata = (Medata) session.load(Medata.class,mdupdate.getId());
             if (mdupdate == null ) return;
                   if (dbmedata != null){ // we have to update the record
                        session.delete(dbmedata);
                        tx.commit();
              catch(Exception ex){
                   System.err.println("%%%% Delete Data %%%%");
                   ex.printStackTrace();
    Here starts the JSF code
    <%@ page language="java" %>
    <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
    <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
    <%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
         <base href="<%=basePath%>">
         <title>My JSF 'trial.jsp' starting page</title>
         <meta http-equiv="pragma" content="no-cache">
         <meta http-equiv="cache-control" content="no-cache">
         <meta http-equiv="expires" content="0">   
         <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
         <meta http-equiv="description" content="This is my page">
         <!--
         <link rel="stylesheet" type="text/css" href="styles.css">
         -->
    </head>
    <body>
         <f:view>
              <h:form>
         <h:dataTable border="3" value="#{bla.all}" var="currentRow">
                          <h:column>
                            <f:facet name="header">
                                 <h:outputText value="Employee Name" />
                            </f:facet>
                  <h:inputText value="#{currentRow.employ}">
                            </h:inputText>
                       </h:column>
                          <h:column>
                            <f:facet name="header">
                                 <h:outputText value="Employee Number" />
                            </f:facet>
                            <h:inputText value="#{currentRow.id}"></h:inputText>
                       </h:column>
                       <h:column>
                       <f:facet name="header">
                       </f:facet>
                       <h:commandButton id="Delete" action="#{bla.insert}" value="Delete"></h:commandButton>
                  <h:commandButton id="Modify" action="#{bla.modify}" value="Modify"></h:commandButton>
                       </h:column>
                  </h:dataTable>
                   <h:commandButton id="Insert" action="#{bla.insert}" value="Insert"></h:commandButton>
               <%--h:outputText value="#{bla.sid}"></h:outputText--%>
               </h:form>
         </f:view>
    </body>
    </html>
    Faces-config file starts here
    <managed-bean>
              <description>Inserts a record</description>
              <managed-bean-name>bla</managed-bean-name>
              <managed-bean-class>redrose.RowEntry</managed-bean-class>
              <managed-bean-scope>session</managed-bean-scope>
         </managed-bean>     
         

  • Possible Loss of Precision

    /* * * * * * * * * * * method quadtratize * * * * * * * * * * * * * * * *
    * Method to convert rectangle into a square with approximately the same
    * area - the closest possible for a square with an integer side.
    public int quadratize()
         double recArea = Math.sqrt (myWidth * myHeight);
         double lenSide = recArea / 4;
         return lenSide;
    i need to square root the recArea and round to nearest int. This is what i have so far, but it won't compile because it has a possible loss of precision. any suggestions on how to fix it?

    milanocookies wrote:
    did this.Did what? Your code is the same
    do i change everything to int?It depends on what you are trying to achieve. Is your method supposed to return an int or a double? If double then you need to change your method signature. If int then you need to do what I already said and cast your variable to an int before you return it. If you don'tknow what I mean by "cast" then perhaps you could read about it in your textbook.

  • ASCII vs. TDMS

    I have this big packet that claims TDMS files are smaller than ASCII files.
    I have a 4x36790 array that i save to an ascii file and tdms file.  The ascii file (862 kb) is significantly smaller than the tdms file (1.12 mb).  
    Can anyone offer an explanation why this NI chart is not supporting my findings?
    Message Edited by elset191 on 05-08-2009 03:42 PM
    Tim Elsey
    LabVIEW 2010, 2012
    Certified LabVIEW Architect
    Solved!
    Go to Solution.
    Attachments:
    test.JPG ‏11 KB
    File size test.vi ‏13 KB
    chart.JPG ‏92 KB

    What is the magnitude of the numbers you are storing? 
    If your dataset is relatively small, the amount of overhead the TDMS file format adds for channel names and grouping is greater than the compression you get by storing the data as a binary file.  Your data set isn't huge, but isn't all that small either.
    However, you are saving doubles which would cost you 8 bytes per array element.  With ASCII, you are storing the elements with about 6 or so characters per number since the default setting is 3 decimal places.  You have a tab separator, 3 decimal places, the decimal point, and 1 character for each digit on the integer side of the decimal point.
    Unfortunately, the VI you posted was missing some subVI's and typedef's and didn't reflect the image you posted.  But cleaning it up and running it with a small 4x4 array with just a 3 in the lower right corner (all rest zeroes), I got 107 bytes for ASCII and 616 for TDMS.  And the TDMS index file added another 456 bytes.  So my test run showed both possibilities, very little data overall so that the extra info in the TDMS format was a greater percentage of the file.   And relatively small numbers that took only 6 bytes to show and separate in ASCII as opposed to 8 bytes to store as a double in binary.
    By looking at your file sizes, I say each value you are storing is costing about 2 more bytes with binary compared to an ASCII string with 3 decimal places.  (147,160 array elements, ~258,000 difference in file size)
    One disadvantage of ASCII is that the formatting to text will limit your precision to some amount that you define by the format string, but if you remain in binary, the value will be stored with all the precision/resolution that was present in its native datatype.

  • Calculating and displaying the Length of the side of a triangle

    Hi everyone. I am currently working on Dragging and Stretching a triangle on screen. Ive got it working to a certain extent but the only problem is that whenever I go to the point from which i have to drag my triangle i.e. the Left hand Corner of the BAse at exactly 300,300 it redraws a new triangle below the existing one and then when i stretch it from the top and the right it leaves a trail of triangles everytime. But when i resize my window it clears the trail only to start agian when I drag or stretch it...
    All my code for wahtever I have done is displayed below. I would appreciate all the help that any one can offer.
    Secondly , as I stretch my triangle I would like to calculate My Length of the hypotenuse and the other 2 sides as they change and display it in System.out.println for now...
    PLEASE HELP
    the code is
    This is my Main Form --- Interactive Geometry.java
    import java.awt.BorderLayout;
    import java.awt.Container;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseMotionListener;
    import javax.swing.JFrame;
    * InteractiveGeometry.java
    * Created on 30 November 2004, 20:29
    * @author  Kripa Bhojwani
    public class InteractiveGeometry extends javax.swing.JFrame {
        public EastPanel eastpanel;
        public Container container;
        public GeomPanel gp;
        public boolean pressed = false;
        public boolean pressT = false;
        public boolean pressR = false;
        /** Creates new form InteractiveGeometry */
        public InteractiveGeometry() {
            initComponents();
            eastpanel = new EastPanel();
            container = new Container();
            Model model = new Model(300,150,450,300,300,300);
            gp = new GeomPanel(model);
            container = getContentPane();
            container.add(eastpanel,BorderLayout.EAST);
            container.add(gp,BorderLayout.CENTER);
            setSize(1400,9950);
            gp.addMouseMotionListener(
            new MouseMotionListener() { //anonymous inner class
                //handle mouse drag event
                public void mouseDragged(MouseEvent me) {
                    setTitle("Dragging: x=" + me.getX() + "; y=" + me.getY());
                public void mouseMoved(MouseEvent me) {
                    setTitle("Moving: x=" + me.getX() + "; y=" + me.getY());
        /** This method is called from within the constructor to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
        private void initComponents() {
            jMenuBar2 = new javax.swing.JMenuBar();
            jMenu2 = new javax.swing.JMenu();
            jMenuItem1 = new javax.swing.JMenuItem();
            jMenu1 = new javax.swing.JMenu();
            jMenuItem2 = new javax.swing.JMenuItem();
            addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
                public void mouseDragged(java.awt.event.MouseEvent evt) {
                    formMouseDragged(evt);
                public void mouseMoved(java.awt.event.MouseEvent evt) {
                    formMouseMoved(evt);
            addWindowListener(new java.awt.event.WindowAdapter() {
                public void windowClosing(java.awt.event.WindowEvent evt) {
                    exitForm(evt);
            jMenuBar2.setBackground(new java.awt.Color(0, 102, 204));
            jMenu2.setBackground(new java.awt.Color(222, 222, 238));
            jMenu2.setText("File");
            jMenu2.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jMenu2ActionPerformed(evt);
            jMenuItem1.setBackground(new java.awt.Color(204, 255, 255));
            jMenuItem1.setText("Exit");
            jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jMenuItem1ActionPerformed(evt);
            jMenu2.add(jMenuItem1);
            jMenuBar2.add(jMenu2);
            jMenu1.setBackground(new java.awt.Color(199, 215, 255));
            jMenu1.setText("Theorem ");
            jMenuItem2.setText("Pythagoras Theorem");
            jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jMenuItem2ActionPerformed(evt);
            jMenu1.add(jMenuItem2);
            jMenuBar2.add(jMenu1);
            setJMenuBar(jMenuBar2);
            pack();
        private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {
            // TODO add your handling code here:
        private void formMouseDragged(java.awt.event.MouseEvent evt) {
            // TODO add your handling code here:
        private void formMouseMoved(java.awt.event.MouseEvent evt) {
            // TODO add your handling code here:
        public void mouseDragged(MouseEvent me) {
            setTitle("Dragging: x=" + me.getX() + "; y=" + me.getY());
        private void jMenu2ActionPerformed(java.awt.event.ActionEvent evt) {
            // TODO add your handling code here:
        private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {
            // TODO add your handling code here:
            System.exit(0);
        /** Exit the Application */
        private void exitForm(java.awt.event.WindowEvent evt) {
            System.exit(0);
         * @param args the command line arguments
        public static void main(String args[]) {
            InteractiveGeometry ig = new InteractiveGeometry();
            ig.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            ig.show();
            // new InteractiveGeometry().show();
        // Variables declaration - do not modify
        private javax.swing.JMenu jMenu1;
        private javax.swing.JMenu jMenu2;
        private javax.swing.JMenuBar jMenuBar2;
        private javax.swing.JMenuItem jMenuItem1;
        private javax.swing.JMenuItem jMenuItem2;
        // End of variables declaration
    This is my Panel -- GeomPanel.java which draws everything -- /*
    * GeomPanel.java
    * Created on 30 November 2004, 20:29
    import java.awt.*;
    import java.util.*;
    import javax.swing.*;
    import java.awt.Graphics.*;
    import java.awt.event.MouseListener;
    import java.awt.event.MouseMotionListener;
    import java.awt.geom.Line2D;
    import java.awt.geom.Point2D;
    import java.awt.event.*;
    import java.awt.Graphics2D;
    import java.awt.geom.Ellipse2D;
    import javax.swing.event.TableModelListener;
    import javax.swing.JScrollPane;
    import javax.swing.event.*;
    import java.awt.Dimension;
    import java.awt.Container.*;
    * @author Kripa Bhojwani
    public class GeomPanel extends javax.swing.JPanel implements Observer, MouseMotionListener, MouseListener {
    private Model model;
    private boolean pressed = false;
    private boolean pressT = false;
    private boolean pressR = false;
    /** Creates new form GeomPanel */
    public GeomPanel(Model model) {
    this.model = model;
    model.addObserver(this);
    addMouseListener(this);
    addMouseMotionListener(this);
    initComponents();
    setBackground(Color.getHSBColor(6,600,660));
    public void paintComponent(Graphics gfx) {
    Graphics2D g = (Graphics2D) gfx;
    Point tc = model.getTop();
    Point lc = model.getLeft();
    Point rc = model.getRight();
    Point2D.Double p1 = new Point2D.Double(tc.getX(),tc.getY());
    Point2D.Double p2 = new Point2D.Double(lc.getX(),lc.getY());
    Point2D.Double p3 = new Point2D.Double(rc.getX(),rc.getY());
    Line2D.Double line = new Line2D.Double(p1, p2);
    Line2D.Double line1 = new Line2D.Double(p2, p3);
    Line2D.Double line2 = new Line2D.Double(p1, p3);
    g.setColor(Color.BLACK);
    g.draw(line);
    g.draw(line2);
    g.draw(line1);
    /** This method is called from within the constructor to
    * initialize the form.
    * WARNING: Do NOT modify this code. The content of this method is
    * always regenerated by the Form Editor.
    private void initComponents() {
    setLayout(new java.awt.BorderLayout());
    addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
    public void mouseDragged(java.awt.event.MouseEvent evt) {
    formMouseDragged(evt);
    private void formMouseDragged(java.awt.event.MouseEvent evt) {
    // TODO add your handling code here:
    public void mouseClicked(MouseEvent e) {
    public void mouseDragged(MouseEvent e) {
    System.out.println("Dragged at "+ e.getX()+ "," + e.getY());
    if(pressed == true){
    model.setLeft(e.getX() , e.getY());
    else if(pressT == true){
    model.setTop(e.getX() , e.getY());
    else if (pressR == true){
    model.setRight(e.getX(), e.getY());
    else{
    pressed = false;
    pressT= false;
    pressR=false;
    repaint();
    public void mouseEntered(MouseEvent e) {
    public void mouseExited(MouseEvent e) {
    public void mouseMoved(MouseEvent e) {
    System.out.println("Mouse at " + e.getX() +"," + e.getY());
    public void mousePressed(MouseEvent e) {
    if (model.getLeft().getX()== e.getX() && model.getLeft().getY()== e.getY()){
    pressed = true;
    else if (model.getTop().getX()==e.getX() && model.getTop().getY()==e.getY()){
    pressT = true;
    else if(model.getRight().getX() == e.getX() && model.getRight().getY()==e.getY()){
    pressR = true;
    // else if(model.getCircle().getX() == e.getX() && model.getCircle().getY() == e.getY()){
    // inoval = true;
    else {
    pressed =false;
    pressT = false;
    pressR = false;
    } repaint();
    public void mouseReleased(MouseEvent e) {
    if(pressed == true){
    model.setLeft(e.getX(),e.getY());
    else if (pressT ==true ){
    model.setTop(e.getX(), e.getY());
    else if(pressR ==true){
    model.setRight(e.getX(),e.getY());
    else {
    pressed = false;
    pressT = false;
    pressR = false;
    repaint();
    public void update(Observable o, Object arg) {
    repaint();
    // Variables declaration - do not modify
    // End of variables declaration
    This is my Model class called Model.java which Holds all teh data for my triangle
    import java.awt.Point;
    import java.util.Observable;
    * Model.java
    * Created on 05 December 2004, 14:11
    * @author  Kripa Bhojwani
    public class Model extends Observable{
        private int  x1,x2,x3, y1,y2,y3;
        private int _transx;
        private int _transy;
        private int _c;
        private int _d;
        /** Creates a new instance of Model */
        public Model(int x1, int y1, int x2, int y2, int x3, int y3) {
            this.x1 = x1;
            this.y1 = y1;
            this.x2 = x2;
            this.y2 = y2;
            this.x3 = x3;
            this.y3 = y3;
            setChanged();
            notifyObservers();
        public void setTop(int x1, int y1){
            //this.x1 =x1;
            this.y1= y1;
            setChanged();
            notifyObservers();
        public void setRight(int x2, int y2){
            this.x2 = x2;
            // this.y2 =y2;
            setChanged();
            notifyObservers();
        public void setLeft(int x3, int y3){
            _transx = x3 - this.x3;
            _transy = y3 - this.y3;
            this.x3 += _transx;
            this.y3 += _transy;
            this.y2 += _transy;
            this.x2 += _transx;
            this.x1 += _transx;
            this.y1 += _transy;
            setChanged();
            notifyObservers();
        public Point getTop(){
            Point p = new Point(x1,y1);
            return p;
        public Point getRight(){
            Point p1 = new Point(x2,y2);
            return p1;
        public Point getLeft(){
            Point p3 = new Point(x3,y3);
            return p3;
        public void update() {
            setChanged();
            notifyObservers();
    This is my TableModel which is the JTable to display all the Cordinates and Lengths and other Measurements like angles etc./*
    * TableModel.java
    * Created on 03 December 2004, 15:08
    import javax.swing.JTable;
    import javax.swing.JScrollPane;
    import javax.swing.JPanel;
    import javax.swing.JFrame;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.Observer;
    import javax.swing.event.TableModelEvent;
    import javax.swing.table.AbstractTableModel;
    * @author Kripa Bhojwani
    public class TableModel extends AbstractTableModel implements Observer{
    private String[] columnNames = {"Point", "X Coordinate", "Y Coordinate"};
    private Object[][] data = {};
    private int rowCount;
    private int columnCount;
    /** Creates a new instance of TableModel */
    public TableModel() {
    rowCount = 0;
    columnCount = 3;
    public int getColumnCount() {
    return columnCount;
    public int getRowCount() {
    return rowCount;
    public String getColumnName(int col) {
    return columnNames[col];
    public void setColumnName (String[] name){
    columnNames = name;
    public void setValueAt(Object obj, int row, int col) {
    data[row][col] = obj;
    fireTableCellUpdated(row, col);
    TableModelEvent tme = new TableModelEvent(this);
    fireTableChanged(tme);
    public Object getValueAt(int row, int col) {
    return data[row][col];
    public void update(java.util.Observable o, Object arg) {
    This is the Panel on the east side of My Main application form which will display all the measurements and Cordinates ---EastPanel.java
    import java.awt.BorderLayout;
    import javax.swing.JScrollPane;
    import javax.swing.JTable;
    import javax.swing.event.TableModelListener;
    import java.awt.Dimension;
    * EastPanel.java
    * Created on 04 December 2004, 23:07
    * @author  Kripa Bhojwani
    public class EastPanel extends javax.swing.JPanel implements TableModelListener{
        private TableModel tm;
        /** Creates new form EastPanel */
        public EastPanel() {   
          initComponents();
            tm = new TableModel();
            JTable table1 = new JTable(tm);
            table1.setPreferredScrollableViewportSize(new Dimension(250,264));
            table1.getModel().addTableModelListener(this);
            JScrollPane sp = new JScrollPane(table1);
            add(sp,BorderLayout.EAST);
        /** This method is called from within the constructor to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
        private void initComponents() {
            setLayout(new java.awt.BorderLayout());
        public void tableChanged(javax.swing.event.TableModelEvent e) {
        // Variables declaration - do not modify
        // End of variables declaration
    }                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    

    import java.awt.*;
    import java.awt.event.*;
    import java.awt.geom.*;
    import java.text.NumberFormat;
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.table.DefaultTableCellRenderer;
    public class G
    public G()
    TriangleModel tri = new
    ri = new TriangleModel(175,100,175,250,325,250);
    TriangleView view = new TriangleView(tri);
    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.getContentPane().add(view.getUIPanel(),
    Panel(), "North");
    f.getContentPane().add(view);
    f.getContentPane().add(view.getTablePanel(),
    Panel(), "South");
    f.setSize(500,500);
    f.setLocation(200,200);
    f.setVisible(true);
    public static void main(String[] args)
    new G();
    class TriangleModel // (x1,
    y1)
    {                                         //      |\
    static final int SIDES = 3; // | \
    private int cx, cy; // |
    | \
    Polygon triangle; // |_
    |_ _\ (x3, y3)
    int selectedIndex; // (x2,
    (x2, y2)
    NumberFormat nf;
    Line2D[] medians;
    Point2D centroid;
    public TriangleModel(int x1, int y1, int x2, int
    int y2, int x3, int y3)
    int[] x = new int[] { x1, x2, x3 };
    int[] y = new int[] { y1, y2, y3 };
    triangle = new Polygon(x, y, SIDES);
    nf = NumberFormat.getNumberInstance();
    nf.setMaximumFractionDigits(1);
    public boolean contains(Point p)
    // Polygon.contains doesn't work well enough
    return (new Area(triangle)).contains(p);
    public boolean isLineSelected(Rectangle r)
    Line2D line = new Line2D.Double();
    for(int j = 0; j < SIDES; j++)
    int[] x = triangle.xpoints;
    int[] y = triangle.ypoints;
    int x1 = x[j];
    int y1 = y[j];
    int x2 = x[(j + 1) % SIDES];
    int y2 = y[(j + 1) % SIDES];
    line.setLine(x1, y1, x2, y2);
    if(line.intersects(r))
    selectedIndex = j;
    return true;
    selectedIndex = -1;
    return false;
    * Only works for right triangle with right angle
    angle at (x2, y2)
    public void moveSide(int dx, int dy, Point p)
    int[] x = triangle.xpoints;
    int[] y = triangle.ypoints;
    switch(selectedIndex)
    case 0:
    x[0] += dx;
    x[1] += dx;
    break;
    case 1:
    y[1] += dy;
    y[2] += dy;
    break;
    case 2:
    double rise = y[2] - y[0];
    double run = x[2] - x[0];
    double slope = rise/run;
    // rise / run == (y[2] - p.y) / (x[2]
    ] - p.y) / (x[2] - p.x)
    x[2] = p.x + (int)((y[2] - p.y) /
    )((y[2] - p.y) / slope);
    // rise / run == (p.y - y[0]) / (p.x
    y - y[0]) / (p.x - x[0])
    y[0] = p.y - (int)((p.x - x[0]) *
    )((p.x - x[0]) * slope);
    public void translate(int dx, int dy)
    triangle.translate(dx, dy);
    public Polygon getTriangle()
    return triangle;
    public String findCentroid()
    int[] x = triangle.xpoints;
    int[] y = triangle.ypoints;
    // construct the medians defined as the line
    the line from
    // any vertex to the midpoint of the opposite
    opposite line
    medians = new Line2D[x.length];
    for(int j = 0; j < x.length; j++)
    int next = (j + 1) % x.length;
    int last = (j + 2) % x.length;
    Point2D vertex = new Point2D.Double(x[j],
    Double(x[j], y[j]);
    // get midpoint of line opposite vertex
    double dx = ((double)x[last] -
    le)x[last] - x[next])/2;
    double dy = ((double)y[last] -
    le)y[last] - y[next])/2;
    Point2D oppLineCenter = new
    Center = new Point2D.Double(x[next] + dx,
    y[next]
    y[next] + dy);
    medians[j] = new Line2D.Double(vertex,
    uble(vertex, oppLineCenter);
    // centroid is located on any median 2/3 the
    2/3 the way from the
    // vertex (P1) to the midpoint (P2) on the
    ) on the opposite side
    double[] lengths = getSideLengths();
    double dx = (medians[0].getX2() -
    etX2() - medians[0].getX1())*2/3;
    double dy = (medians[0].getY2() -
    etY2() - medians[0].getY1())*2/3;
    double px = medians[0].getX1() + dx;
    double py = medians[0].getY1() + dy;
    //System.out.println("px = " + nf.format(px)
    rmat(px) +
    // "\tpy = " +
    py = " + nf.format(py));
    centroid = new Point2D.Double(px, py);
    return "(" + nf.format(px) + ", " +
    ", " + nf.format(py) + ")";
    public String[] getAngles()
    double[] lengths = getSideLengths();
    String[] vertices = new
    es = new String[lengths.length];
    for(int j = 0; j < lengths.length; j++)
    int opp = (j + 1) % lengths.length;
    int last = (j + 2) % lengths.length;
    double top = lengths[j] * lengths[j] +
    lengths[last] *
    lengths[last] * lengths[last] -
    lengths[opp] *
    lengths[opp] * lengths[opp];
    double divisor = 2 * lengths[j] *
    lengths[j] * lengths[last];
    double vertex = Math.acos(top /
    h.acos(top / divisor);
    vertices[j] =
    ertices[j] = nf.format(Math.toDegrees(vertex));
    return vertices;
    public String[] getLengths()
    double[] lengths = getSideLengths();
    String[] lengthStrs = new
    rs = new String[lengths.length];
    for(int j = 0; j < lengthStrs.length; j++)
    lengthStrs[j] = nf.format(lengths[j]);
    return lengthStrs;
    public String[] getSquares()
    double[] lengths = getSideLengths();
    String[] squareStrs = new
    rs = new String[lengths.length];
    for(int j = 0; j < squareStrs.length; j++)
    squareStrs[j] = nf.format(lengths[j] *
    lengths[j] * lengths[j]);
    return squareStrs;
    private double[] getSideLengths()
    int[] x = triangle.xpoints;
    int[] y = triangle.ypoints;
    double[] lengths = new double[SIDES];
    for(int j = 0; j < SIDES; j++)
    int next = (j + 1) % SIDES;
    lengths[j] = Point.distance(x[j], y[j],
    (x[j], y[j], x[next], y[next]);
    return lengths;
    class TriangleView extends JPanel
    private TriangleModel model;
    private Polygon triangle;
    private JTable table;
    private JLabel centroidLabel;
    private boolean showConstruction;
    TriangleControl control;
    public TriangleView(TriangleModel model)
    this.model = model;
    triangle = model.getTriangle();
    showConstruction = false;
    control = new TriangleControl(this);
    addMouseListener(control);
    addMouseMotionListener(control);
    public void paintComponent(Graphics g)
    super.paintComponent(g);
    Graphics2D g2 = (Graphics2D)g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
    RenderingHints.VALUE_ANTIALIAS_ON);
    g2.draw(triangle);
    if(model.medians == null)
    centroidLabel.setText("centroid location:
    id location: " + model.findCentroid());
    // draw medians and centroid point
    if(showConstruction && !control.dragging)
    g2.setPaint(Color.red);
    for(int j = 0; j < 3; j++)
    g2.draw(model.medians[j]);
    g2.setPaint(Color.blue);
    g2.fill(new
    g2.fill(new Ellipse2D.Double(model.centroid.getX() -
    2,
    model.centroid.getY()
    model.centroid.getY() - 2, 4, 4));
    public TriangleModel getModel()
    return model;
    public JTable getTable()
    return table;
    public JLabel getCentroidLabel()
    return centroidLabel;
    public JPanel getUIPanel()
    JCheckBox showCon = new JCheckBox("show
    ox("show construction");
    showCon.addActionListener(new
    ener(new ActionListener()
    public void actionPerformed(ActionEvent
    (ActionEvent e)
    boolean state =
    boolean state =
    ((JCheckBox)e.getSource()).isSelected();
    showConstruction = state;
    repaint();
    JPanel panel = new JPanel();
    panel.add(showCon);
    return panel;
    public JPanel getTablePanel()
    String[] headers = new String[] { "", "", "",
    // row and column data labels
    String[] rowHeaders = {
    "sides", "lengths", "squares", "angles",
    ", "angles", "degrees"
    String[] sidesRow = { "vertical",
    rtical", "horizontal", "hypotenuse" };
    String[] anglesRow = { "hyp to ver", "ver to
    "ver to hor", "hor to hyp" };
    // collect data from model
    String[] angles = model.getAngles();
    String[] lengths = model.getLengths();
    String[] squares = model.getSquares();
    String[][] allData = { sidesRow, lengths,
    lengths, squares, anglesRow, angles };
    int rows = 5;
    int cols = 4;
    Object[][] data = new Object[rows][cols];
    for(int row = 0; row < rows; row++)
    data[row][0] = rowHeaders[row];
    for(int col = 1; col < cols; col++)
    data[row][col] = allData[row][col -
    lData[row][col - 1];
    table = new JTable(data, headers)
    public boolean isCellEditable(int row,
    ble(int row, int col)
    return false;
    DefaultTableCellRenderer renderer =
    (DefaultTableCellRenderer)table.getDefaultRenderer(St
    ring.class);
    renderer.setHorizontalAlignment(JLabel.CENTER);
    centroidLabel = new JLabel("centroid
    centroid location: ", JLabel.CENTER);
    Dimension d =
    sion d = centroidLabel.getPreferredSize();
    d.height = table.getRowHeight();
    centroidLabel.setPreferredSize(d);
    JPanel panel = new JPanel(new
    anel(new BorderLayout());
    panel.setBorder(BorderFactory.createTitledBorder("tri
    angle data"));
    panel.add(table);
    panel.add(centroidLabel, "South");
    return panel;
    class TriangleControl extends MouseInputAdapter
    TriangleView view;
    TriangleModel model;
    Point start;
    boolean dragging, altering;
    Rectangle lineLens; // used for line
    line selection
    public TriangleControl(TriangleView tv)
    view = tv;
    model = view.getModel();
    dragging = altering = false;
    lineLens = new Rectangle(0, 0, 6, 6);
    public void mousePressed(MouseEvent e)
    Point p = e.getPoint();
    lineLens.setLocation(p.x - 3, p.y - 3);
    // are we over a line
    if(model.isLineSelected(lineLens))
    start = p;
    altering = true;
    // or are we within the triangle
    else if(model.contains(p))
    start = p;
    dragging = true;
    public void mouseReleased(MouseEvent e)
    altering = false;
    dragging = false;
    view.getCentroidLabel().setText("centroid
    centroid location: " +
    model.findCentroid());
    view.repaint(); // for the construction
    truction lines
    public void mouseDragged(MouseEvent e)
    Point p = e.getPoint();
    if(altering)
    int x = p.x - start.x;
    int y = p.y - start.y;
    model.moveSide(x, y, p);
    updateTable();
    view.repaint();
    start = p;
    else if(dragging)
    int x = p.x - start.x;
    int y = p.y - start.y;
    model.translate(x, y);
    view.repaint();
    start = p;
    private void updateTable()
    String[] lengths = model.getLengths();
    String[] squares = model.getSquares();
    String[] angles = model.getAngles();
    JTable table = view.getTable();
    for(int j = 0; j < angles.length; j++)
    table.setValueAt(lengths[j], 1, j + 1);
    table.setValueAt(squares[j], 2, j + 1);
    table.setValueAt(angles[j], 4, j + 1);
    view.getCentroidLabel().setText("centroid
    centroid location: " +
    model.findCentroid());
    Hey sorry mate.. ive got a nother problem.
    I need to add loads of theorems to this tool. so i need a JMenu Bar called File with all the normal things. then another Menu called Theorems where i can have a list of JMenuItems with the theorem names --- Like when they click on Pythagoras Theorem it opens up all the triangle and the traingle data that u helped me with.
    The thing is im using netbeans and in netbeans i can do it coz its there and all you got to do is put the components together.
    Please Help
    Thanks...
    Sharan

  • Developing Pythagoras Triangle

    Hi.. Im new to JAVA and i need to develop a program where i can build a Right angle triangle to start with and eventually move the vertexs of the triangle and see the lengths change in such a way that the proof still holds i.e. a^2 + b^2 = c^2
    is always true
    the user should be able to move the triangle and drag the vertexs and incease the lengths of any side.
    Please help me with CODE AND HOW TO BEGIN WITH
    all help is greatly appreciated..
    THanks
    Sharan

    This isn't a great medium for personalized tutoring. Please ask specific questions. If you need additional resources for learning Java, please take a look at the following:
    The Java Tutorial - A practical guide for programmers
    Essentials, Part 1, Lesson 1: Compiling & Running a Simple Program
    New to Java Center
    How To Think Like A Computer Scientist
    Introduction to Computer Science using Java
    The Java Developers Almanac 1.4
    JavaRanch: a friendly place for Java greenhorns
    jGuru
    Object-Oriented Programming Concepts
    Object-oriented language basics
    Don't Fear the OOP
    Books:
    Bruce Eckel's Thinking in Java (Free online)
    Joshua Bloch's Effective Java
    Bert Bates and Kathy Sierra's Head First Java

  • HELP - hi with apple Configurator why does it show with a yellow triangle on the right side of the screen what am i doing wrong for the ipads not syncing or whatever and how do i fix that?

    HELP -- hi with apple Configurator why does it show with a yellow triangle on the right side of the screen what am i doing wrong for the ipads not syncing or whatever and how do i fix that? although i have looked online to try and figure it out and here is the website i found is this the stuff i need to do to fix this? is this site what i need to do to fix this? http://edtechstandish.wordpress.com/what-ive-learned-about-apple-configurator-so -far/  Thanks

    Sorry but I don't know anything about this.  But you might have better luck posting this question over ing the iPad in Business and Education forum here: https://discussions.apple.com/community/ipad/ipad_in_business_and_education?view =discussions.

  • 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

Maybe you are looking for

  • Ios5 iMessage on multiple devices with a single apple id

    I have 2 iphones and a ipad, how do i message individual devices, at the moment any message i said shows on all three devices, very confused here. Any help appreciated.

  • G/L account 500000 cannot be used (please correct)

    Dear Expert, When making purchase requistion with New G/L account, i am getting the following error msg no : ME045. G/L account 500000 cannot be used (please correct) Message no. ME045 Diagnosis Comparison of the field selection strings from the G/L

  • Split and transform words

    I have a problem I'm having trouble solving. I have an application I write a textbox: 'SQL SQL' MICROSOFT 'SQL SQL' When I click a button, I wanted to receive as stored procedure parameter:   @ String = 'SQL SQL "OR MICROSOFT OR MICROSOFT OR' SQL SQL

  • 1131 AP Shows as having "other" antenna in the WCS

    I just installed 5 lightweight 1131 ap's, two of them show up as having " other " as the antenna type in my WCS , the others show as having Ajax-Omni. They all have the same code and were installed at the same time. Also I can't get a het map profile

  • Cannot print duplex with Mac OSX 10.9.1

    with brother printer no line with option box shows up in the print dialog box under "size"