How to add mouseListener to classes and not to main, so each object is clic

Hello everyone,
Im developing a window system for applets. I know I could use the jframe windows but I want black outlined semi transparent windows. Im working on the basic stuff now. Basically you call the constructor and send it a string, the constructor will chop up the strings at '^' chars and determine the width and height of the window from there, anyway i can do all that.
Is it possible to have each instance of my appletwindow class implement mouseListener and act upon mouse clicks separately or should i make a window manager and send mouse events from the main to my window manager? Of course if each object could have its own mouse handling that would save me having to iterate through all the objects every time there is a mouse click. Also do i need to extend component? Here is my code so far.
public class AppletWindow extends Component implements MouseListener{
    String winText;
    Rectangle2D bounds;
    boolean isTop;
    Color bgColor;
    Color fgColor;
    int Margin;
    Font font;
    int fontHeight;
    int fontWidth;
    // some other contstructors here
    public AppletWindow(String winText, int x, int y)
        super();
        this.winText = new String();
        this.winText = winText;
        this.Margin = 10;
        this.fontHeight = 12;
        font = (new Font("SansSerif", Font.PLAIN, this.fontHeight));
        this.fontWidth = font.getSize()/2;
        int j = 0;
        int Width = 1;
        int Height = 1;
        for (int i=0; i<this.winText.length()-1; i++){
            if (this.winText.charAt(i) == '^'){    
                if(Width < (i-j)){
                    Width = (i-j);
                j=i;
                Height++;
        } // end for
        this.bounds = new Rectangle(x, y,
                Width*fontWidth+Margin*2,
                Height*10+Margin*2 + fontHeight);
        this.bgColor = Color.BLACK;
        this.fgColor = Color.ORANGE;
        addMouseListener(this);
        boolean isTop = false;
    // all the mouse methods here
    // a method to paint the window to the screenIn my main (applet) i have these lines in the init()
  public void init() {
    this.setSize(800,600);
    testwin.addMouseListener(this);
    addMouseListener(this);
    } but when i click on the window or do anything to it, it does not respond. I had set up inside the appletwindow class so it would print out "applet window" on any mouse actions but none of them print.
Thanks In advance

Well i made my own window manager. So i pass the mouse events from the applet to the window manager and then to all the windows like so
main (the appletscenemanager is my "window manager")
    AppletSceneManager asm = new AppletSceneManager();
    Thread repaintMe;
    // double buffering stuff
    Graphics bufferGraphics;
    Image offscreen;
    Dimension dim;
    public void init() {
    this.setSize(800,600);
    this.setBackground(Color.DARK_GRAY);
    dim = getSize();
    offscreen = createImage(dim.width,dim.height);
    bufferGraphics = offscreen.getGraphics();
    String winText = new String();
    int j = 0;
    int k = 0;
    for (int i=0; i< 25; i++){
        if(j==5){j=0;k++;}
        winText = "Window: " + i + '^';
        asm.addWindow(winText, j*160, k*120,160,120);
        j++;
    addMouseListener(this);
    addMouseMotionListener(this);
    public void mouseMoved(MouseEvent e) {
        //asm.processMouseEvent(e);
    public void mouseDragged(MouseEvent e) {
        asm.processMouseEvent(e);
    public void mousePressed(MouseEvent e) {
        asm.processMouseEvent(e);
    }then in my applet scene manager (which holds the windows in a linked list)
    public void processMouseEvent(MouseEvent e){
        AppletWindow temp = null;
        System.out.println("e.gid" + e.getID());
        for(AppletWindow aw :appletWindows){
            if(aw.processMouseEvent(e) != null)
            temp = aw;
        if (temp != null){
        appletWindows.remove(temp);
        appletWindows.push(temp);    
    }and in the actual window class its getting a little messy, its hard to tell which window is currenty being acted upon because i find if the window was clicked using .contains so if windows are on top of each other several can .contains(e.getpt()) and then several are "selected" at one time, which causes problems
    public AppletWindow processMouseEvent(MouseEvent e)
    if(dragging)
        moveWindow(e.getPoint());
        if (e.getID() != e.MOUSE_DRAGGED)
            dragging = false;
    if(sizing)
        sizingWindow(e.getPoint());
        if (e.getID() != e.MOUSE_DRAGGED)
            sizing = false;
    if(contains(e.getPoint()))
        // we are in this window pay attention
        if(e.getButton() == e.BUTTON1)
            setTopMost(true);                   // set it to topmost
            alpha = makeComposite(0.9F);        // make this one less transparent
        if(e.getID() == e.MOUSE_DRAGGED && isTopMost()  // are they draggin me?
                && this.titleBounds.contains(e.getPoint())){dragging = true;}
        if(e.getID() == e.MOUSE_DRAGGED && isTopMost()
                    && this.sizeBounds.contains(e.getPoint())){sizing = true;}
        }else{
        setTopMost(false);
        alpha = makeComposite(0.5F);
        return this; // let them know it was us !
    return null; // it aint my fault!
    // window operations stuff
    public void moveWindow(Point pt){
        this.bounds.x = (int)(pt.getX() - (this.bounds.width/2));
        this.bounds.y = (int)(pt.getY()-5);
        this.titleBounds.setBounds(this.bounds.x, this.bounds.y,
                this.bounds.width, fontHeight);
        this.sizeBounds.setBounds((int)this.bounds.getMaxX()-resizeWH,
                (int)this.bounds.getMaxY()-resizeWH,resizeWH, resizeWH);
    public void sizingWindow(Point pt){
        if((pt.x - bounds.getMaxX()) > 0 && (pt.y - bounds.getMaxY()) > 0){
        this.bounds.width = (int)(bounds.width + (pt.x - bounds.getMaxX()));
        this.bounds.height = (int)(bounds.height + (pt.y - bounds.getMaxY()));
        }else{
        this.bounds.width = (int)(bounds.width - (bounds.getMaxX() - pt.x));
        this.bounds.height = (int)(bounds.height - (bounds.getMaxY() - pt.y));       
        this.titleBounds.setBounds(this.bounds.x, this.bounds.y,
                this.bounds.width, fontHeight);
        this.sizeBounds.setBounds((int)this.bounds.getMaxX()-resizeWH,
                (int)this.bounds.getMaxY()-resizeWH,resizeWH, resizeWH);
    public boolean contains(Point pt)
        if (bounds.contains(pt))
            return true;
        return false;
    }As anyone can see im getting no feedback what so ever from these forums (as usual), so i might be doing this the very hard way.
here is the applet if anyone wants to see it run [http://www.zonemikel.com/smf/index.php?topic=18.0]

Similar Messages

  • How to add a code TestIfElse(10) to the Main method of the Program.cs class?

    How to add a code  TestIfElse(10) to the Main method of the Program.cs class?
    Here is my code and I have copied from the Wiley book for Microsoft certification page 14,
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    namespace ifelse_Statement
        class Program
            static void Main(string[] args);
            TestIfElse(10);
            public static void TestIfElse(int n);
            if(n < 10)
                     Console.WriteLine("n is less than 10");
             else if(n < 20)
                    Console.WriteLine("n is less than 20");
             else if(n < 30)
                Console. WriteLine("n is greater than or equal to 30");
    Here is the error list I am getting,
    Error 1      Method must have a return type        C:\Users\PVS\documents\visual studio 2013\Projects\Lesson01\switch_Statement\Program.cs
    12 13
    switch_Statement
    Error 2
    Type expected C:\Users\PVS\documents\visual studio 2013\Projects\Lesson01\switch_Statement\Program.cs
    12 24
    switch_Statement
    Error 3
    Method must have a return type C:\Users\PVS\documents\visual studio 2013\Projects\Lesson01\ifelse_Statement\Program.cs
    12 9
    ifelse_Statement
    Error 4
    Type expected C:\Users\PVS\documents\visual studio 2013\Projects\Lesson01\ifelse_Statement\Program.cs
    12 20
    ifelse_Statement
    Error 5
    Invalid token 'if' in class, struct, or interface member declaration
    C:\Users\PVS\documents\visual studio 2013\Projects\Lesson01\ifelse_Statement\Program.cs
    16 9
    ifelse_Statement
    Error 6
    Invalid token '10' in class, struct, or interface member declaration
    C:\Users\PVS\documents\visual studio 2013\Projects\Lesson01\ifelse_Statement\Program.cs
    16 16
    ifelse_Statement
    Error 7
    Type expected C:\Users\PVS\documents\visual studio 2013\Projects\Lesson01\ifelse_Statement\Program.cs
    16 16
    ifelse_Statement
    Error 8
    Invalid token '(' in class, struct, or interface member declaration
    C:\Users\PVS\documents\visual studio 2013\Projects\Lesson01\ifelse_Statement\Program.cs
    18 35
    ifelse_Statement
    Error 9
    A namespace cannot directly contain members such as fields or methods
    C:\Users\PVS\documents\visual studio 2013\Projects\Lesson01\ifelse_Statement\Program.cs
    20 10
    ifelse_Statement
    Error 10
    Type or namespace definition, or end-of-file expected
    C:\Users\PVS\documents\visual studio 2013\Projects\Lesson01\ifelse_Statement\Program.cs
    30 1
    ifelse_Statement
    Error 11
    The type or namespace name 'n' could not be found (are you missing a using directive or an assembly reference?)
    c:\users\pvs\documents\visual studio 2013\projects\lesson01\ifelse_statement\program.cs
    16 12
    ifelse_Statement
    Error 12
    'System.Console.WriteLine(string, params object[])' is a 'method' but is used like a 'type'
    c:\users\pvs\documents\visual studio 2013\projects\lesson01\ifelse_statement\program.cs
    18 26
    ifelse_Statement

    static void Main(string[] args){
    TestIfElse(10);
    public static void TestIfElse(int n)
    if (n < 10)
    Console.WriteLine("n is less than 10");
    else if (n < 20)
    Console.WriteLine("n is less than 20");
    else if (n < 30)
    Console.WriteLine("n is greater than or equal to 30");
    Fouad Roumieh

  • How to add a navigation Panel and Zoom Slider Bar using Java API

    Hello,
    I am using Mapviewer Java bean as I have to use Oracle Mapviewer in Java Stanalone application.Please can anyone tell me how to add a Navigation panel and Zoom Slider in Java API. I found the API s for same in Java Script but not in Java.Kindly help.
    I am using Oracle Mapviewer 11g.

    This is forum sponsored by Adobe make of Acrobat and Reader. Since Chrome and FireFox web browser have chosen to use their own viewer you might get more help in their forums or customer support.

  • How to add one date column and charecter column

    hi all,
    i have 3 column start_date(date),end_date( date),duration (varchar2)
    i am trying to add start_time and duration like this
    end_date := to_char(start_time) + duration;
    but its showing value_error
    how to add one date column and charecter column.
    Thanks

    you need something that does:
    end_date (DATE) := start_date (DATE) + <number of
    days> (NUMBER)Not necessarily, because if the duration is just a string representation of a number then it will be implicitly converted to a number and not cause an error
    e.g.
    SQL> ed
    Wrote file afiedt.buf
      1  with t as (select to_date('01/07/2007','DD/MM/YYYY') as start_dt, '3' as duration_days from dual)
      2  -- END OF TEST DATA
      3  select start_dt + duration_days
      4* from t
    SQL> /
    START_DT+
    04-JUL-07

  • How to make google come up and not yahoo when i click anew tab

    how to make google come up and not yahoo when i click a new tab
    == This happened ==
    Every time Firefox opened
    == today

    You can use 1 of these add-ons
    [https://addons.mozilla.org/en-us/firefox/addon/newtaburl/?src=search
    NewTabURL ]
    [https://addons.mozilla.org/en-us/firefox/addon/new-tab-homepage/?src=search New Tab Homepage]
    with NewTabUrl you have more options
    thank you
    Please mark "Solved" the answer that really solve the problem, to help others with a similar problem.

  • I've used iMessage for abit now and latly my step dad has got an ipad that is now joint to the same computer and on his ipad is my number and the email for imessage and i want to no how to get it of fully and not just untick it?

    I've used iMessage for abit now and latly my step dad has got an ipad that is now joint to the same computer and on his ipad is my number and the email for imessage and i want to no how to get it of fully and not just untick it?

    Hi barryfromwarrington,
    Welcome to the Support Communities!  There are two things I can think of to keep your Stepdad's information separate from yours on the computer and the iPad.   On the computer, he should have his own administrative account, and on the iPad he needs his own Apple ID for iTunes and iCloud services.  Here is some basic information to get started.  I don't know if you have a Mac or Windows computer, so I'll include info for both.)
    OS X Yosemite: Set up users on your Mac
    http://support.apple.com/kb/PH18891
    OS X Yosemite: Set up users on your Mac
    If your Mac has multiple users, you should set up an account for each person so he or she can personalize settings and options without affecting other users. 
    Add a user
    Choose Apple menu > System Preferences, then click Users & Groups.
    Click the lock icon  to unlock it, then enter an administrator name and password. 
    Click Add  below the list of users. 
    Click the New Account pop-up menu, then choose a type of user.
    administrator: An administrator can add and manage other users, install apps, and change settings. 
    Enter a full name for the new user. An account name is generated automatically. To use a different account name, enter it now—you can’t change it later. 
    Enter a password for the user, then enter it again to verify. Using a password hint is recommended to help the user remember his or her password. 
    Click Create User.
    For an administrator, select “Allow user to administer this computer.”
    Last Modified: Nov 18, 2014
    iTunes for Windows Vista, Windows 7, or Windows 8: Fix unexpected quits or launch issues - Apple Support
    http://support.apple.com/en-us/HT203206
    Follow the steps below to create a new user account in Windows Vista or Windows 7:
    Choose Start > Control Panel.
    Open "Add or remove user accounts." (If you're using the Classic view in Windows Vista, open "User Accounts," and then open "Manage another account.")
    Select "Create a new account" and follow the instructions to set up the account.
    Once you create the new account, choose Start > Log Off.
    Log in to the new user account.
    Open iTunes and see if the issue you're experiencing persists in this new user account.
    Frequently asked questions about Apple ID - Apple Support
    http://support.apple.com/en-us/HT204161
    iCloud: Set up iCloud
    http://support.apple.com/kb/PH2609
    Cheers,
    - Judy

  • How can I buy Photoshop CC and not rent the software? [was: buy]

    HOW CAN I BUY
    PHOTOSHOP CC AND NOT RENT THE SOFT WARE

    You can't.  You can, however,  buy Photoshop CS6.
    http://www.adobe.com/products/catalog/cs6._sl_id-contentfilter_sl_catalog_sl_software_sl_c reativesuite6.html
    By the way, your caps lock is stuck on.

  • How can i download InDesign CS6 and not CC from your website?

    how can i download InDesign CS6 and not CC from your website?

    Are you a cloud subscriber, or are you looking for a perpetual license or trial version?

  • I am in Saudi and trying to download navigon middle east. Every time I try to buy the app it will show up, says waiting and disappears. How can I get around it and not get lost on these crazy roads?

    I am in Saudi and trying to download navigon middle east. Every time I try to buy the app it will show up, says waiting and disappears. How can I get around it and not get lost on these crazy roads?

    I recently purchased a second hand new macbook air, although it was second hand to me the previous owner had never actually turned it on.
    Something doesn't make sense here, though I'm not saying the previous owner is lying....
    Time to send your serial # to iTS and let them see what's happening here.
    iTunes Store Support
    http://www.apple.com/emea/support/itunes/contact.html

  • How to restrict the last record and not moving to next reocrd

    1) how to restrict the last record and not moving to next reocrd.
    2) Also for the F6 key(for new record).

    When you are on the last record, next-record will create a new one, so that my question is do you want to forbid new record creation.
    Francois

  • When insert my lexar USB flash drive I get the message that the disk was not readable by this computer.  It has worked previous to this and I do not want to lose the data by reformatting the drive.  How can I reformat this drive and not lose my data?

    When insert my lexar USB flash drive I get the message that the disk was not readable by this computer.  It has worked previous to this and I do not want to lose the data by reformatting the drive.  How can I reformat this drive and not lose my data?

    You can't reformat it and not wipe everything on it.
    Have you tried a different USB port?
    Only other option, back it up on a different computer.

  • I want to delete a few contacts, apps, pics etc from my iphone, but when I delete and connect to my laptop they sync and come back again. How can I delete those items and not get them back when I connect my iphone to my laptop?

    I want to delete a few contacts, apps, pics etc from my iphone, but when I delete and connect to my laptop they sync and come back again. How can I delete those items and not get them back when I connect my iphone to my laptop?
    Also where exactly on the laptop is teh data stored.
    Thank you!!

    go to 'Edit' in the menu bar. Then choose 'Preferences'.
    you'll see a pop-up and there's a tab called 'Devices' there. If you click that, you will be able to check a box that says 'prevent automatic syncing for iPods, iPads and iPhones' or something like that.
    Hope this helps
    NB: if you don't even see the menu bar that has options like 'File, Edit, View, etc', first click the black/white square button on the top left of your screen, and then click 'show menu bar'. It should pop right up.
    Good luck

  • HT1284 How can I backup word documents and not have them crowd my screen? Thanks.

    Hi. How can I backup word documents and not have them crowd my screen? I know, you guessed it. I'm a novice, but not ashamed!

    Please explain what you mean when you say backup Word documents crowds your screen.
    I don't see any connection between backup and your screen.
    Allan

  • How can I get my photo and notes after restore

    How can I get my photo and notes back after restoring an i phone?

    Had you backed up your stuff to iCloud or iTunes?

  • When I drag ANY JPEG into a new folder of ANY kind, I get an alias, not an original. And, when I drag aliases onto a  blank disk to burn it, I get burned aliases, NO originals. That's what I'm asking. How do you drag a JPEG and NOT get an alias?

    When I drag ANY JPEG into a new folder of ANY kind, I get an alias, not an original. And, when I drag aliases onto a  blank disk to burn it, I get burned aliases, NO originals. That's what I'm asking. How do you drag a JPEG and NOT get an alias?

    Finder Help describes how to move, copy etc.
    As well, Apple - Support - Discussions - Moving or Copying Files and ...

Maybe you are looking for