How can i rewrite this code

i have tried to rewrite this code but keep getting errors. ive read loads of tutorials on actionperformed and mouseclicked i just need som1 to point me in the right direction
heres the code
public boolean mouseUp(Event e, int x, int y){
if (y == 0)
swit = true;
return true;
//else
if (pics[getMC(x,y)].getID() > rw*col/2){
  return true;}
if (0 == track)
card1 = pics[getMC(x,y)];
start = new Date();
etime.start();
track = 2;
stat = "pic again";
repaint();
return true;
if (1 == track){
  card1 = pics[getMC(x,y)];
  track = 2;
  stat = "pick again";
  repaint();
  return true;
else if (2 == track)
       if (card1 == pics[getMC(x,y)]) return true;
         card2 = pics[getMC(x,y)];
         track = 3;
         attempts++;
         if (card1.getID() == card2.getID())
          stat = "well done";
            matched++;
            if (rw*col/2 == matched)
             stat = "finished";
               etime = null;
         else
          stat = "Try Again";
         repaint();
         return true;
      else
       return false;
   }

Hi,
Do you want your code to listen to different Mouse events? and what other events?
ex:
copy the content of the below link and run the application
http://java.sun.com/docs/books/tutorial/uiswing/examples/events/MouseEventDemoProject/src/events/MouseEventDemo.java
http://java.sun.com/docs/books/tutorial/uiswing/examples/events/MouseEventDemoProject/src/events/BlankArea.java
If you have any problem with the code; please let us know
Regards,
Alan Mehio
London,UK

Similar Messages

  • How can i rewrite this code into java?

    How can i rewrite this code into a java that has a return value?
    this code is written in vb6
    Private Function IsOdd(pintNumberIn) As Boolean
        If (pintNumberIn Mod 2) = 0 Then
            IsOdd = False
        Else
            IsOdd = True
        End If
    End Function   
    Private Sub cmdTryIt_Click()
              Dim intNumIn  As Integer
              Dim blnNumIsOdd     As Boolean
              intNumIn = Val(InputBox("Enter a number:", "IsOdd Test"))
              blnNumIsOdd = IsOdd(intNumIn)
              If blnNumIsOdd Then
           Print "The number that you entered is odd."
        Else
           Print "The number that you entered is not odd."
        End If
    End Sub

    873221 wrote:
    I'm sorry I'am New to Java.Are you new to communication? You don't have to know anything at all about Java to know that "I have an error," doesn't say anything useful.
    I'm just trying to get you to think about what your post actually says, and what others will take from it.
    what does this error mean? what code should i replace and add? thanks for all response
    C:\EvenOdd.java:31: isOdd(int) in EvenOdd cannot be applied to ()
    isOdd()=true;
    ^
    C:\EvenOdd.java:35: isOdd(int) in EvenOdd cannot be applied to ()
    isOdd()=false;
    ^
    2 errors
    Telling you "what code to change it to" will not help you at all. You need to learn Java, read the error message, and think about what it says.
    It's telling you exactly what is wrong. At line 31 of EvenOdd.java, you're calling isOdd(), with no arguments, but the isOdd() method requires an int argument. If you stop ant think about it, that should make perfect sense. How can you ask "is it odd?" without specifying what "it" is?
    So what is this all about? Is this homework? You googled for even odd, found a solution in some other language, and now you're just trying to translate it to Java rather than actually learning Java well enough to simply write this trivial code yourself?

  • How can I rewrite this update stmt to improve its poor performance?

    Hi,
    I have the following update stmt that runs for over 6 hours. Here is the SQL and its plan:
                UPDATE TABLE1
                     SET mainveh = 'Y'
                 WHERE (comp#,polnum,a8dtef,a8deef,a8dtac,
                        DECODE(everif,'Y',10000,0)+auunit*100+vrcdsq)
                    IN (SELECT comp#,polnum,a8dtef,a8deef,a8dtac,
                               MAX(DECODE(everif,'Y',10000,0)+auunit*100+vrcdsq)
                          FROM TABLE1
                         GROUP BY comp#,polnum,a8dtef,a8deef,a8dtac);
    PLAN_TABLE_OUTPUT
    | Id  | Operation             | Name     | Rows  | Bytes |TempSpc| Cost (%CPU)|
    |   0 | UPDATE STATEMENT      |          |     1 |   108 |       |   798K  (1)|
    |   1 |  UPDATE               | TABLE1   |       |       |       |            |
    |   2 |   HASH JOIN           |          |     1 |   108 |  1079M|   798K  (1)|
    |   3 |    TABLE ACCESS FULL  | TABLE1   |    21M|   834M|       |   224K  (1)|
    |   4 |    VIEW               | VW_NSO_1 |    21M|  1364M|       |   440K  (1)|
    |   5 |     SORT GROUP BY     |          |    21M|   794M|  2453M|   440K  (1)|
    |   6 |      TABLE ACCESS FULL| TABLE1   |    21M|   794M|       |   224K  (1)|I'm using Oracle 10.2.0.3. The TABLE1 table has 21 million rows. The update stmt will update about 15 million rows. How can I rewrite this update stmt so it'll perform better? There is a primary index on all the columns selected in the subquery. That is the only index on TABLE1.
    Thank you!
    Edited by: user6053424 on Jul 21, 2010 6:59 AM

    Hi,
    Thank you for your suggestions. There is an index on the columns in the group by, it is the PK index on TABLE1. I'm suspecting that due to the amount of data to update, the optimizer decided that full table scan is cheaper than index scan. I'm very interested in the GTT idea, but still need some help if I decide to create a GTT from the subquery, because if I just do this:
    create global temporary table table1_tmp
    on commit preserve rows
    as SELECT comp#,polnum,a8dtef,a8deef,a8dtac,
               MAX(DECODE(everif,'Y',10000,0)+auunit*100+vrcdsq)
          FROM TABLE1
         GROUP BY comp#,polnum,a8dtef,a8deef,a8dtac;then the original update stmt still has the DECODE and such in it, I'm not sure how much benefit that'll do to us:
    UPDATE TABLE1
                     SET mainveh = 'Y'
                 WHERE (comp#,polnum,a8dtef,a8deef,a8dtac,
                        DECODE(everif,'Y',10000,0)+auunit*100+vrcdsq)
                    IN (SELECT comp#,polnum,a8dtef,a8deef,a8dtac,???
                          FROM TABLE1);Your input is greatly appreciated! Thanks!

  • How  can i run this code correctly?

    hello, everybody:
        when  i run the code, i found that it dons't work,so ,i  hope somebody can help me!
        the Ball class is this :
        package {
        import flash.display.Sprite;
        [SWF(width = "550", height = "400")]
        public class Ball extends Sprite {
            private var radius:Number;
            private var color:uint;
            private var vx:Number;
            private var vy:Number;
            public function Ball(radius:Number=40, color:uint=0xff9900,
            vx:Number =0, vy:Number =0) {
                this.radius= radius;
                this.color = color;
                this.vx = vx;
                this.vy = vy;
                init();
            private function init():void {
                graphics.beginFill(color);
                graphics.drawCircle(0,0,radius);
                graphics.endFill();
    and the Chain class code is :
    package {
        import flash.display.Sprite;
        import flash.events.Event;
        [SWF(width = "550", height = "400")]
        public class Chain extends Sprite {
            private var ball0:Ball;
            private var ball1:Ball;
            private var ball2:Ball;
            private var spring:Number = 0.1;
            private var friction:Number = 0.8;
            private var gravity:Number = 5;
            //private var vx:Number =0;
            //private var vy:Number = 0;
            public function Chain() {
                init();
            public function init():void {
                ball0  = new Ball(20);
                addChild(ball0);
                ball1 = new Ball(20);
                addChild(ball1);
                ball2 = new Ball(20);
                addChild(ball2);
                addEventListener(Event.ENTER_FRAME, onEnterFrame);
            private function onEnterFrame(event:Event):void {
                moveBall(ball0, mouseX, mouseY);
                moveBall(ball1, ball0.x, ball0.y);
                moveBall(ball2, ball1.x, ball1.y);
                graphics.clear();
                graphics.lineStyle(1);
                graphics.moveTo(mouseX, mouseY);
                graphics.lineTo(ball0.x, ball0.y);
                graphics.lineTo(ball1.x, ball1.y);
                graphics.lineTo(ball2.x, ball2.y);
            private function moveBall(ball:Ball,
                                      targetX:Number,
                                      targetY:Number):void {
                ball.vx += (targetX - ball.x) * spring;
                ball.vy += (targetY - ball.y) * spring;
                ball.vy += gravity;
                ball.vx *= friction;
                ball.vy *= friction;
                ball.x += vx;
                ball.y += vy;
    thanks every body's help!

    ok, thanks for your reply ! I run this code in the Flex builder 3!and the Ball class and the Chain class are all in the same AS project!
      and i changed the ball.pv property as public in the Ball class, and  the Chain class has no wrong syntactic analysis,but the AS code don't run.so this is the problem.
    2010-04-21
    Fang
    发件人: Ned Murphy <[email protected]>
    发送时间: 2010-04-20 23:01
    主 题: how  can i run this code correctly?
    收件人: fang alvin <[email protected]>
    I don't see that the Ball class has a pv property, or that you even try to access a pv property in the Chain class.  All of the properties in your Ball class are declared as private, so you probably cannot access them directly.  They would need to be public.  Also, I still don't see where you import Ball in the chain class such that it can use it.

  • How can i know how to redeem the code? how can i get this code?

    how can i know how to redeem the code? how can i get this code? please i need you help
    <Email Edited by Host>

    You are trying to create a new Apple ID? You don't have one yet? Is that correct?
    If so, then see this article on how to creat your Apple ID - and make up a password for it. Remember to write it down immediately.
    http://support.apple.com/en-us/HT203993

  • I forgot the codeslot of my ipod. How can I delete this code?

    I forgot the codeslot of my ipod. How can I delete this code? Can anybody help help me? I'm sorry for the bad English.

    Connect it to iTunes and Restore it.

  • How can i improve this code ?

    DATA: t_bkpf TYPE bkpf.
    DATA: t_bseg type bseg_t.
    DATA: wa_bseg like line of t_bseg.
    select * from bkpf into t_bkpf where document type ='KZ' and bldat in s_bldat.
    select single * from bseg into wa_bseg where belnr = t_bkpf-belnr.
    append wa_bseg to t_bseg.
    endselect.
    loop at t_bseg into wa_bseg.
      at new belnr.
         if wa_bseg-koart EQ 'K'.
            // pick vendor wrbtr
         else
           // pick other line item's wrbtr
         endif.
      endat.
    endloop.
    i am guessing my select statements arnt efficient performance wise, secondly in the loop when i use  'at new belnr' it aint showing my any values  whereas i get all the vendors(KOART EQ 'K') when i dont use 'at new belnr' .
    why is this so and how can i make the code efficient ?
    Thanks..
    Shehryar

    Hi,
    1.Dont read all the fields from the table unless it is required in your program.
    This will tremendously improve your performance.
    2.Make use of the key fields of the table wherever possible
    In your scenario you could use the fields BUKRS,BELNR,GJAHR of the table BKPF in the WHERE Clause rather than
    other fields.This will improve your performance a lot..
    3.As BSEG is a cluster table it will cause performance problem in most cases.So try to read
    the required fields from it rather than reading all the fields.Again Make use of the key fields in the WHERE Clause
    here too to improve the performance..
    4.Remove SELECT..ENDSELECT and replace it with FOR ALL ENTRIES to improve the performance.
    Cheers,
    Abdul Hakim
    Mark all useful answers..

  • How can I get this code to display 20 lines

    I need to get this code I have written to display 20 lines at a time, then the 20 using the Enter key.
    How would I approach this?
    I thought of making a RandomAcessFile object, but that seems like overthinking the problem, and I'm not sure that I could get that to work anyway.
    import java.io.*;
    public class ReadIt
    public static void main(String[] args)
         throws IOException
              System.out.println ("Enter The Desired .java Filename.");
              System.out.println ("Do not add the .java extention.");
              String fname;
              EasyIn type = new EasyIn();
              fname = type.readString();
              String fndotjava = new String(fname + ".java");
              //System.out.println (fndotjava);
              File inFile = new File(fndotjava);
              InputStream istream;
              OutputStream ostream;
              istream = new FileInputStream(inFile);
              ostream = System.out;
              int c;
              try
                     while((c = istream.read()) != -1)
                           ostream.write(c);
              catch(IOException e)
                     System.out.println("Error: " + e.getMessage());      
              finally
                    istream.close();
                    ostream.close();                 
    }Thanks
    Brad

    Well, a RandomAccessFile together with a counter should work. However, you can also achieve this by buffering the input rather than writing it directly out
    java.util.Vector vect = new java.util.Vector();
    try{
         while((c = istream.read()) != -1){
             vect.append(c);
    catch(IOException e){
         System.out.println("Error: " + e.getMessage());      
    finally{
         istream.close();                 
    }     with the help of
    java.util.Vector.size() and
    java.util.Vector.elementAt(int index)
    you are able to display only 20 lines at a time, you just need the additional code for reading System.in
    public static void prompt(String s){
        System.out.print(s + " ");
        System.out.flush();
      public static String readData ( BufferedReader in)  {
        boolean verfuegbar = true;
        while ( verfuegbar){
          try{
            S = in.readLine();
            if ( S != null)verfuegbar = false ;
          catch (IOException e){System.out.print (e);}
        return S;
      }now it should work with
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    prompt("return for continuing");
    int twentscount = 0;
    int count = 0;
    do{
       while( count < 20 && twentscount+count < vect.size() ){
           outstream.write(vect.elementAt(twentscount + count).toString() );
           count++;
    prompt("return");
    readData(in);
    twentscount += 20;
    count = 0;
    while(twentscount + count < vect.size());sure, this is code from head, and you can make many changes (e.g. instead of using twentscount use the modulo (%) operator saving one variable (while count % 20 != 0 ).
    I'm also not sure if it will definitly run , since i haven't tested it (especialy for index borders).
    I hope this will give you enough hints for this possible solution.
    Adrian

  • How can I use this code in Muse?

    Please, tell me with details how to paste this code, which the "add this" widget on Muse to appear...
    <!-- AddThis Smart Layers BEGIN -->
    <!-- Go to http://www.addthis.com/get/smart-layers to customize -->
    <script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-538d2f0f4872fcfe"></script>
    <script type="text/javascript">
      addthis.layers({
        'theme' : 'transparent',
        'follow' : {
          'services' : [
            {'service': 'facebook', 'id': 'africa.si.zgz'},
            {'service': 'twitter', 'id': 'Africa_Si'},
            {'service': 'google_follow', 'id': 'u/0/b/103262715708033329485/103262715708033329485/posts'},
            {'service': 'linkedin', 'id': 'África-sí', 'usertype': 'company'},
            {'service': 'youtube', 'id': 'africasizgz'}
        'whatsnext' : {} 
    </script>
    <!-- AddThis Smart Layers END -->
    Thank you!

    Thank you, but I still have a problem.... When a copy it directly on Muse through "ctrl + v" I see the whole code as text on Muse and when I paste it thorugh object--> Insert HTML Muse says that they "couldn't generate de miniature", do you know what I'm doing wrong?
    Thank you!

  • How can i modify this code in BI?

    hi friends,
    suppose i have data in infosource with deffirent customers.
    like from usa,germany,uk.
    i created 3 cubes and uploaded records corresponding countries.
    i have written code like this in 3.5
    loop at data_package.
    if data_package-/bic/zcustomer <> 'usa'.
    delete data_package.
    endif.
    endloop.
    same logic i need to write in BI 7.0 now where can i write this logic, what modifications i need to change for BI 7.0
    regards
    suneel.

    Hi,
    Check this link:
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/6090a621-c170-2910-c1ab-d9203321ee19
    I guess, you just need to change the DATA_PACKAGE to the new naming convention.
    Hope this helps.
    PB

  • How can I fix this code ?

    hello,
    I have a small problem with this code:
    #include  <fstream>
    #include  <iostream>
    #include  <algorithm>
    #include  <iterator>
    #include  <string>
    #include  <vector>
    using namespace std;
    int main()
         string from, to;
         cin >> from >> to;
         ifstream is(from.c_str());
         istream_iterator<string> ii(is);
         istream_iterator<string> eos;
         //  line 24: Error:
         vector<string> b(ii, eos);  //  line 24: Error:
         sort(b.begin(), b.end());
         ofstream os(to.c_str());
         ostream_iterator<string> oo(os, "\n");     
             unique_copy(b.begin(), b.end(), oo);     
             return !is.eof() && !os;          
             return 0;
    }When I compile this happens
    bash-2.05$ CC -V
    CC: Sun C++ 5.6 2004/06/02
    bash-2.05$ CC -o std_vector.out std_vector.cpp
    "std_vector.cpp", line 24: Error:
    Could not find a match for
    std::vector<std::string>::vector(std::istream_iterator<std::string, char, std::char_traits<char>, int>, std::istream_iterator<std::string, char, std::char_traits<char>, int>)needed in main().
    1 Error(s) detected.
    What can I do ?
    best regards
    Morten Gulbrandsen

    You have run into a documented limitation of the default libCstd implementation of the C++ standard library. The default library is not a complete implementation, and in particular lacks required template member functions that allow implicit type conversions. We still use this library for binary compatibility with earlier releases.
    The optional STLport version of the library is a full implementation of hte C++ Standard Library. If you don't need binary compatibility, meaning you don't need to link to code that uses libCstd, you can add the option -library=stlport4 to every CC command line, compiling and linking. Your sample code compiles with STLport.
    If you need to use libCstd, you might get this code to work by inserting explicit type conversions. I have not tried to see whether that actually can be done.

  • How can I simplify this code?

    Here's some code I am working on for my CompScience class. If any of you more advanced java users can assist me in simpliying this code, it will be much appreciated. Thanks
    import javax.swing.JOptionPane;
    public class lab09b
         public static void main (String args[])     
              String str;     
              int num = 1, den = 1; //Initializes variables for use.         
              Rational2 r3 = new Rational2 (num,den); //Creates new Rational2 object to be used for math operations.     
              str = JOptionPane.showInputDialog("Enter Numerator 1:"); 
              num = Integer.parseInt(str);
              str = JOptionPane.showInputDialog("Enter Denominator 1:");     
              den = Integer.parseInt(str);
              Rational1 rA = new Rational1 (num,den); //Creates object to store original input of fraction 1.
              Rational2 r1 = new Rational2 (num,den); //Creates object to store reduced input of fraction 1.
              str = JOptionPane.showInputDialog("Enter Numerator 2:");
              num = Integer.parseInt(str);
              str = JOptionPane.showInputDialog("Enter Denominator 2:");     
              den = Integer.parseInt(str);
              Rational1 rB = new Rational1 (num,den); //Creates object to store original input of fraction 2.
              Rational2 r2 = new Rational2 (num,den); //Creates object to store reduced input of fraction 1.
              r3.add(r1,r2);
              JOptionPane.showMessageDialog(null,rA.getOriginal()+"+"+rB.getOriginal()+"="+r3.getRational()); //Outputs results of addition
              r3.multiply(r1,r2);
              JOptionPane.showMessageDialog(null,rA.getOriginal()+"*"+rB.getOriginal()+"="+r3.getRational()); //Outputs results of multiplication.                                 
              System.exit(0);     
    class Rational1
         protected int num; // Entered numerator.
         protected int den; // Entered denominator.
         private int getGCF(int n1,int n2) //Method for reduction.
              int rem = 0;
              int gcf = 0;
              do
                   rem = n1 % n2;
                   if (rem == 0)
                   gcf = n2;
                   else
                        n1 = n2;
                        n2 = rem;
              while (rem != 0);
              return gcf;
         public void reduce() //Modifies fraction to a equivalent simplified rational.
              int gcf = getGCF(num,den);
              num = num / gcf;
              den = den / gcf;
         public Rational1(int n, int d) //Constructs Rational1 without reducing it.
              num = n;
              if (d == 0)
                   System.out.println("Illegal denominator; altered to 1");
                   den = 1;
              else
                   den = d;
         public int getNum() //Returns Numerator.
              return num;
         public int getDen() //Returns Denominator.
              return den;
         public String getOriginal() //Returns Original Fraction.
              return ""+num+"/"+den;     
    class Rational2 extends Rational1 //Class used to modify fractions.
         public Rational2(int n, int d) //Constructs Rational2 using superclass constructor.
              super(n,d);
         public String getRational() //Returns the reduced fraction version.
              super.reduce();
              return ""+num+"/"+den;     
         public void add(Rational2 r1, Rational2 r2) //Adds two rationals together.
              den = r1.getDen() * r2.getDen();
              num = r1.getNum() * r2.getDen() + r2.getNum() * r1.getDen();
         public void multiply(Rational2 r1, Rational2 r2) //Multiplies two rationals.
              den = r1.getDen() * r2.getDen();
              num = r1.getNum() * r2.getNum();
    }

    seems simple enough to me.... you want complicated code... I could find you some good complicated code, and you'll look at yours and say, wow, this is pretty simple.
    What part are you expecting to simplify?
    Does it compile? Does it run? Does it do what you expect it to do?

  • How can I make this code faster? optimized.

    Its part of two jsp pages that go back and forth. I feel I am creating new strings all of the time. I have 3 graphic representations of a radion button and a check box. its for a quiz program.
    if the button is not checked, it uses rd0.gif.
    if the button is checked, then its assigned rd1.gif.
    However, if the button is the wrong answer, then its assigned rd2.gif.
    the use of char arrays is neccasary, but not vital, I guess I could use indexof in the string. But I Dont know if its faster. I want to optimize the code, so it uses less resources.
    heres the code
    TrueFalse=entry[11].indexOf("TRUE");
    myButton = Integer.parseInt((String)session.getAttribute("BUTTONNO"));
    GivenAnswer =(String)session.getAttribute("GIVEN");
    if(TrueFalse==-1) {
    char[] questions = GivenAnswer.toCharArray();
    for(x=1;x<5;x++) {
    if(questions[x]=='1') { bp[x]="images/ck1.gif"; }else{ bp[x]="images/ck0.gif";}
    }else{
    if(myButton==1) {bp[1] = "images/rd1.gif";} else {bp[1] = "images/rd0.gif";}
    if(myButton==2) {bp[2] = "images/rd1.gif";} else {bp[2] = "images/rd0.gif";}
    questions is discarded.
    the quiz is fast at the begining, but once you go deeper and deeper it slows down. This is the second page:
    <%@ include file ="include4.jsp" %>
    <%
    session.setAttribute("BUTTONNO", "1");
    GivenAnswer =(String)session.getAttribute("GIVEN");
    char[] questions = GivenAnswer.toCharArray();
    questions[1]='1';
    tempString = new String (questions);
    GivenAnswer = tempString;
    session.setAttribute("GIVEN", GivenAnswer);
    %>
    <jsp:forward page="train2.jsp">
    </jsp:forward>
    I tried to keep all of the code on one page, but I am using images instead of real radio buttons, for several reasons. JSP doesnt seem to return a value for check/radio buttons in JSP, so clicking on an anchored image and going to a second JSP PAge seemed reasonable. I dont know how to force garbage collection. But the speed in which the pages and images appear, get slower and slower. so I Think im using up memory (Stings) at a greater rate than I should.
    thanks
    MIKe NIEMI
    [email protected]

    I'm not sure that an "optimisation" is necessarily what you're after. I doubt it's the creation of Strings that's causing any performance issue - even if it is then it's probably the result of something more sinister.
    Don't assume that your code is using a lot of resources.
    For example it's tempting to change it to this:
    if(myButton==1) {bp[1] = "images/rd1.gif";} else {bp[1] = "images/rd0.gif";}
    if(myButton==2) {bp[2] = "images/rd1.gif";} else {bp[2] = "images/rd0.gif";}
    // change to this?
    bp[myButton] = "images/rd1.gif";
    bp[3 - myButton] = "images/rd0.gif";I'd say that the original code was clearer and used just as many resources (once the Strings are interned).
    The same goes for this:
    if(questions[x]=='1') { bp[x]="images/ck1.gif"; }else{ bp[x]="images/ck0.gif";}
    // change to this?
    bp[x] = "images/ck" + questions[x] + ".gif";Again, the former is possibly clearer as it indicates that questions is really a boolean flag - it should also be easily optimised by the compiler.
    You're right that you could replace "questions" by simply using GivenAnswer.charAt(x).
    Enterprise Java applications can generate hundreds of thousands of Strings during their execution - your Servlet is unlikely to have a serious impact on that unless you've got an enormous loop in there or a very large user base.
    A golden rule of optimisation is not to assume that you know where the performance/resource bottlenecks are. Measure the improvement you get from a change - does it warrant the resultant increase in the complexity of the code?
    Put some profiling in your code - how long is it taking to run your Servlet? How many times is it being invoked? I can't imagine that the code you've provided will take more than a few milliseconds to run.
    Also, you can't force garbage collection. You can suggest it to the Java runtime (it might not even have a garbage collector!). However, this generally indicates a flaw in the application and should be avoided unless absolutely necessary (and it's not in this case!).
    If you really want to optimise then get hold of something like OptimizeIt - it will provide a great deal of information about what's being created and where.
    Hope this helps.

  • Can't reuse HTTPRequest  --- how can I reuse this code?

    public var getCategories: HttpRequest = HttpRequest {
        location: "http://lydias-kitchen.com/FXcategories.php";
        onInput: function(is: java.io.InputStream) {
            try {
                if(is.available()> 0){
                  categories.parser.input = is;
                  categories.parser.parse();
             } finally {
                 is.close();
                 var a = ids.size();
                 println ("categories ids size = {a}");
                 var b = bind (a-1);
                 for (i in [0 .. b]){
                    println("ids = { ids} names = {names[i]}");
    categories.newCategoryItem = com.javafx.preview.control.MenuItem {
    text: names[i]
    id: ids[i]
    onMouseClicked: function(e:javafx.scene.input.MouseEvent) {
    Main.CategoryId = e.node.id;
    println("category id = {Main.CategoryId}") ;
    recipes.getRecipes.start();
    font: Font {name: "Times New Roman" size: 20}
    graphic: ImageView {image: Image {url: "{__DIR__}images/ball.png"}
    fitWidth: 32
    fitHeight: 32
    insert newCategoryItem into Main.categoryItems;
    {code}
    I use the above code to get a PHP file to return all the recipe categories in a database table. The insert -> creates a dynamic menu. the println has confirmed that each menu item is assigned the correct text and recipe ID.
    I can click any one of the 19 "category" menu items generated and the "OnMouseClicked:" will call and start getRecipes.
    The code for getRecipes is identical to the code shown except that the returned recipes are inserted into the "recipe" menu instead of the "category" menu.
    Now it doesn't matter if I click an item in the "Recipe" or "Category" menu ......... any attempt to reuse the HTTPRequest functions will return:
    Exception in thread "AWT-EventQueue-0" java.lang.IllegalStateException: request reuse not permitted
    at javafx.io.http.HttpRequest.start(HttpRequest.fx:1316)
    at jim2.categories$categories$Script$1Local$5$1ForPart$3.invoke$(categories.fx:59)
    at com.sun.javafx.functions.Function1.invoke(Function1.java:44)
    at com.sun.javafx.functions.Function1.invoke$(Function1.java:38)
    at javafx.scene.Node.impl_processMouseEvent(Node.fx:2938)
    at javafx.scene.Node.preprocessMouseEvent(Node.fx:2967)
    at javafx.scene.Scene$MouseHandler.process(Scene.fx:1559)
    at javafx.scene.Scene$MouseHandler.process(Scene.fx:1421)
    at javafx.scene.Scene.impl_processMouseEvent(Scene.fx:686)
    at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.fx:1016)
    at com.sun.javafx.tk.swing.SwingScene$SwingScenePanel.doMouseEvent(SwingScene.java:446)
    at com.sun.javafx.tk.swing.SwingScene$SwingScenePanel.mouseClicked(SwingScene.java:454)
    at java.awt.AWTEventMulticaster.mouseClicked(Unknown Source)
    at java.awt.AWTEventMulticaster.mouseClicked(Unknown Source)
    at java.awt.Component.processMouseEvent(Unknown Source)
    at javax.swing.JComponent.processMouseEvent(Unknown Source)
    at java.awt.Component.processEvent(Unknown Source)
    at java.awt.Container.processEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Window.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)
    Since this is a recipe program you can see that I'm going to have to call the database for data each time a different category or recipe is called.
    *QUESTION: What do I have to do to get the HTTPRequest to work repeatly*
    Edited by: JWK on Feb 28, 2011 11:54 AM

    Exactly what it says; Create a new http request every single time you want to retrieve the data:
    //Records data retrieved from the request.
    var data : String;
    function makeRequest() : Void {
        //Create a new request object every time this function is called.
        var request : HttpRequest = HttpRequest {
            location: "http://en.wikipedia.org/"
            onInput: function(io : InputStream) {
                //Read input to data string and close input stream
        //Make the request connect.
        request.start();
    //Get the data
    makeRequest();
    //Get the data again.
    makeRequest();Each individual HttpRequest object is meant to be used once and only once so you need to create a new one each time.

  • How can we rewrite this query for better performance

    Hi All,
    The below query is taking more time to run. Any ideas how to improve the performance by rewriting the query using NOT EXITS or any other way...
    Help Appreciated.
    /* Formatted on 2012/04/25 18:00 (Formatter Plus v4.8.8) */
    SELECT vendor_id
    FROM po_vendors
    WHERE end_date_active IS NULL
    AND enabled_flag = 'Y'
    and vendor_id NOT IN ( /* Formatted on 2012/04/25 18:25 (Formatter Plus v4.8.8) */
    SELECT vendor_id
    FROM po_headers_all
    WHERE TO_DATE (creation_date) BETWEEN TO_DATE (SYSDATE - 365)
    AND TO_DATE (SYSDATE))
    Thanks

    Try this one :
    This will help you for partial fetching of data
    SELECT /*+ first_rows(50) no_cpu_costing */
    vendor_id
    FROM po_vendors
    WHERE end_date_active IS NULL
    AND enabled_flag = 'Y'
    AND vendor_id NOT IN (
    SELECT vendor_id
    FROM po_headers_all
    WHERE TO_DATE (creation_date) BETWEEN TO_DATE (SYSDATE - 365)
    AND TO_DATE (SYSDATE))
    overall your query is also fine, because, the in this query the subquery always contain less data compare to main query.

Maybe you are looking for