Have a look at code!!

I want to draw a rectangle in an applet and trace
the mouse pressed action only inside that rectangle
To achive this i have created 2 classes
1.Class Rect
This class extends Component and used to draw the Rectangle
using drawRect() method and used to trace the action performed
in side the Rect using a Thread
2.Class Display extends applet,implements ActionListener
and adds the textarea and the Rect class
this class is used to display the rectangle in the applet.
ActionListener is added to this class to trace any
action performed in the Rectangle.So when ever mouse key is
pressed in side the rectangle action event is generated and
that is appended into the textarea
My problem
Action event is fired in the entire area of the applet
how to get the action event(the mouse key press)only in side
the rectangle
I am drawing images dynamicaly at run time , i want to make the code
simplified,so i draw the rect in a class which extends the
component(actually i want to make the rect as a component like
button or label ) so that the addActionListener can be implemented
in that rect to trace any action
what i am doing is right ??
Here is the Runnable code
//////**class Rect***//////////////////////////
import java.awt.*;
import java.awt.event.*;
public class Rect extends Component implements Runnable,MouseListener
     public Rect(){
          addMouseListener (this);
public void paint(Graphics g)
          g.setColor(Color.red);
          g.fillRect(10,10,30,30);
public synchronized void mousePressed (MouseEvent me) {
     processAction ();}
public synchronized void mouseDragged (MouseEvent me) {}
public synchronized void mouseClicked (MouseEvent me) {}
public synchronized void mouseReleased (MouseEvent me) {}
public synchronized void mouseEntered (MouseEvent event){}
public synchronized void mouseExited (MouseEvent event){}
private ActionListener actionListener = null;
public synchronized void addActionListener (ActionListener al) {
actionListener = AWTEventMulticaster.add (actionListener, al);
public synchronized void removeActionListener (ActionListener al) {
actionListener = AWTEventMulticaster.remove (actionListener, al);
public void processAction () {
if (null != actionListener)
new Thread (this).start ();
public void run () {
try { actionListener.actionPerformed
(new ActionEvent(this,ActionEvent.ACTION_PERFORMED,toString ()));
} catch (Exception exc) {
System.out.println ("failed processAction:"+exc);
exc.printStackTrace ();
/////////////********Display***********/////////////////
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class Display extends Applet implements ActionListener{
Rect1 rect;
TextArea textarea;
public Display(){
     rect = new Rect1();
     setLayout(new BorderLayout());
     add(rect,BorderLayout.CENTER);          
     rect.addActionListener(this);          
     add (textarea = new TextArea (12,60),BorderLayout.SOUTH);          
public void actionPerformed (ActionEvent evt) {          
     textarea.append ("\n"+evt);
}

I know i can get the x and y coordenation of the
Mouse click to compare the rect area, but I
do not want to do in that way, I want to make the
rect as component like button or label to trace
the mouse click in that rect , is it possible to
do this way , will any one help me
-Ramya

Similar Messages

  • Arrrrrrr! Someone please have a look at this code!

    Ok! I'm pulling my hair out! I've got this code!
    import mx.transitions.Tween;
    import mx.transitions.easing;
    function turnOn() {
    new Tween(camel_shoe_mc, "_alpha", Regular.easeIn, 0, 100,
    1, true);
    camel_bt.onRollOver = turnOn;
    function turnOff() {
    new Tween(camel_shoe_mc, "_alpha", Regular.easeIn, 100, 0,
    1, true);
    camel_bt.onRollOut = turnOff;
    function turnOn() {
    new Tween(fudge_shoe_mc, "_alpha", Regular.easeIn, 0, 100,
    1, true);
    fudge_bt.onRollOver = turnOn;
    function turnOff() {
    new Tween(fudge_shoe_mc, "_alpha", Regular.easeIn, 100, 0,
    1, true);
    fudge_bt.onRollOut = turnOff;
    Now this is what is happning! you rollover the camel_bt the
    camel_shoe_mc show's up, great! Then you rollover the fudge_bt and
    the camel_shoe_mc come's up!! Is there a way of having this code in
    the same layer? Or do I have to make a new layer for each. Or is
    the code written wrong? I do have about 50 "_mc" so I would like to
    have the code in one place as well as the images. I hope someone
    out there can help! If you need to butcher the code by all means
    do! That's for having a look!!!!

    the code is great! Even if it should be "i++". The whoe thing
    work's like a charm! It's just what I wanted! Christmass comes
    again! Hay, seeing as I have you hear. Do you have any idea what
    code I should add to the _bt's so when you click on them it fills
    in a form at the bottom of the page? i.e rollOver the button it
    inform's you waht the color is and you click the button and it
    fill's out a combo box form at the bottom.

  • Help needed in look up code

    Hello ALL,
    I am new to ABAP and would like to check if any one can guide me through on the following issue.
    DSO-1
    Keys: promise#, doc_num, item_num,reason
    DSO-2: promise#
    field: withdrawn_reason
    restrictiont: get only withdrawn reason with 1
    DSO-3: doc_num, item_num,reason
    fields required: Doc_amount, invoice_num
    Target DSO-4: promise#, doc_num, item_num,reason, Doc_amount, invoice_num
    I need to use a lookup code in DSO-1 to Target DSO-4 transformations. I think an end routine would work here.
    here first I look DSO-2 for getting only those promise#'s that has withdrawn 1
    then I have to look for DSO-3 to get doc_amount & invoice_num.
    I am actually not much familiar with ABAP. it would be great if someone  can guide me on this.

    Hi you can do it this way.
    Fetch the values you require from DSO 2 and DSO 3 for your conditions
    Use FOR ALL ENTRIES in SOURCE_PACKAGE to fetch all at once
    i.e.
    select fields from DSO2
    into internal_table
    for all entries in source_package
    where promise#=source_package-promise#
    and withdrawn ='1'
    now select required data from DSO3 into another internal table.
    i.e.
    select fields from DSO3
    into internal_table2
    for all entries in internal_table
    where doc_number = internal_table-doc_number
    and item=internal_table-item
    and reason = internal_table-reason.
    Now write field routine to populate the doc_amount and invoice_num
    in the field routine it would be something like
    read table internal_table2 into work_area
    with key doc_number = source_fields-doc_number
    and item = source_fields-item
    and reason = source_fields-reason.
    if sy-subrc = 0. "this means the entry is found in the table
    result = work_area-doc_amount.
    "same to populate invoice_amount
    "result = work_area-invoice_num.
    endif.
    Hope this helps.
    Regards
    Joe
    Edited by: lazarus_joey on Feb 23, 2012 6:22 PM

  • Can I access my husband's iTunes acct. from my iPad?  I have his permission & pass code.  We want to keep all music in one place & family accessible.

    Can I access my husband's iTunes acct. from my iPad?  i have his permission & pass code.  We want to keep all music in one place & family accessible.

    If you log into his account and download some of his past purchases on your iPad then you risk tying your iPad to his account for 90 days : iTunes Store: Associating a device or computer to your Apple ID
    But it looks like that might change when iOS 8 is released in the Autumn (no date has been announced yet) : http://www.apple.com/ios/ios8/family-sharing/
    If you have his content in your computer's iTunes library then you could sync it from there instead of risking the 90 days association on your iPad. If you don't then you could copy it from his computer and then sync it to your iPad e.g. copy his music to a flash drive and then add it to your library via File > Add To Library

  • Can some one have a look at this php script?

    Ok! hear's the script! It work's fine! but with one problem.
    when I get the email it look's like this>
    Base Color: NaturalTread Color: Black
    What I want the email to look like is>
    Base Color: Natural
    Tread Color: Black
    ie i don't want all the "var's" on on line!
    Hear's my php code>
    Can someone have a look to give me some poniters?

    I too am learnig. And just found this>
    <?php
    $sendTo = "******@hotmail.com";
    $subject = "Combo Test Two";
    $headers = "From: " . $_POST["name"];
    $headers .= "<" . $_POST["email"] . ">\r\n";
    $headers .= "Reply-To: " . $_POST["email"] . "\r\n";
    $headers .= "Return-Path: " . $_POST["email"];
    $message .= $_POST["baseColor"] . "\r\n";
    $message .= $_POST["treadColor"] . "\r\n";
    mail($sendTo, $subject, $message, $headers);
    ?>
    u need to put Line-Feed & Carridge Return:
    \r\n
    And good luck to you! Thanks for the help my friend!

  • Have a look at my RFC call, it doesn't return anything

    Hi all,
    In my project, I create a RFC Model named 'SCO' which will call bapi function 'BAPI_SALESORDER_CREATEFROMDAT1', if successfully a SALEDOCUMENT should return.
    below is the code in my custom controller
      public void wdDoInit()
        //@@begin wdDoInit()
              Bapi_Salesorder_Createfromdat1_Input input =
                   new Bapi_Salesorder_Createfromdat1_Input();
              wdContext.nodeCSOC_Input().bind(input);
              input.setOrder_Header_In(new Bapisdhead());
              input.addOrder_Items_In(new Bapiitemin());
              input.addOrder_Partners(new Bapipartnr());
        //@@end
    public void executeBapi( )
        //@@begin executeBapi()
              try {
                   wdContext.currentCSOC_InputElement().modelObject().execute();
              } catch (WDDynamicRFCExecuteException e) {
                   // TODO Auto-generated catch block
                   System.err.println(e.getMessage());
                   e.printStackTrace();
              } finally {
    //               wdContext.nodeCSOC_Input().invalidate();
        //@@end
    In my view(TestSOCView) I mapped a node named SOC_Input has the structure
    Order_Header_In
    -Distr_Chan
    -Division
    -Doc_Type
    -Sales_Org
    Order_Partnr_In
    -Partn_Numb
    -Partn_Role
    Order_Items_In
    -Material
    -Req_Qty
    Output
    -Return
    --Message
    --Type
    -Salesdocument
    I have a very simple view which has only one button and two textview (one bind to Output-Salesdocument, another to Output-Return-Message)
    In my action method, I have the code
      public void onActionCreateSO(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )
        //@@begin onActionCreateSO(ServerEvent)
              IOrder_Header_InElement newHeader =
                   wdContext.currentOrder_Header_InElement();
              IOrder_PartnersElement newPartner =
                   wdContext.createOrder_PartnersElement(new Bapipartnr());
              IOrder_Items_InElement newItem =
                   wdContext.createOrder_Items_InElement(new Bapiitemin());
              newHeader.setSales_Org("1000");
              newHeader.setDoc_Type("OR");
              newHeader.setDistr_Chan("10");
              newHeader.setDivision("00");
    //          wdContext.nodeOrder_Header_In().addElement(newHeader);
              newPartner.setPartn_Role("SP");
              newPartner.setPartn_Numb("1000");
              wdContext.nodeOrder_Partners().addElement(newPartner);
              newItem.setMaterial("TEST2");
              newItem.setReq_Qty("00001000");
              wdContext.nodeOrder_Items_In().addElement(newItem);
              wdThis.wdGetSOCControllerController().executeBapi();
        //@@end
    This is all my implementation, I dont know why there's always nothing retrieved, even no Return Message.
    I of course have the right JCO connection, if not, this view will not display.
    My wonder is my initilization for two table maybe wrong:
    input.addOrder_Items_In(new Bapiitemin());
    input.addOrder_Partners(new Bapipartnr());
    because I know there's a method
    set<Node>(AbstractList)
    but this is not java.util.AbstractList, I dont know how to initiate this list.
    And if I follow the turtorial which will enable the line after execution
    wdContext.nodeCSOC_Input().invalidate();
    This will make my application run only one time, the second time a NullPointerException will be thrown. So there's also a question: what's the usage of this line?
    Any one have a look at my problem? Thanks in advance
    And at last,
    Happy New Year to everyone.
    Wish you all a nice new year.
    best regards,
    William

    Hello William,
    Try using the following code:
    public void wdDoInit()
    //@@begin wdDoInit()
        Bapi_Salesorder_Createfromdat1_Input input =
        new Bapi_Salesorder_Createfromdat1_Input();
    //@@end
    public void onActionCreateSO(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )
    //@@begin onActionCreateSO(ServerEvent)
    <b>/*** Instantiate the Structure ***/
    /// <Name of the Structure> = <Order_Header_In></b>   Order_Header_In newHeader =
        new Order_Header_In();
        newHeader.setSales_Org("1000");
        newHeader.setDoc_Type("OR");
        newHeader.setDistr_Chan("10");
        newHeader.setDivision("00");
        wdContext.currentBapi_Salesorder_Createfromdat1_Input().setOrder_Header_In(newHeader);
    <b>*** Instantiate the Structure ***/
    /// <Name of the Structure> = <Order_Partners></b>    Order_Partners newPartner = new Order_Partners();
        newPartner.setPartn_Role("SP");
        newPartner.setPartn_Numb("1000");
        wdContext.currentBapi_Salesorder_Createfromdat1_Input().modelObject().addOrder_Partners(newPartner);
    <b>*** Instantiate the Structure ***/
    /// <Name of the Structure> = <Order_Items_In></b>    Order_Items_In newItem = new Order_Items_In();
        newItem.setMaterial("TEST2");
        newItem.setReq_Qty("00001000");
                 wdContext.currentBapi_Salesorder_Createfromdat1_Input().modelObject().addOrder_Items_In(newItem);
        wdThis.wdGetSOCControllerController().executeBapi();
    //@@end
    This will work.
    <b>
    Please reward appropriate points</b>
    Bala

  • Looking for Code Review Resources

    We have completed a complex project using jakarta struts and are in beta testing at the moment.
    Would like to have someone review our code but we have not been able to find expierienced developers in our (physical) area.
    Does anyone have suggestions on where I could look to find a qualified individual for independent code review.
    Thank you in advance for your suggestions.

    Just post it here. Some of our fine reviewers will be happy to serve you.
    P.S. Be sure to say that it's homework.

  • My Artificial Intelligent (AI) Application. Have a look! :)

    Hello,
    I thought I might just share this with the community. I developed an App with XCode's Applescript studio for my Gooogle Science Fair submission. The program consists roughly of 2000 lines of code. The application called "Simple" lets Users program their robots (NXT MINDSTORMS) in english.
    Have a quick look at my *project summary (video)*: Summary of Project
    Have a quick look at my *application demo (video)*: Demo of App
    Have a look at my *submission website*: My website
    Your feedback is welcome.
    +(Source code can be found under the "data" page of my website)+

    Your source code download consists of only the xcodeproj file, which just has xcode's project settings. If someone is going to be looking at your project files, you will need to zip up all of the items in the project folder, minus the build folder.

  • Hey eric i have commented ont he multiply matrix question....please have a look into it and kindly help!

    didn't know if it wud come through to uSo i thought i wud post it too...sorry if its a mess!!

    CMS's like  WordPress, Joomla! & Drupal are popular open source (PHP & MySql) frameworks.  They contain all the backend PHP code needed to create a dynamic web site that contains capability for advanced functions:  site search, on-line editing, shopping carts, member log-in sites, blogs with comments, scripted contact forms, and so much more...
    The allure of Open Source frameworks is that they save developers time and money.  Instead of building everything from scratch (which can take months), an experienced developer can usually install WordPress on the client's server and be up & running in a few hours without customizations, or in a couple of weeks with customizations.   A firm understanding of PHP, how to set up a server-side database, backing up MySql, CSS theming, and HTML code are required skills to work with these frameworks.  WordPress is probably the easiest to set-up; Drupal is for more experienced coders.
    I am still not sure how I will know when I am competent enough to work in Web Design... What are the best signs that an individual is good enough?
    You're ready when you can look at code and understand what it means/does. Being able to problem solve, identify mistakes and fix them on your own is a must have skill. 
    Code Tutorials - http://w3schools.com/
    How to Develop with CSS?
    http://phrogz.net/css/HowToDevelopWithCSS.html
    CSS positioning in 10 Steps
    http://www.barelyfitz.com/screencast/html-training/css/positioning/
    Code Validation Tools
    CSS - http://jigsaw.w3.org/css-validator/
    HTML - http://validator.w3.org/
    Nancy O.
    Alt-Web Design & Publishing
    Web | Graphics | Print | Media  Specialists 
    http://alt-web.com/
    http://twitter.com/altweb

  • Could you help me with an app situation? We purchased several codes for Splashtop to install on our iPad 2's. It was working great but now that we upgraded the OS they have disappeared. The codes that we purchased are giving us an error that they have alr

    Could you help me with an app situation? We purchased several codes for Splashtop to install on our iPad 2's. It was working great but now that we upgraded the OS they have disappeared. The codes that we purchased are giving us an error that they have already been used. So far it has only been 2 iPads. 
    Any solutions?

    The compiler is highlighting the areas you got wrong, although the error messages are somewhat confusing.
    Error 1: NSLog is a function and needs to be called as such, see e.g. the circleArea call on the line above. Functions are called using the function-name with its arguments in paratheses e.g. foo(12, 13).
    Error 2: looks like a typo, defining a function is done as function-name(... <arguments> ...) { ... <body> ...}. In your code there is a ";" between the arguments and the body that should not be there, you probably copy pasted it from the forward declaration at the top of the source codde file.

  • My ipod wont let me buy any apps because it says i have an invalid security code for my moms credit card but its the right one. and it also says i owe money for upgrading an app does anyone know how to remove my moms credit card cause i cant figure itout

    my ipod wont let me buy any appps because it says i have an invalid security code for my moms credit card but its the right one. and it also says i owe money for upgrading an app does anyone know how to remove my moms credit card cause i cant figure itout

    To change asccount information see:
    Changing Account Information
    For the code issue this may help.
    iTunes Store: My credit card's security code or zip code does not match my bank's records
    For a standard iTunes account you need a valid payment method even for free apps and app updates.
    What is making it think that you own money for an app upgrade?

  • My iMac just crashed, and I had some documents open in Pages that were unsaved. Is there a temporary file or backup file that I can access as on a PC? (I have just looked in Timemachine which I had operating, but it did not seem to have any temp files).

    My iMac just crashed, and I had some documents open in Pages that were unsaved. Is there a temporary file or backup file that I can access as on a PC? (I have just looked in Timemachine which I had operating, but it did not seem to have any temp files in it at all - not sure what it would be useful for then).
    Any suggestions?

    Question asked and answered several times.
    If you didn't save, nothing is recoverable.
    iWork apps don't create temp files so, as far as you on't save something, Time Machine can't archive it.
    Yvan KOENIG (VALLAURIS, France) mardi 5 juillet 2011 12:25:31
    iMac 21”5, i7, 2.8 GHz, 4 Gbytes, 1 Tbytes, mac OS X 10.6.8
    Please : Search for questions similar to your own
    before submitting them to the community
    To be the AW6 successor, iWork MUST integrate a TRUE DB, not a list organizer !

  • HT5035 Is there a way to redeem iTunes account if I no longer have the card or code number

    Is there a way to redeem iTunes gift card credits if I no longer have my card or code?

    I do not have a card the credits were given for issues that I had with itunes not via a card

  • I have got 2 iPad Air one of it is not logging me in because I have forgotten the pass code and have logged out from iCloud by accident. Can you please help me to use my iPad.

    HI
    I have 2 IPads, I am unable to use one of it because I have forgotten my pass code and also logged out from iCloud accidentially. Can you please help me to solve this problem.
    Cheers
    Raveena

    Follow the instructions on this page : Forgot passcode for your iPhone, iPad, or iPod touch, or your device is disabled - Apple Support

  • I wish to reset my ipad.  However, when I selectGeneral Reset Erase all content and Settings, I am prompted for a a Restrictions Passcode (which I have never set).  I have now entered random codes 11 times and the ipad not reset. How do I get past this?

    I wish to reset my ipad (as advised by the Apple Store) to attempt to resolve an issue with a non-responsive part of the screen..  However, when I select General>Reset>Erase all content and Settings, I am prompted for a a Restrictions Passcode (which I have never set).  I have now entered random codes 11 times and the ipad has not reset. How do I get past this?  I am now at the point where I have to wait 60 mins before I can enter another random passcode.  I just want the ipad to clear down, erase everything so I can start again.

    The other option is to force iPad into Recovery Mode.
    http://support.apple.com/kb/HT1808
    Note: You need to be patient and repeat the above many times to recover your iPad

Maybe you are looking for