Program works but..........

My program works. It is a program to track rainfall during a week. You enter in a number, hit enter, then click the box and the number will appear in the box. The problem is you can click outside of the box and get the same results. How can I get it to when you click outside the box, nothing will happen, only when you click inside the box something will happen. I hope this makes sense.
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class Rainfall extends Applet implements ActionListener,
                                                                      MouseListener
{//begin class
protected Table rainData;
protected TextField value;
protected int newValue;
protected int yCoord;
protected int index;
protected int sum = 0;
     public void init()
     {//begin init
          //setBackground(Color.cyan);
          rainData = new Table();
          Label name = new Label("Enter number and click component");
          add(name);
          value = new TextField(10);
          add(value);
          value.addActionListener(this);
          addMouseListener(this);
     }//end init
     public void paint(Graphics g)
     {//begin paint
          rainData.display(g);
     }//end paint
     public void actionPerformed(ActionEvent event)
     {//begin ActionEvent
          newValue = Integer.parseInt(value.getText());
          rainData.setValue(newValue);          
          repaint();
     }//end ActionEvent
     public void mouseClicked(MouseEvent event)
     {//begin MouseEvent                              
          yCoord = event.getY();
          rainData.selectComponent(yCoord);          
          repaint();
     }//end MouseEvent
     public void mouseReleased(MouseEvent event)
     public void mousePressed(MouseEvent event)
     public void mouseEntered(MouseEvent event)
     public void mouseExited(MouseEvent event)
}//end class
class Table extends Rainfall
{//begin class Table
     private final int tableSize = 7;
     private int[] rain = new int[tableSize];
     private final int startX = 20;
     private final int startY = 40;
     private final int boxHeight = 20;
     private final int boxWidth = 40;
     public void display(Graphics g)
     {//begin display
          int y = startY;
          for(int day = 0; day < 7; day++)
          {//begin for
               g.drawRect(startX, y, boxWidth, boxHeight);
               g.drawString(Integer.toString(rain[day]),
                         startX, y + boxHeight * 3/4);
               y+=boxHeight;
          }//end for
          addValues();
          g.drawString("Total rainfall is " + sum, 100, 100);
     }//end display
     public void selectComponent(int y)
     {//begin selectComponent
          index = (y - startY)/boxHeight;
          rain[index] = newValue;          
     }//end selectComponent
     public void setValue(int value)
     {//begin setValue
          newValue = value;
     }//end setValue
     private void addValues()
     {//begin addValues
          sum = 0;
          for(int day = 0; day < 7; day++)
               sum=sum+rain[day];
     }//end addValues
}//end class Tables

....see this line: "addMouseListener(this);"
don't do that :)
you're capturing all the Applet's mouse events...not just the button

Similar Messages

  • I am unable to open my Photoshop program after installing the entire Creative Suite: Premium Production 6. All other programs work, but with Photoshop it says that the program is "locked or in use by another user". I need this fixed immediately.

    I am unable to open my Photoshop program after installing the entire Creative Suite: Premium Production 6. All other programs work, but with Photoshop it says that it "Could not open a scratch file because the file is locked, you do not have necessary access permissions, or another program is using the file. Use the 'Properties' command in the Windows Explorer to unlock the file." Then I select "OK" and the next message comes up "Could not initialize Photoshop because the file is locked, you do not have the necessary permissions, or another program is using the file. Use the 'Properties' command in the Windows Explorer to unlock this file. I installed all of the programs on the same day from a CD. I need this fixed immediately.
    I am not interested in switching to Creative Cloud, so don't even suggest it. I spoke to Mashmi (or something to that effect) on the "Support" Chat and there was absolutely no support. Useless actually.
    Thanks in advance.

    Could not open a scratch file because the file is locked or you do not have the necessary access privileges. (…) | Mylen…
    Mylenium

  • Program works but background job for that program fails....

    I have a requirement where I have to collect the details of the purchase order and put the details in XML file format and FTP the XML file to an external third party FTP Server.
    To realize this I developed a report program which follows following logic.
    1)     First I collected the PO details by calling the BAPI BAPI_PO_GETDETAIL1.
    2)     Then using the following link "/people/r.eijpe/blog/2005/11/10/xml-dom-processing-in-abap-part-i--convert-an-abap-table-into-xml-file-using-sap-dom-approach
    I converted these PO details to the XML file format that the third party people accept.
           In the code I used u201CCALL METHOD cl_gui_frontend_services=>gui_downloadu201D and in this process first the XML file is generated and is getting stored on my deskytop.
    3)     Then I called HTTP_SCRAMBLE, FTP_CONNECT, FTP_COMMAND , FTP_DISCONNECT and RFC_CONNECTION_CLOSE.
    This works perfectly well and each time I execute the report the file is getting FTPu2019ed to the third party FTP server.
    Now I tried to schedule a batch job for this and the batch job fails with follwing errors
    02/25/2009 15:08:47 Error in Control Framework
    Message Class  = FES         
    Message Number = 022  
    Message Type   = E
    02/25/2009 15:08:47 Job cancelled after system exception ERROR_MESSAGE 
    Message Class  = 00        
    Message Number = 564  
    Message Type   = A                
    Can some one tell me what is going wrong. My report works perfect in front end but fails if I try to schedule a background job for it in SM36.
    Can you please tell me whatz going wrong with batch job? Any Help is highly appreciated.
    Regards,
    JEssica SAm

    Robert...Thanks for the reply...
    I am using follwing code
    l_xml_size = l_ostream->get_num_written_raw( ).
        CALL METHOD cl_gui_frontend_services=>gui_download
          EXPORTING
            bin_filesize = l_xml_size
            filename     = FILEPATH
            filetype     = 'BIN'
          CHANGING
            data_tab     = l_xml_table
          EXCEPTIONS
            OTHERS       = 24.
        IF sy-subrc <> 0.
          MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                     WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    Now what changes should i make..where should i store my XML file then instead of my desktop?
    and whih Function Module should i Use..

  • Weird scanner problem, no program works but vuescan

    Today i installed my epson xp-201 printer/scanner to scan some photos. I was able to scan once, but when i want to scan another photo, it never worked again.
    When i ran scanimage -L, i saw the scanner just once too, and it never appeared again. I changed the usb cable, and rebooted the system several times with same results.
    But, vuescan works perfect. It's so weird...
    Thanks in advance!

    raavas wrote:
    acampbell wrote:Have you tried as root? See my yesterday's post regarding a different Epson scanner which works only as root with xsane but is fine with vuescan.
    t
    Apologies if this is classified as thread necromancy, but this was extremely helpful! Such a simple thing fixed it for my Epson XP-215.
    Having to do this as root is not exactly an ideal solution! However in my case I think that the problems are not yet triaged and there are many reported issues running scanners with usb3 ports on the machine they are connected to, with analogous posts on forums for a number of different linux distributions. I have also more recently been engaged in a developer thread on the xsane dev list and provided diagnostics as best I can, but it is still not clear whether there are issues with the usb code in the kernel, the libusb code or within sane itself.  I was able to get at the packet stream whilst the scanner failed using usb debugging and capturing the stream with wireshark. However the developers have not been able to tie down what the problem is so this is ongoing.
    In your case it would be interesting to know if you were using a usb3 or a usb2 port on the computer?
    Last edited by mcloaked (2014-11-23 21:14:50)

  • My program works but.....  please help

    heres my problem. my applet asks a math question ( what is x * y ) and user inputs answer in jtext field. when answer is correct, status bar displays " very good!"
    if incorrect, status bar displays " sorry, try again". it does this fine, however when the user answer correctly a new problem should be painted on the applet. thats where my problem is, i cant get it to refresh the question.
    here is a summary of my code.
    public void init()
    container....
    Jtextfield....
    public void paint( Graphics g)
    paints the question here
    public void actionPerformed(ActionEvent actionEvent)
    if / elsestatements checking if answer is correct
    public int calculation()
    math.random() class method
    i know i need to put a while loop in there but i dont know where and i dont know how to call the method that needs to be called. any guidance is greatly appreciated.
    thanks

    add stuff like this. Everything that is bolded add. NOTE, I am assuming calculate is your button.
    boolean flag = false;
    public void init()
    container....
    Jtextfield....
    public void paint( Graphics g)
    paints the question here
    public void actionPerformed(ActionEvent actionEvent)
    if(actionEvent.getSource() == calculate){
    flag = true;
         if / elsestatements checking if answer is correct
         if(flag){
    repaint();
    flag = false;
    public int calculation()
    math.random() class method
    }If this works could I have some Duke Dollars?

  • I have a MacBook Pro with Snow Leopard. After connecting my HP Photosmart D110 to it, the printer works but the scanner doesn't. The message is"The scan cannot be performed because another program has control of the HP imaging device". Can anyone help?

    I have a MacBook Pro with Snow Leopard. After connecting my HP Photosmart D110 to it, the printer works but the scanner doesn't. The message is"The scan cannot be performed because another program has control of the HP imaging device". Can anyone help?

    Found the answer on the HP site. It's the original software that works with this printer OS X 10.6!!
    http://h20000.www2.hp.com/bizsupport/TechSupport/SoftwareDescription.jsp?lang=en &cc=us&prodTypeId=18972&prodSeriesId=3558902&prodNameId=3562006&swEnvOID=219&swL ang=8&mode=2&taskId=135&swItem=ma-60835-3

  • Dvd/cd drive works but won't allow me to install new programs from disk, doesn't recognize the disk,

    dvd/cd drive works but won't allow me to install new programs from disk, doesn't recognize the disk, what can I do?

    Well I was able to obtain a work around download of Flash and it installed fine but Firefox tells me it needs updating so I go out, thinking I'm "IN" finally to update it and I get that issue of not being able to get the update for it.  It's a regular laptop, not a touch screen or one of those new fangled ones for todays world.  In fact it's a refurb so it's probably origin date was a year or so ago before all this MS stuff took off fully.  So not understanding why I'm feeling like I'm being BLOCKED from getting the updated Flash I need and desire.  If I click on the little "X" and tell it to ignore the warning the vid will play just fine but don't want to have to do that every time.  Must be a better way. 
    Again, I'm sorry for posting in the wrong forum, getting this posted in the Flash forum was my desire but the way Adobe has this set up I just couldn't figure it out.  I belong to ALLOT of forums and most are pretty straight forward but this one is confusing! 

  • OCI - Sample program works on Windows but gives error in Solaris ??

    Hi,
    I am new to OCI. I was trying the following sample program:
    #include<iostream>
    #include<conio.h>
    #include<firstheader.h>
    //#include<stdafx.h>
    #include<string.h>
    using namespace std;
    class OCIClass
    public:
         OCIClass()
    int p_bvi;
    char p_sli[20];
    int rc;
    char errbuf[100];
    int errcode;
    const char *s;
    printf("Hello\n");
    string sql;
    string sql2="select substr(ename,1,3) from emp where job='ANALYST'";
    cout<<sql2;
    //char sql[512];
    int flag=0;
    sql += "SELECT * from emp where job='";
    if (flag==0)
    sql += "MANAGER";
    else
    sql += "ANALYST";
    sql += "'";
    cout<<sql + "\n";
    s=sql.c_str();
    char* cstr = new char[sql.size()+1];
    strcpy (cstr, sql.c_str());
    char* cstr2 = new char[sql2.size()+1];
    strcpy (cstr2, sql2.c_str());
    sql=" ";
    /* Initialize evironment */
    rc=OCIEnvCreate((OCIEnv **)&p_env,(ub4)OCI_DEFAULT ,(void *)0, (void * (*)(void *, size_t))0,
    (void * (*)(void *, void *, size_t))0,(void (*)(void *, void *))0,(size_t)0, (void **)0);
    /* Initialize handles */
    rc = OCIHandleAlloc( (dvoid *) p_env, (dvoid **) &p_err, OCI_HTYPE_ERROR,
    (size_t) 0, (dvoid **) 0);
    printf("Error handle allocated\n");
    rc = OCIHandleAlloc( (dvoid *) p_env, (dvoid **) &p_svc, OCI_HTYPE_SVCCTX,
    (size_t) 0, (dvoid **) 0);
    printf("service handle allocated\n");
    printf("Value of RC before Logon\n %d", rc);
    /* Connect to database server */
    rc = OCILogon(p_env, p_err, &p_svc, (OraText *)"scott", 5,(OraText *) "welcome", 7,(OraText *) "", 0);
    printf("Value of RC after Logon\n %d", rc);
    if (rc != 0) {
    OCIErrorGet((dvoid *)p_err, (ub4) 1, (text *) NULL, &errcode, (OraText *)errbuf, (ub4) sizeof(errbuf), OCI_HTYPE_ERROR);
    printf("Error - %s\n",errbuf);
         printf("error");
    //exit(8);
         getch();
    printf("Connect successful\n");
    /* Allocate and prepare SQL statement */
    rc = OCIHandleAlloc( (dvoid *) p_env, (dvoid **) &p_sql,
    OCI_HTYPE_STMT, (size_t) 0, (dvoid **) 0);
    rc = OCIStmtPrepare(p_sql, p_err, (OraText*) cstr,
    (ub4) 37, (ub4) OCI_NTV_SYNTAX, (ub4) OCI_DEFAULT);
    /* Bind the values for the bind variables
    p_bvi = 10; /* Use DEPTNO=10
    rc = OCIBindByName(p_sql, &p_bnd, p_err, (text *) ":x",
    -1, (dvoid *) &p_bvi, sizeof(int), SQLT_INT, (dvoid *) 0,
    (ub2 *) 0, (ub2 *) 0, (ub4) 0, (ub4 *) 0, OCI_DEFAULT);*/
    /* Define the select list items */
    rc = OCIDefineByPos(p_sql, &p_dfn, p_err, 1, (dvoid *) &p_sli,
    (sword) 20, SQLT_STR, (dvoid *) 0, (ub2 *)0,
    (ub2 *)0, OCI_DEFAULT);
    /* Execute the SQL statment */
    rc = OCIStmtExecute(p_svc, p_sql, p_err, (ub4) 1, (ub4) 0,
    (CONST OCISnapshot *) NULL, (OCISnapshot *) NULL, OCI_DEFAULT);
    while (rc != OCI_NO_DATA) {             /* Fetch the remaining data */
    printf("%s\n",p_sli);
    rc = OCIStmtFetch(p_sql, p_err, 1, 0, 0);
    printf("After fetch\n");
    rc = OCILogoff(p_svc, p_err); /* Disconnect */
    rc = OCIHandleFree((dvoid *) p_sql, OCI_HTYPE_STMT); /* Free handles */
    rc = OCIHandleFree((dvoid *) p_svc, OCI_HTYPE_SVCCTX);
    rc = OCIHandleFree((dvoid *) p_err, OCI_HTYPE_ERROR);
    void main()
    OCIClass c1;
    getch();
    The above program works on my Windows desktop. If I try this in Solaris, OCILogon fails and gives an error. If I check the value of rc, I find that it is -2. I can connect to the database using SQLPlus, but not through the program. Not sure how to debug this...
    Any pointers ?
    Thanks in advance,
    mrk

    Did you make the required port entry in the /etc/services file? You will need to add the gateway service port there. Then try to run your program.
    T00th

  • Student account for Adobe CC - downloaded and worked but only for TRIAL - now asks for license - how do I access the programs? I was given a redemption code (apparently redeemed already). How do I get the licensing code?

    Student account for Adobe CC - downloaded and worked but only for TRIAL - now asks for license - how do I access the programs? I was given a redemption code (apparently redeemed already). How do I get the licensing code?

    Ask whom/wherever you got the redemption code from for one that has not already been used.

  • I have new MacBook Pro with OS 10.10.  My MAIL program was working but suddenly won't recognize my VERIZON FIOS server.   FYI, the MAIL programs on my iPAD and old iMAC continue to work. No answer yet from Apple Support HELP!!!

    I have new MacBook Pro with OS 10.10.  My MAIL program was working but suddenly won’t recognize my VERIZON FIOS server.  FYI, the MAIL programs on my iPAD and old iMAC continue to work. No answer yet from Apple Support HELP!!!

    Additional Information. 
    On my Mail Accounts setup it was set to "verizon.net" on incoming.
    Now it faintly reads, "incoming.yahoo.verizon.net"
    This came up automatically ....  I did not do it and I cannot change it

  • I have an ipad 2 the itunes program worked fine at first but now it will not connect to the store. it says 'secure link to itune store failed' i have uninstalled it and reinstalled it. what do i do

    i have an ipad 2 the itunes program worked fine at first but now it will not connect to the store. it says 'secure link to itune store failed' i have uninstalled it and reinstalled it. what do i do?

    Doublechecking before proceeding. Is iTunes endlessly saying "Accessing iTunes Store"? Or is something a bit different going on?

  • Program compiles but doesn't work

    The folowing program compiles, but it doesn't work, when I type GuessingGame.play(5); into the interactions pane, I get the message
    No 'play' method in 'GuessingGame'. All my brackets line up and I can't see where the problem is. I would definitely apreciate it if you could help!
    /** Allows a user to play a number-guessing game.
    The constructor takes the integer to be guessed. */
    public class GuessingGame {
    int theNumber; //The number to be guessed by the user.
    int guessNumber; //The users guess.
    public void play(int g){
    theNumber=g;
    guessNumber = Integer.parseInt(JOptionPane.showInputDialog("Guess an integer."));
    while(guessNumber!=theNumber){
    if(guessNumber > theNumber){
    JOptionPane.showMessageDialog(null, "Your guess was too high. Guess again.");
    else if(guessNumber < theNumber){
    JOptionPane.showMessageDialog(null, "Your guess was too low. Guess again.");
    JOptionPane.showMessageDialog(null, "You're right!");

    Sorry, it's just that no-one was answering, it took over 2 hours to get a response. I finally got some help now(with the topic as 'Fun to be had by all!'), so you can now just ignore all of them.

  • I have just subscribed to Photoshop Photography Program, Lightroom works but Photoshop CC doesn't, I don't think it has down loaded, can anyone help please?

    I have just subscribed to Photoshop Photography Program, Lightroom works but Photoshop CC doesn't, I don't think it has down loaded, can anyone help please?

    HI,
    What error are you getting?
    You are having issues with installing Photoshop or launching it?
    -Pragya

  • Hello. I am having much difficulty using any software drum program. I am trying to use EZ Drummer and the drum programs in Logic, with limited success. I was using them, and they were working, but this is no longer the case. Please help me navigate my way

    Hello.
    I am having much difficulty using any software drum program. I am trying to use EZ Drummer and the drum programs in Logic, with limited success. I was using them, and they were working, but this is no longer the case. Please help me navigate my way through these issues, if possible.
    Thanks.
    Eric

    Aha! I have sorted it.
    For those with similar problems, the solution is this:
    Macintosh HD > Library > Audio > MIDI Drivers
    Then delete DigiDioMidiDriver.plugin

  • I am working on a PC.  My InDesign CS6 was working but is now missing its amtlib.dll file.  To fix it it says to reinstall program but I was am idiot and didn't make a copy.  Is there any way to reinstall this missing file?

    I am working on a PC.  My InDesign CS6 was working but is now missing its amtlib.dll file.  To fix it it says to reinstall program but I was am idiot and didn't make a copy.  Is there any way to reinstall this missing file?

    It was bought for my son and he never registered it. 
    I still don't understand why Neema was trying to reinstall it when she didn't have the serial number but after she uninstalled it, said she couldn't reinstall it because I didn't have the serial number.  I never had it yet she didn't have a problem with trying to install it originally.
    Still won't buy another Adobe product again.  I've talked to a lot of people who can't stand Adobe and I now know why.  I can't even update Flash without my whole system crashing or getting a virus.
    I won't re-purchase InDesign either.  I realize it should have been registered and I explained that my email had been hacked and my proof of purchase was deleted with ALL of my emails and I also had a major virus after updating Flash.
    I can't afford to buy the same product twice.
    I will find out what other formats my book distributor (Ingram Books) accepts and purchase that program.
    Not impressed with Adobe and will share my experience with others so they can be sure to register their product and make a copy of the program BEFORE allowing an Adobe employee to take control of their computers.
    If you knew the answer to my question, customer support should have too.
    Thanks for your help.
    Denise

Maybe you are looking for

  • Time machine is making two backup folders for my external drive

    I have two external drives connected to my iMac, running 10.6.8.  One is the Time Machine drive; the other is PhotosMovies.  I've been having trouble for the last several months where about once a week my Time Machine backups won't finish, no matter

  • Query related to Discoverer Rpt

    Hi all, I have a problem in creating a report , I have 2 database fields Invoice Amt and Prepaid Amt , I want the third field to be the diff of these two fields eg: Note************************** IA=InvoiceAmt PA=PrepaidAmt RA=RemainingAmt First colu

  • Are you using the Extended Classic Scenario ?

    Hello everybody, Is somebody using the Extended Classic Scenario - SRM 4.0 ? If yes, could you describe briefly the config steps that you follow ?     I have received and followed some advices here and I have checked all the official documents withou

  • How to Install Java Studio Creator

    Hello: I have a question regardin on how can I optimize the resources that my enterprise already have. I.e I can put an X86 Server (i mean really a server) to be an application server, however i can do It with the Java Studio Enterprise, but not on t

  • Load multiple swf play one by one when required

    Dear Friends, i want to Load multiple swf play one by one when required, i mean, i want to reduce the loading time, so i cut my swf in to 2 portion, load both same time or load 2nd while 1st one playing and how can i show the 2nd one when first one f