paintcomponent

What is the most efficient way to implement particle filters in Java?

旧街凉风 提交于 2019-12-13 05:04:38
问题 I am working on implementing a particle filter localization in Java, in which I have to create a GUI and then fill it with 100 particles and a robot. Then, i have to update the particles and robot periodically. For example, I will increment the values of x and y by 5 units every time. What should be the design of such a project? I am having a method createGUI and I am calling the constructor to create and fill the particles in the frame. But how will I update the points again and again. Will

JavaGame character is not moving accurately while drawing?

北慕城南 提交于 2019-12-13 03:43:34
问题 for personal practice, I am remaking Flappy bird for desktop with Java, I have managed to get all the pillars generating, screen, bg moving done, but now I have one problem, which is performance. I sometimes feel that the game isn't moving as fast, and sometimes gets stuck for 0.5 secs or something, but that's not the case, when I move my bird, it's moving a bit weird, looks like its moving too much forward & then to the back, watch the gif in MP4 format: http://gyazo.com

Adding Images on Mouse Click to JPanel

孤街醉人 提交于 2019-12-13 03:19:58
问题 I am working with Swing for the first time and am having a bit of an issue. What I have is a JFrame split into four JPanels. There is a MouseListener on the JFrame that acts like this On a click, if the click is inside of the left hand bar, determine which of the 13 icons is being selected. If the click is inside the right hand "game pane" & an icon has been selected, place it at the location clicked. This is done here @Override public void mouseClicked(MouseEvent event) { // TODO Auto

Gradient textfields in panel with TitledBorder - performance issue

我是研究僧i 提交于 2019-12-13 01:49:43
问题 I have a panel with 3 inner panels that all use a TitledBorder . The third inner panel has a number of custom textfields that are painted with GradientPaint . The textfields come from a custom class that extends JTextField and uses an overriden paintComponent method along with a MouseListener , so that when mouse enters on a textfield area the gradient color slightly changes (and changes back again when mouse leaves the textfield). The problem is that the gradient color change does not

Why do my shapes and images disappear on my panel?

老子叫甜甜 提交于 2019-12-12 22:44:30
问题 I have used the paintComponent method to draw shapes on my panel. However, every time I minimize the frame or resize it, they disappear. Not sure what to add to my code. public class ShapePanel extends JPanel implements ActionListener, MouseListener{ int a,b,c,d; Graphics2D g2D; private Rectangle2D rect = new Rectangle2D(a,b,c-a,d-b); public ShapePanel(){ addMouseListener(this); setLayout(new GridLayout()); } public void paintComponent(Graphics g) { g2D = (Graphics2D) g; g2D.draw(rect);

Graphics on top of a Panel

百般思念 提交于 2019-12-12 19:21:42
问题 I am having trouble with the Graphics that I am drawing on a Panel which has a JLabel on top of it. I am using a custom paintComponent(Graphics g) method to draw a String on the Panel. I want the string to show on top of the JLabel instead of under the JLabel, which is what is currently happening. Here is the paintComponent method if you want to see it: public void paintComponent(Graphics g){ super.paintComponent(g); if(a.shouldAnnotate()){ FontMetrics size= g.getFontMetrics(); if(getWidth()>

Zoom in and out of jPanel

别来无恙 提交于 2019-12-12 18:13:10
问题 I am wondering what is the best way to retrieve the location of a mouse clic after a zoom was made using paintComponent of a panel? (The location relative to this zoom). Here's the zoom code : public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D) g; if(zoomer==true){ at.scale(zoom,zoom);//at = AffineTransform... zoomer=false; } g2.transform(at); In my main class, I use a mouse listener private class and override the mouseRelase method : @Override

Aligning Shape's Center to JPanel's Center

送分小仙女□ 提交于 2019-12-12 16:50:26
问题 I have been trying to align my java2d shape's center to the JPanel's center with no success. I was able to do it for an image and many 2D shapes like parallelogram using getBounds method but not for rhombus though all of them follow the same pattern. Drastically, when I prepared an SSCCE out of the actual project I could align none of them correctly. I've written a drawShape method for drawing shapes on center. I didn't understand where I'm going wrong. This is SSCCE: import java.awt.*;

Drawing Graphics is too slow

ぃ、小莉子 提交于 2019-12-12 15:42:43
问题 So, I have this project, and you can draw images in it. I wanted people to be able to draw on it, but at first it was too slow when I was using repaint() So i used the repaint(Rectangle r) tool. It's better, but still not the speed i was looking for. Here is the code: import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; public class DrawingPad extends JPanel implements MouseListener,MouseMotionListener,ListSelectionListener{ public Color[][] picture =

Java Transparency rendering error

蹲街弑〆低调 提交于 2019-12-12 08:43:27
问题 I am currently developing a kiosk style Java program to display weather, time, forecast etc. Here is a shot of what the program should look like (screenshot taken before the time updated) The various sections are created as JPanels with the paintComponent() method overridden. They draw in a gradient header and a semitransparent background. However, when I change the content of one of these panels, the previous content is left behind, rather than being removed. An example is shown below: As