简体   繁体   中英

How to create mouse adapter in kotlin

I am trying to create a mouse adapter to handle when a mouse button to print something. I have created a class and extended the mouse adapter. I override the mouseClicked method and now I to intialize the new object but i dont know what the argument is

What I tried

Created the MouseAdapterEvent where i override the mouseClicked method


class MouseAdapterEvents: MouseAdapter() {
    override fun mouseClicked(e: java.awt.event.MouseEvent?) {
        print("something")
    }
}

then created the object in my other class

var a:MouseAdapterEvents

then in an async I'm waiting for mouse to be clicked a.mouseClicked() but i dont know what the argument is.

What should i put there? And tbh i don't know how to initialize this var either.

You can initialize class by

var a:MouseAdapterEvents = MouseAdapterEvents()

and if you don't want to create new class you can use Object Expression

var a = object: MouseAdapter() {
    override fun mouseClicked(e: java.awt.event.MouseEvent) {
        print("something")
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM