久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何在 Java 中檢測 Image 對象上的鼠標單擊事件

How can you detect a mouse-click event on an Image object in Java?(如何在 Java 中檢測 Image 對象上的鼠標單擊事件?)
本文介紹了如何在 Java 中檢測 Image 對象上的鼠標單擊事件?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

在 Java 中實現Kings' Corners"(美化多人紙牌).

Implementing "Kings' Corners" (glorified multiplayer Solitaire) in Java.

我試圖讓玩家將一張牌(圖像)從他們的手中拖到桌子上的其他地方.問題是玩家的手是扇形的",因此卡片的圖像會旋轉并且它們重疊.

I'm trying to allow a player to drag a card (image) from their hand to somewhere else on the table. The problem is that the player's hand is "fanned" so the images of the cards are rotated and they overlap.

這是一手牌的例子:

我考慮過將每張卡片設為 JPanel,但問題是我必須在其 矩形 JPanel<內繪制旋轉的卡片/code>,因為它們本身不能旋轉.理想情況下,我想避免使用鼠標 x,y 公式來確定選擇哪張卡.

I've considered making each card a JPanel, but the issue then is that I'd have to paint the card rotated inside its rectangular JPanel, as they themselves can't be rotated. Ideally I'd like to avoid mouse-x,y formulas to determine which card is being chosen.

使用事件驅動的方法,我如何確定從手牌中選擇哪張牌?

Using an event-driven approach, how can I determine which card is chosen from the hand?

推薦答案

AWT(和 Swing)組件通常是矩形的(與軸對齊).

AWT (and Swing) components are normally rectangular (aligned to the axes).

但這不一定是這樣 - 雖然實際邊界必須是矩形,但組件使用的實際區域可以更小.組件支持 contains(Point) 方法,只要出現點屬于哪個組件的問題(例如,鼠標單擊),事件調度機制就會調用該方法.(不同組件的重疊將由父容器內的 z-order 處理.)

But this does not have to be the case - while the real bounds must be rectangular, the actual area which a component uses can be smaller. Component supports a contains(Point) method, which will get called by the event dispatch mechanism whenever the question arises to which component a point belongs - for example, for mouse clicks. (Overlapping of different components will be handled by the z-order inside the parent container.)

您可以基于 Shape.contains() 方法實現此方法,使用仿射變換的矩形作為您的形狀.每個旋轉的組件都將知道自己的形狀(或從其 AffineTransform 動態生成它,它也將用于繪畫本身).

You can implement this method based on the Shape.contains() method, using a affine transformed rectangle as your shape. Each of your rotated components would know its own shape (or generate it on the fly from its AffineTransform, the same one which would also be used for painting itself).

有一個自定義的 LayoutManager 也可以安排您的卡片.(不要使用 CardLayout,盡管有這個名字.)

Have a custom LayoutManager which arranges your cards, too. (Don't use CardLayout, despite the name.)

我不確定我是否會遵循為每張卡片設置單獨組件的方式,但您肯定需要一些代表旋轉矩形的對象.

I'm not sure I would follow the way of having separate components for each card, but you certainly need some objects which represent the rotated rectangles.

這篇關于如何在 Java 中檢測 Image 對象上的鼠標單擊事件?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Parsing an ISO 8601 string local date-time as if in UTC(解析 ISO 8601 字符串本地日期時間,就像在 UTC 中一樣)
How to convert Gregorian string to Gregorian Calendar?(如何將公歷字符串轉換為公歷?)
Java: What/where are the maximum and minimum values of a GregorianCalendar?(Java:GregorianCalendar 的最大值和最小值是什么/在哪里?)
Calendar to Date conversion for dates before 15 Oct 1582. Gregorian to Julian calendar switch(1582 年 10 月 15 日之前日期的日歷到日期轉換.公歷到儒略歷切換)
java Calendar setFirstDayOfWeek not working(java日歷setFirstDayOfWeek不起作用)
Java: getting current Day of the Week value(Java:獲取當前星期幾的值)
主站蜘蛛池模板: 久久激情视频 | 久久亚洲一区二区 | 99久久婷婷国产综合精品首页 | 久久狠狠 | 91福利在线观看 | 国产精品自拍啪啪 | av一区在线观看 | 国产日韩精品视频 | 精品国产不卡一区二区三区 | 国产精品久久久久久久久久免费看 | 欧美一区二区三区国产精品 | 日本三级在线 | 九九热精品视频 | 一级黄色片在线免费观看 | 久久久久亚洲精品 | 免费一级黄色 | 午夜激情免费视频 | 午夜精品一区二区三区在线观看 | 免费在线精品视频 | 国产精品国产精品国产专区不卡 | 三级av在线 | 精品国产乱码久久久久久丨区2区 | 成人免费在线观看 | 久久久久久久久久久久久9999 | 亚洲一区二区三区免费视频 | 黄色大片在线播放 | 国产视频中文字幕 | 国产成人免费 | 国产一区久久 | 国产成人麻豆免费观看 | 日韩欧美在线观看 | 中文字幕亚洲精品 | 亚洲国产欧美国产综合一区 | 超碰91在线| 欧美成人第一页 | 国产精品久久久久久av公交车 | 色综合99| 亚洲一区电影 | 日韩高清三区 | 国产97在线视频 | av黄色国产 |