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

如何在 Java 中檢測 Image 對象上的鼠標(biāo)單擊事件

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

問題描述

限時送ChatGPT賬號..

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

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

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

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.

這是一手牌的例子:

我考慮過將每張卡片設(shè)為 JPanel,但問題是我必須在其 矩形 JPanel<內(nèi)繪制旋轉(zhuǎn)的卡片/code>,因為它們本身不能旋轉(zhuǎn).理想情況下,我想避免使用鼠標(biāo) 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.

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

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).

但這不一定是這樣 - 雖然實際邊界必須是矩形,但組件使用的實際區(qū)域可以更小.組件支持 contains(Point) 方法,只要出現(xiàn)點屬于哪個組件的問題(例如,鼠標(biāo)單擊),事件調(diào)度機制就會調(diào)用該方法.(不同組件的重疊將由父容器內(nèi)的 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() 方法實現(xiàn)此方法,使用仿射變換的矩形作為您的形狀.每個旋轉(zhuǎn)的組件都將知道自己的形狀(或從其 AffineTransform 動態(tài)生成它,它也將用于繪畫本身).

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.)

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

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.

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

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

相關(guān)文檔推薦

Parsing an ISO 8601 string local date-time as if in UTC(解析 ISO 8601 字符串本地日期時間,就像在 UTC 中一樣)
How to convert Gregorian string to Gregorian Calendar?(如何將公歷字符串轉(zhuǎn)換為公歷?)
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 日之前日期的日歷到日期轉(zhuǎn)換.公歷到儒略歷切換)
java Calendar setFirstDayOfWeek not working(java日歷setFirstDayOfWeek不起作用)
Java: getting current Day of the Week value(Java:獲取當(dāng)前星期幾的值)
主站蜘蛛池模板: 欧美电影免费观看高清 | 国产在线视频一区二区 | 欧美性猛交| 国产精品久久久久久久久久久免费看 | 国产高清免费在线 | 欧美成人精品欧美一级 | 色偷偷人人澡人人爽人人模 | 日韩av一区二区在线观看 | 国产1区 | 天天操网 | 九九热在线观看视频 | 狠狠天天 | 日日操操| 亚洲一区影院 | 日韩精品一区二区三区在线播放 | 久久色视频 | 中文字幕高清免费日韩视频在线 | 成人一区精品 | 国产一区二区三区免费观看在线 | 一级黄a| 欧美成视频 | 亚洲h视频 | 美女爽到呻吟久久久久 | 一级做a爰片性色毛片视频停止 | 亚洲精品久久久久久首妖 | 91精品国产综合久久久久久 | 欧美成人久久 | 久久爆操 | 成人影院av | 亚洲综合色婷婷 | 性欧美精品一区二区三区在线播放 | 黄a免费看 | 成人自拍av | 欧美激情亚洲激情 | 久久久.com | 国产精品激情 | 国产91av视频在线观看 | 亚洲一区亚洲二区 | 亚洲精品视频在线播放 | 女人毛片a毛片久久人人 | 午夜精品久久久久久久星辰影院 |