paintcomponent

Spring behavior simulation

£可爱£侵袭症+ 提交于 2019-11-26 23:06:47
Basically, i want to simulate spring behavior on painted image. I want to make it run through a few iterations scaling it up and down (like it is fixed on a spring). All of the examples i found on the net lead to this class - FloatSpring.java It should provide the needed calculations to move point A to point B applying spring-like effect which depends on various FloatSpring class settings. The problem is that i didn't find a single clear example how to use it properly. I made this small example to test FloatSpring on: public static void main ( String[] args ) { // Some image to bounce final

Difference between paint() and paintcomponent()?

[亡魂溺海] 提交于 2019-11-26 22:58:54
I have tried tutorials on this but I still don't quite understand it. Basically my question is which method is better and why? Should I use paint or paintComponent ? Please try to keep the answer simple, thanks. christianhs Quoting from documentation of paint() method This method actually delegates the work of painting to three protected methods: paintComponent, paintBorder, and paintChildren. ... A subclass that just wants to specialize the UI (look and feel) delegate's paint method should just override paintComponent. It looks like the paint() method actually draws the component, including

paint() in java applet is called twice for no reason

巧了我就是萌 提交于 2019-11-26 18:39:37
问题 Is there a common reason why the paint() method may be called twice without being intended. I have the following code: public void paint(Graphics g) { //Graphics2D gg; //gg=(Graphics2D) g; drawMatrix(g); } private void drawMatrix(Graphics g) { int side = 40; hex hexagon=new hex(); for(int i = 0; i<9; i++) for(int k = 0; k<9; k++){ g.setColor(Color.lightGray); g.fill3DRect(i*side,k*side, side, side, true); if (matrix[i][k]!=null){System.out.println("i is "+i+" k is "+k); g.setColor(Color.black

.gif image doesn't moves on adding it to the JTabbed pane

混江龙づ霸主 提交于 2019-11-26 17:57:49
I have a JFrame. In that i have two containers i.e two JPanel. one Panel holds a image. other holds a JButton. Then these two are added to JTabbedPane. My problem is on using a .gif image the image becomes static as any other normal .jpg image. Can anyone help me with some more ideas? Here is my code: import java.awt.Component; import java.awt.Dimension; import java.awt.Frame; import java.awt.Graphics; import java.awt.GridBagLayout; import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.image.BufferedImage; import java.io

Why not to draw directly inside JFrame [duplicate]

南笙酒味 提交于 2019-11-26 17:22:46
问题 This question already has answers here : Difference between paint() and paintcomponent()? (2 answers) Closed 5 years ago . Can anyone explain me why shouldn't i use paint method to draw directly inside a JFrame window, and i should use paintComponent method with a JPanel inside the JFrame ? Thanks in advance. 回答1: Three main reasons... Top level containers aren't double buffered, which cause flickering when the frame is repainted, yes, you can implement you're own double buffering, but...

Swing Worker : function get()

放肆的年华 提交于 2019-11-26 16:41:48
My problem is that I don't understand how the swingworker works because what I'm trying to do is to make fa=worker.get() because I have a long method which compute a lot of points running in background because I don't want to freeze my interface and I want to get her results to paint the component image. But I don't understand where it goes when I do fa=worker.get() because my console prints "titi" and I put a lot of other printing to see the next part of program reached but no one is printed. Please help me to know where the compilation goes after get() or while it execute it and if you have

How to draw an image over another image?

旧时模样 提交于 2019-11-26 15:31:35
I have a Java project that's about traffic network simulation in a random city, I've managed to figure out a way to implement this project, so I divided each intersection into a section which is basically an extended JPanel class (named Carrefour)...everything works well until I got stuck with how to draw vehicles and make them pass through roads. So my problem is how to draw an image (vehicle image) over an another image (road)? If this is Swing, then draw the background image in a BufferedImage. Display this BufferedImage in a JComponent's (such as a JPanel's) paintComponent method using

Implementing a mouse click event on a tile in a map

喜你入骨 提交于 2019-11-26 14:55:20
问题 I'm trying to implement a mouse click event for an image (basically a tile on a map) on a JPanel. I'm just not able to figure out how to go about it. I have a Main class that extends JPanel. I'm retrieving tiles from a tile server and displaying them in the paintComponent() method of the Main class based on the specific zoom level. I use tiny locator images to represent a specific monument or a building in a city in the same paintComponent() method. They are placed on top of these tiles based

paintComponent draws other components on top of my drawing

主宰稳场 提交于 2019-11-26 14:48:54
问题 I'm trying to build a simple paint tool. The mouseDrag events creates a new ellipse and causes my JPanel to repaint() . This works fine so far. However, if I press any button (or any other UI component) before firing the mouseDrag event for the first time, the button is painted in the upper left corner of my panel. I have isolated the code into this test application: import java.awt.BasicStroke; import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.Graphics; import java.awt

Why does calling dispose() on Graphics object cause JPanel to not render any components

删除回忆录丶 提交于 2019-11-26 14:43:07
问题 After learning that dispose() should be called on Graphics / Graphics2D object after use, I went about changing my game to incorporate this. When I added g2d.dispose() in overridden paintComponent(Graphics g) of JPanel , my components which I added (extensions of JLabel class) where not rendered I was able to still click on them etc but they would not be painted . I tested with a normal JLabel and JButton with same effect (though JButton is rendered when mouse is over it). So my question is