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

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

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

問(wèn)題描述

限時(shí)送ChatGPT賬號(hào)..

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

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

我試圖讓玩家將一張牌(圖像)從他們的手中拖到桌子上的其他地方.問(wèn)題是玩家的手是扇形的",因此卡片的圖像會(huì)旋轉(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.

這是一手牌的例子:

我考慮過(guò)將每張卡片設(shè)為 JPanel,但問(wèn)題是我必須在其 矩形 JPanel<內(nèi)繪制旋轉(zhuǎn)的卡片/code>,因?yàn)樗鼈儽旧聿荒苄D(zhuǎn).理想情況下,我想避免使用鼠標(biāo) x,y 公式來(lái)確定選擇哪張卡.

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ū)動(dòng)的方法,我如何確定從手牌中選擇哪張牌?

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

推薦答案

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

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

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

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

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

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

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

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 中檢測(cè) Image 對(duì)象上的鼠標(biāo)單擊事件?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

相關(guān)文檔推薦

Parsing an ISO 8601 string local date-time as if in UTC(解析 ISO 8601 字符串本地日期時(shí)間,就像在 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)前星期幾的值)
主站蜘蛛池模板: 91精品久久久久久久久久入口 | 午夜视频一区二区三区 | 日本一二区视频 | 99久久中文字幕三级久久日本 | 亚洲欧美日韩中文字幕一区二区三区 | 91在线免费视频 | 欧美自拍另类 | 看黄在线 | 成人黄色三级毛片 | 亚洲国产aⅴ成人精品无吗 欧美激情欧美激情在线五月 | 亚洲精色| 欧美一级黑人aaaaaaa做受 | 综合天天久久 | 中文字幕一区二区三区日韩精品 | 欧美久久国产精品 | 日日干夜夜操 | 日韩国产一区二区三区 | 国产一区二区影院 | 九九热久久免费视频 | 精品伊人久久 | 精品国产高清一区二区三区 | 国产精品一区二区在线播放 | 日日摸夜夜添夜夜添特色大片 | 91免费在线看 | 国产精品欧美一区喷水 | 婷婷激情在线 | 欧美日韩在线播放 | 97av视频在线观看 | 国产精品久久久久9999鸭 | 亚洲精品成人av久久 | 国产精品久久久久久 | 日本高清视频在线播放 | 成年网站在线观看 | 精品久久久久久中文字幕 | 91精品国产自产精品男人的天堂 | a级片www| 欧美久久久久 | 久久久91 | 中文字幕国产一区 | 欧美中文字幕一区二区三区 | 欧美精品一区二区三区四区五区 |