Key Events (using Scala)

preview_player
Показать описание
This video shows how you can add handling of key events to a panel. This functionality is used in the video to control a small image moving around with the arrow keys.

This video is part of a series of learning support material for "Introduction to the Art of Programming Using Scala".
Рекомендации по теме
Комментарии
Автор

The video before this one in the playlist deals with mouse events. You would react to MousePressed, MouseDragged, and MouseReleased events. For the dragged and released events you would set the location for the image to draw by the offset that the mouse had moved since the last event.

MarkLewis
Автор

You just want to check if a click location is in a particular area of the screen? You could just do an if on the coordinates. The java.awt.geom package has geometric objects that can tell you if a point is contained in them if you are using more complex shapes or don't want to write the logic yourself.

MarkLewis
Автор

Hi Sir, thank you. I made it work again. Just another question, can you recommend any Scala/Java library that I can use to check if a certain location in a panel is clicked? This is for my game again. I tried looking for other references and so far, I found 2dline library of Java and it didn't work when I implemented it. What I want to happen is, once this image is clicked, and it's in this position, the frame will be disposed and will lead to another frame. Something like that.

_japh
Автор

Hi, Sir. It's me again. What if I want to use the mouse events instead of the keys? Like, there's a specific image placed in the panel, and once you click or drag the image, you can move it. Something like that. Any tips? :D

_japh
Автор

Ooops, got it figured out already, sir. Still, thank you!

_japh