How can make Jpanel response click event?(help!)

in a program i want to make jpanel response mouseclicked event, but jpanel class does not provide addActionListener(). through which way? i am able to arrive at the purpose! (create a new class extends jpanel, how to do?)
thank a lot!!!

Hello,
have a look:import java.awt.Color;
import java.awt.event.*;
import javax.swing.*;
public class ClickPanel extends JPanel implements MouseListener
     public static void main(String[]args)
          JFrame frame = new JFrame("Click-Panel");
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.getContentPane().setLayout(null);
          frame.getContentPane().add(new ClickPanel());
          frame.setBounds(200,200,400,400);
          frame.setVisible(true);
     public ClickPanel()
          addMouseListener(this);
          setBounds(200,200,100,100);
          setBackground(Color.CYAN);
     public void mouseClicked(MouseEvent e)
          System.out.println("clicked");
     public void mouseEntered(MouseEvent e)
          System.out.println("entered");
          setBackground(Color.ORANGE);
     public void mouseExited(MouseEvent e)
          System.out.println("exited");
          setBackground(Color.CYAN);
     public void mousePressed(MouseEvent e)
          System.out.println("pressed");
     public void mouseReleased(MouseEvent e)
          System.out.println("released");
}regards,
Tim

Similar Messages

  • How can i call mouse click event from keypress event???

    How can i call mouse click event from keypress event???
    I want same GUI changes to be occured at key press.....i.e . button going down & comming up.....
    for calculator

    Put all the code that happens on those events into a method. Then call that method from both events.

  • How can I capture mouse click events on BSP or Web Dynpro ABAP Screen

    hi Guys,
    Currently we have a user inactivity problem,
    the requirement is: if user is clicking on BSP/Web Dynpro ABAP screen, he/she is considered active. so we need an mechanism to capture the mouse click event.
    Using Firebug, we found that this js is in the iframe which contains BSP/web dynpro scrren: /sap/public/bc/ur/nw5/js/languages/urMessageBundle_en.js
    we want to find this js file & put in some javascript code to track user's mouse click, but i cannot find it on server.
    while in ie if we type http://host:port/sap/public/bc/ur/nw5/js/languages/urMessageBundle_en.js
    this file can be downloaded, means this file is there.
    Any one can help on this issue? find the js file or another way to capture the mouse click event.
    Thanks a lot with points!

    Hi  Feng Guo,
                        We can not capture mouse click events on Web Dynpro ABAP Screen . I am not sure about BSP. But as for as I know the portal keep active the iViews until unless mouse clicks happens.
    But for your problem I think you can get solution by setting iView Expiration to some more time period.
    Regards,
    Siva

  • I downloaded Itunes to my computer today to update my ipod's ios (4.2.1 yes i know im way behind) but when i click check for updates it tells me my ios is the current one. How can i fix this? please help!

    I downloaded Itunes to my computer today to update my ipod's ios (4.2.1 yes i know im way behind) but when i click check for updates it tells me my ios is the current one. How can i fix this? please help!

    and at the same time....
    I guess you can be glad that you at least aren't "way behind"!
    Cheers,
    GB

  • HT4759 How can make the events listed in my chalenda become automatically a reminder in the reminder?:

    How can make the events listed in my chalenda become automatically a reminder in the reminder?:

    Welcome to the Apple community.
    Calendar and reminders are two different and separate apps, you cannot transfer information between the two of them.

  • I cracked my screen. I want to use other monitor which I had one. I bought Apple Mini-DP to VGA adapter. It worked. It means I can see ADDITIONAL screen. However I want to use this monitor for the main screen. How can I do?? Please help.

    I cracked my screen. I want to use other monitor which I had one. I bought an Apple Mini-DP to VGA adapter. It worked. It means I can see ADDITIONAL screen. However I want to use this monitor for the main screen. How can I do?? Please help.

    You have the display set in Extended Desktop mode. The Menu Bar and Dock will be on the MacBook display and your background screen on the monitor. In System Preferences>Display on the MacBook screen there should be an Arrangement tab when you have the MacBook hooked up to the monitor and both screens working. When you click the Arrangement tab do you see two monitors side by side? One of them will have a Menu Bar at the top. Just click on the Menu Bar and drag it to the second monitor. That will make the second monitor your main screen. You can now use your MacBook in Clamshell Mode with a wired or Bluetooth keyboard and mouse.  http://support.apple.com/kb/HT3131 When you disconnect from the monitor your Menu Bar will automatically change back to the MacBook.

  • How can I trigger an onchange event for hidden or never displayed item

    hi -- I have an item that I don't want displayed on my page -- more info than the user wants or needs; call it B. It needs to be
    set by an onchange event from a visible item (A); then, the change of B triggers on onchange to set another item (visible) -- C.
    When B is visible on the page, it all works. If I make it hidden or conditionally never displayed, it doesn't work. From the looks of
    it, B never gets changed.
    How can I trigger this onchange event (from B to set C) with B not visible?
    Thanks,
    Carol

    hi Varad -- Probably more info than you want... but here's the whole chain of events.
    Hope it answers your question.
    C
    **** 1
    In A's html form element attributes (simplified; I took out the irrelevant call to jsLookupValue that sets another item).
    onchange='jsLookupValue($v("P142_SITE_ID"),"site_id","P142_OBJECTTYPE_ID","objecttype_id","hdb_site_syn");'
    **** 2
    jsLookupValue is the following.
    The statement that actually sets the value of B is: $s(dest_item_name, jsonobj.row[0].RETURN_VAL);
    function jsLookupValue(source_item_value, source_column_name, dest_item_name, dest_column_name, lookup_table_name){
    // Continue only if there are valid values
    if (valueOf(source_column_name)&&valueOf(dest_item_name)&&valueOf(dest_column_name)&&valueOf(lookup_table_name)){
    //Check to see if the source_item_value is null (either all spaces or empty
    //If it is, set the dest item to null, but only if it's not already --
    //otherwise we get into a loop.
    source_item_value = trim(source_item_value);
    dest_item_value = trim($v(dest_item_name));
    if (source_item_value.length==0) {
    if (dest_item_value.length != 0) {
    $s(dest_item_name, null);
    }else{
    //This is the AJAX call to the Application Process from step 1
    ajaxRequest = new htmldb_Get(null,&APP_ID.,'APPLICATION_PROCESS=LOOKUP_VALUE',0);
    //Here we are adding that x01 parameter we use in the app process with the value of the objecttype_name field
    ajaxRequest.addParam('x01', source_item_value);
    ajaxRequest.addParam('x02', source_column_name);
    ajaxRequest.addParam('x03', dest_item_name);
    ajaxRequest.addParam('x04', dest_column_name);
    ajaxRequest.addParam('x05', lookup_table_name);
    //Now do the actual AJAX call and put the result in ajaxResponse
    ajaxResponse = ajaxRequest.get();
    //Check if there is a response
    if (ajaxResponse) {
    //We need to format the JSON return string and put it in a JSON object
    // the formatting is done by a function in the external JSON library
    // the jsonobj can be used to retrieve the data returned by the App process
    var jsonobj= ajaxResponse.parseJSON();
    // And finally, we set the DNAME item with the value of the jsonobj.DNAME
    // an array was created in the object with the name row, so that is why you have to include row[0] to retrieve the data
    if (jsonobj.row[0].RETURN_VAL != $v(dest_item_name)) {
    $s(dest_item_name, jsonobj.row[0].RETURN_VAL);
    }else{
    } //not setting
    }else{
    alert('No response from app process');
    } //no response
    } //no source item value
    } //no bad nulls
    } //function
    **** 3
    I won't bore you with app process LOOKUP_VALUE. It just builds an sql query that gets the value for B, aliased to RETURN_VAL.

  • How can i import my calendar events from google calendar to ical?

    how can i import my calendar events from google calendar to ical?

    To set up CalDAV support for Google Calendar in Apple's iCal, follow these steps:
    Open Apple iCal, go to Preferences and then the Accounts tab.
    Click on the + button to add an account.
    In the box that pops up, enter a description for the account and your Google Account username and password.
    Under Server Options, add the following URL:
    https://www.google.com/calendar/dav/[email protected]/user//www.google.com/calendar/dav/[email protected]/user
    Replace '[email protected]' with the email address that you use to log in to Calendar. Make sure to include the '@domain.com' portion (which is @gmail.com for Gmail users) in this section.
    DO NOT substitute your username for 'user' at the end of the URL.
    Leave the Use Kerberos v5 for authentication option unchecked.
    Click Add.
    Under the Delegation tab, select the calendars you'd like to add to iCal by checking the boxes next to them. You may need to hit refresh to get the latest list of calendars.
    Add your email address to your Address Book card by selecting Add Email. You'll be prompted to add your email address only if your address is not already in your Address Book.
    You won't be able to invite or email guests to Google Calendar events within iCal if your address is not in your Address Book.
    Your Google Calendar will now appear in iCal's list of calendars, and changes you make to your Google Calendar in iCal will be reflected when you sign in to Google Calendar.
    Event information will automatically refresh every five minutes. You can change this interval by opening the iCal > Preferences > Accounts menu and selecting a new refresh interval under the 'Refresh calendars' drop-down. Keep in mind you can also force a refresh by selecting a calendar and pressing the Apple and R keys at the same time.
    Calendars that are checked but disabled have already been added to iCal - you can remove them from within iCal.

  • I can't login, keep geting "Your  Startup Disk is Full" and asking me to delete file. if I cant login how can I delete files? Please help

    I Keep getting "your startup disk is full" ..... "You need to make more space available on your startup disk by deleting file..."  If I can't have an acess, how can I delete files. Please help..

    That means the hard drive of your computer is full, and you don't have enough free space on your computer, to do what you are trying to do. 
    You need to clear up space on your computer. 
    If you hard drive is full, check the following places to ensure they are not holding unwanted data.
    - your trash can in the dock
    - if you use iPhoto, your trash in iPhoto - launch iPhoto, and select trash in the left hand column.  iPhoto has it's own trash, and is often overlooked
    - your download folder - finder / home user / downloads - every time you download something, it stores it here. This is often overlooked as well
    - do you have more than one user on the computer?  If you do, ensure they are needed.  If not, delete them, and the contents of their home folders
    If you hard drive is very full, you may want to consider the following:
    - putting in a newer larger hard drive - (call you local apple store for prices on this)
    - deleting data off your computer
    - moving data to an external drive - (iPhoto Libraries, iTunes Libraries or iMovie events, as they are the biggest space hogs)

  • How can i copy and paste events in my icloud calendar?

    how can i copy and paste events in my icloud calendar?

    What I do, since I have shifts with same times just different daily, is make an event for the shift. Then on the repeat option, choose custom, and then monthly choose the days I want to copy the event to. Then on the end date option I choose the end of that month, so it essentially doesn't repeat, more of the copy and paste effect. Hope this helps, cheers.

  • I updated my iPhone 4 to iOS5 and let it sync with my Macbook and now all my iPhone iCal entries are gone. How can I get my iCal events back on my iPhone?

    I updated my iPhone 4 to iOS5 and let it sync with my Macbook (running Lion) and now all my iPhone iCal entries are gone. How can I get my iCal events back on my iPhone?

    Me too!  Help anyone?

  • How can I synchronize my iPhoto events? my iTunes doesn't read them and with the app Images in the iPad I can only find Photos, Albums, Faces and Places, not Events.

    How can I synchronize my iPhoto events? my iTunes doesn't read them and with the app Images in the iPad I can only find Photos, Albums, Faces and Places, not Events.

    I had a problem a couple of months ago when iPhotos suddenly rearranged the order of my Events (Why won't iPhoto let me arrange my photos?) .  I was told "Use albums not events - events are not a good way to organize - albums and folder are designed for organisation and are very flexible".
    Haha!  I should have paid attention and read between the lines!  My iPhotos were highly organised groupings - not according to date but the way I wanted them - and it was so easy to do!  I see now that if I had them all in albums, as per the Apple Apologist suggestion, I wouldn't have this unholy mess I have been left with just to make iPhone & iCloud users happy.  I am now going through Photos and making Albums (of what used to be in my Events)  ... maybe I'll get this finished before they do another non user friendly update!

  • I am new to IPhoto 9.5  and I think I missed a step. I uploaded pictures but they do not appear as an event in my library.  They are in Last imported only. How can I get them into event.

    I am new to IPhoto 9.51  and I think I missed a step when I uploaded my vacation pictures. I uploaded pictures but did not import them into the library.  They are in L\last imported only.  How can I get them into events?

    If the Photos are under 'Last Import' or 'Last N Months' then they are in the Library somewhere, just not where you are expecting them to be. We know this as both Last Import and 'Last N Months' are not places, just listings of elements in the the Library.
    The two most common reasons that they can't be found is either an incorrect date on the camera or the Sorting (View Menu -> Sort Photos - or Sort Events, as appropriate) has changed.
    Quick route to find them: Right-click on one of the images in Last Import and select 'Show Event'. This will bring you to the image in the Library.

  • How can I print stuff from the 'Help' file using my MacBook Air?

    How can I print stuff from the 'Help' file using my MacBook Air?

    Open the Help viewer, select a category then from the menu bar top of your screen, click File > Print

  • Why can't I buy any app ? Iv tried creating a new Appel account ect but it says the same thing everytime . Sorry your payment was declined . How can I sort this ? Please help

    Why can't I buy any app ? Iv tried creating a new Appel account ect but it says the same thing everytime . Sorry your payment was declined . How can I sort this ? Please help

    - Try another payment method.
    - Contact iTunes
    Apple - Support - iTunes - Contact Us
    - Create a NEW account using these instructions. Make sure you follow the instructions. Many do not and if you do not you will not get the None option. You must use an email address that you have not used with Apple before.
    Creating an iTunes Store, App Store, iBookstore, and Mac App Store account without a credit card

Maybe you are looking for

  • Help! I need more details on doing a clean install of 10.7.3

    I have a late 2008 mac book pro, intel 2.4ghz processor dual core, 4gb of RAM. It came with Leopard, I upgraded to Snow Leopard and just recently to Lion. Since upgrading to Lion, my system runs very slow, takes for ever to boot and hangs often requi

  • Query related to Migrating non Dc Web dynpro project to DC.

    Hi All, I have the requirement to migrate a non DC Web dynpro project to DC. I have a project which involves few models.The models are nothing but BAPIs released as web services. So, when I am trying to do what i intend to do, I am getting compile ti

  • Reverts to non drop frame without a tape

    Whenever I try to just log timecodes into Final Cut without a tape, it reverts to non-drop frame timecode. How do I tell final cut to always revert to drop frame?

  • Getting Data Direct license error on Development Environment setup

    Using .NET portal G6 sp1 <br> I have setup UI development environment. But I am getting datadirect license error on Debug->F5 in Visual studio. <br> I get Database connectivity error. I checked PT config manager. It showed connection was good. <br> L

  • Delays in Automation! WHY?

    So sometimes when i start getting heavy into automation-it doesn't work right: It does not activate or de-activate right where i draw the line or bypass it. For example i want to automate an 1/8 note delay or a reverse reverb on 1 word in the vocals-