How to create non swing buttons in Java?
•
Java
I'm creating a game in which I have a menu with multiple views for selecting game types, options, etc. using game state transitions Each menu will be actively rendered in the JFrame of the canvas object Since I render each game state actively by drawing buffered images to canvas, I cannot use JButton or any other JComponent or component (AWT) because graphics2d objects cannot draw them as follows:
Graphics2D g = bufferStrategy.getDrawGraphics(); g.draw(new JButton("Click me"));
How to implement a custom button that can receive mouse input and draw with graphics2d objects?
Solution
Add a mouse listener to the component you are drawing and determine whether the mouse click is in the area you want to be a button
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码