repaint

Java graphics events not occurring in the order I expect them to

Deadly 提交于 2019-12-24 12:48:47
问题 So I'm making a graphical card game. Each card is a JPanel with a button and two images associated with it. I have a flip method, which is the first thing I call in my action listener when a card is clicked on. public void flip() { if(b1.getIcon() == card2) b1.setIcon(card1); else b1.setIcon(card2); revalidate(); repaint(); } However, for some reason the card doesnt flip (meaning the icons don't change) until some point after I call this method. For example, when I put a Thread.sleep after I

Smooth out Java paint animations

被刻印的时光 ゝ 提交于 2019-12-24 10:49:02
问题 I would like to make my app draw moving image a little smoother than how it is currently drawing them. I am not sure what to do to do that. This is what my main game Thread looks like: @Override public void run(){ int delay = 500; //milliseconds ActionListener taskPerformer = new ActionListener(){ @Override public void actionPerformed(ActionEvent evt){ Car car = new Car(); int speed = (int)(3 + Math.floor(Math.random() * (6 - 3))); car.setSpeed(speed); MainLoop.this.gameObjects.vehicles.add

Java repaint method does not work when called from another class

半城伤御伤魂 提交于 2019-12-24 09:26:24
问题 I have been coding up Java with Netbeans for about a year now, and have written a lot of data manipulation code which plots graphs on-screen. I generally plant a JPanel object in my main window, write custom painting code, and call the repaint() method as needed. But today, for the first time, I tried to invoke a repaint on a panel from a class (object) other than the one that contained the panel. Although the compiler found nothing wrong with this, and in debugging mode, it single-stepped

EDT and other Thread relations regard repaint() method java

好久不见. 提交于 2019-12-24 06:58:33
问题 if the GUI was sure build by EDT does a repaint call on some other Thread invoke painting on the EDT? if not, how do i make sure it does, the more efficient the better. 回答1: Basically method repaint() invoke EDT by default, everything works until first Thread.sleep(int) was called, then you have an issue with Concurency in Swing, Have to look at Swing Timer, which providing basic funkcionalities for painting in the Swing or delaying any event(s) in the Swing GUI , If your update(s) isn't

In Java, AWT, repaint-method seems to be ignored in favor of start-method

ⅰ亾dé卋堺 提交于 2019-12-24 06:38:12
问题 I'm building an applet of a board game, and handling user input roughly looks like this: public void mousePressed(MouseEvent event) { int row = event.getX() / (getSize().width / 8) ; int column = event.getY() / (getSize().height / 8) ; if(possibleMove(column, row) { makeMove(column,row,whosTurn); repaint(); start(); } } After a human input, the computer chooses a move and calls repaint() and start() like this method does. But the screen seems to update only after the computer has made a move,

Image not repainting, just multiplying

谁说胖子不能爱 提交于 2019-12-24 00:05:15
问题 I have a JPanel implements a key listener. It pulls and displays an Image pulled from another class. NA the Key listener is passed to that class to get one of many images and move it 2px in a direction. My problem is that the old image does not disappear when I call repaint(), so i get a line of images. The thing is that when i combined the class with the image and the JPanel class in to one bi final it worked perfectly. I have done some research on this and i found double buffering. If i

How can I ensure correct drawing order in an OverlayLayout?

六眼飞鱼酱① 提交于 2019-12-23 15:52:39
问题 I am using a JPanel with an OverlayLayout to draw two unrelated components on top of each other. Specifically, I have a transparent component which contains my own line drawings, and beneath that, I am using a JMapViewer component, which displays OpenStreetMap tiles. This works. Except when the JMapViewer loads tiles asynchronously. In that case, it calls repaint() on itself when the loading is finished, and it draws itself over my line layer. My line layer cannot know this, since it cannot

how java graphics repaint method actually works

穿精又带淫゛_ 提交于 2019-12-23 02:04:37
问题 I've just started working with java 2d graphics applications, on my studies repaint is redrawing our graphics wasting a lot of resources. but I want to know what repaint is, does and how to use it efficiently, thread safely and fast for many movable dynamic objects on my canvas? 回答1: I would start by having a read through Performing Custom Painting and Painting in AWT and Swing repaint makes a request to the RepaintManager to paint part or all of a component. The RepaintManager will decide

JavaFX: Best way to update GridPane after row deletion?

浪尽此生 提交于 2019-12-23 00:22:30
问题 I am using a GridPane (inside a ScrollPane) as a table with user entries. Each row incorporates a username (Label), an icon depicting its state (ImageView) and two buttons, the second of which is used to delete the user entry. The two images below depict the scroll pane before and after the user entry deletion UPDATE: Code sample below: The obvious issue is that the GridPane items do not get automatically re-arranged and the deleted line still occupies space. Do I have to provide a method to