java-2d

Drawing on a JPanel

核能气质少年 提交于 2019-12-11 00:33:09
问题 I'm start with create RubicPanel class extended from JPanel from NetbeanIDE set it to black background, put it on a JFrame and I start to draw on it by using another class like this. public class Drow { private final int SquareSize = 99; public void DrowRubic(RubicEntity GameRubic, RubicPanel rPanel) { Graphics g = rPanel.getGraphics(); g.setColor(Color.pink); g.fillRect(0, 0, 301, 301); int CurrentFace = GameRubic.getDirection(1); for(int i=0; i<3; i++) { for(int j=0; j<3; j++) { DrowSquare

Trouble with mouseDragged and multiple objects

我是研究僧i 提交于 2019-12-10 21:53:47
问题 We are playing around with mouseDragged and multipleObjects. We are trying to create a board game that has 8 pieces that can be individually clicked and dragged to their respective location on the board (without using jpanel, jframe, etc). As of now we have created 8 individual pieces for the board game, however when you go to click/drag piece '2', it causes all of the pieces to come together under the top piece. Our initial solution (not shown) is to use a button to cycle between players

Drawing a bordered path with sharp corners in Java

南笙酒味 提交于 2019-12-10 21:18:56
问题 I am working on an application that displays GPS tracks on a map. I want to draw the track as a colored path of arbitrary thickness. I found the GeneralPath class which seems to do just what I want. However, I want the colored path to also have a black border. I couldn't find anything about how to add a border to a path, so I came up with a quick hacky solution of drawing a thick black path first, and then drawing a thin colored path on top. SSCCE: import java.awt.BasicStroke; import java.awt

Why My JComponent is not displayed on top of backgound JFrame?

南笙酒味 提交于 2019-12-10 18:09:20
问题 Why My JComponent is not displayed on top of backgound JFrame? Please check the following code: class CounterFrame extends JFrame { /** * */ private static final long serialVersionUID = 1L; private MyPanel myComponent = new MyPanel(); private JLabel contentPane = new JLabel(new ImageIcon(getClass() .getResource("background/2.jpg"))); CounterFrame() { contentPane.setLayout(new GridBagLayout()); setContentPane(contentPane); add(myComponent); } } class MyPanel extends JPanel { /** * */ private

Why doesn't the Graphics' draw method respect stroke attributes?

拜拜、爱过 提交于 2019-12-10 15:45:17
问题 I want to create a custom border with rounded corners. Code - import java.awt.BasicStroke; import java.awt.Color; import java.awt.Component; import java.awt.FlowLayout; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Insets; import java.awt.RenderingHints; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.SwingUtilities; import javax.swing.border.AbstractBorder; class JRoundedCornerBorder extends AbstractBorder { private static final long

Collision detection tutorials [closed]

馋奶兔 提交于 2019-12-10 10:35:10
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 3 years ago . I'm supposed to develop a Java game using AWT. I'm stuck with the concept of "collision detection". If you can help me with any tutorials that explain the concept (how it works) or give examples (source code), I'd be grateful. 回答1: A strong tutorial on 2d collision detection can be found at metanetsoftware

How to animate Rectangle on a Path2D object in Graphics2D context

[亡魂溺海] 提交于 2019-12-10 05:39:06
问题 I have just started learning basics about Graphics2D class, So far I am able to draw different objects and implements ActionListener to actually move them on screen by onKeyPress . So far so good, While I thought of doing something more complicated. I want to give a path to my object and animate it on that particular path only. Something like, I will draw a line on sky and a plane should stick with that drawn line and keep it self to fly on that particular line. Now is it possible? I don't

How to create a curve between 2 points in 2D and get back Points that makes that curve every d distance?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-09 17:51:50
问题 I'm not good in math. I have 2 points, A(x1, y1) and B(x2, y2) in 2D. I need to create a virtual path from point A to B curved at R(radius), and then return an array of points which are describing this curved path, not all maybe every D(distance) from each other. In Java I need a method like this: private ArrayList<PointF> generateCurve(PointF pFrom,PointF pTo,float pRadius,float pMinDistance){ ArrayList<PointF> pOutPut = new ArrayList<PointF>(); // ...generate result to pOutPut return

Java Swing: Awfully slow cursor response when hovering over rectangles

血红的双手。 提交于 2019-12-08 13:22:38
问题 Below is code where a user is moving the mouse cursor over a bunch of rectangles and the cursor is supposed to change to a hand cursor while over the rectangles and revert to a default normal cursor when not on top of the given rectangles. Problem: The solution works,but painfully slow.They are many ways "to skin a cat", therefore we can model the question in many variants and solutions could be of all kinds, but what is constant, is that we have to loop over each rectangle using an iterator

How can I draw on JPanel using another quadrant for the coordinates?

别来无恙 提交于 2019-12-08 10:56:20
问题 I would like to draw some shapes on a JPanel by overriding paintComponent . I would like to be able to pan and zoom. Panning and zooming is easy to do with AffineTransform and the setTransform method on the Graphics2D object. After doing that I can easyli draw the shapes with g2.draw(myShape) The shapes are defined with the "world coordinates" so it works fine when panning and I have to translate them to the canvas/JPanel coordinates before drawing. Now I would like to change the quadrant of