repaint

Changing Color of a Java graphic object

[亡魂溺海] 提交于 2019-12-25 09:47:30
问题 I'm trying to flash a Java graphic object by changing the color and calling the repaint() method. The color is only updating with the final change color call. Here is my code: public void start() { try { Color origColor = node.getColor(); for (int i=0; i<noOfFlashes; i++) { Manager.gui.getDrawGraph().changeNodeColor(node, Color.WHITE); Thread.sleep(500); Manager.gui.getDrawGraph().changeNodeColor(node, origColor); Thread.sleep(500); } Manager.gui.getDrawGraph().changeNodeColor(node, Graph

Changing Color of a Java graphic object

徘徊边缘 提交于 2019-12-25 09:47:28
问题 I'm trying to flash a Java graphic object by changing the color and calling the repaint() method. The color is only updating with the final change color call. Here is my code: public void start() { try { Color origColor = node.getColor(); for (int i=0; i<noOfFlashes; i++) { Manager.gui.getDrawGraph().changeNodeColor(node, Color.WHITE); Thread.sleep(500); Manager.gui.getDrawGraph().changeNodeColor(node, origColor); Thread.sleep(500); } Manager.gui.getDrawGraph().changeNodeColor(node, Graph

Java graphics isn't repainting

半世苍凉 提交于 2019-12-25 07:27:04
问题 I want to add in a feature so that when the mouse goes over a button then it will add a drop shadow. Currently I'm just trying to get the mechanics to work. I have my game loop calling a update method which I know works but here it is anyway public void updateManager(double delta){ mhandler.updateCoordinates(); if(mhandler.getX() >= 144 && mhandler.getX() <= 444 && mhandler.getY() >= 784 && mhandler.getY() <= 980){ oversp = true; }else{ oversp = false; } } mhandler is what I named my

Calling repaint in multiple threads?

ぐ巨炮叔叔 提交于 2019-12-25 03:39:31
问题 Since a few days I've been playing a bit with a small game in java. Does it hurt java swing when 2 threads call repaint() at the same time? I ask this because i have a paint thread, which calls repaint at a certain interval. In addition i call repaint when the player executes an action. Both repaint calls will repaint the same custom JPanel. In theory repaint can then be called by 2 threads at the same time. 回答1: Actually repaint() can be called in the same time in this case. But it is not a

Repaint doesn't work and the value of my private fields won't change?

不想你离开。 提交于 2019-12-25 02:31:08
问题 I am making a graphical interface in Netbeans where you can put a series of numbers (example: 7 8 5 4 10 13) in the textfield "punten" and when you press the button "ververs" a graphical linechart of all the numbers should appear (in my panel). I made a class "Gui" that extends JFrame with the Textfield, the button and a panel in it. I also made a class "Grafiek" that extends JPanel and that is linked with the panel in my "Gui". The problems that I experience are: the repaint(); command won't

Snake Game in Java

巧了我就是萌 提交于 2019-12-24 21:04:49
问题 I'm working on a program for snake. So far I have two classes, one for all the logic of the game and the other as a main class to run the game. Here's what I have Snake class: this is all the constants import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.util.*; public class Snake { // GUI components private JPanel board; private JButton[] snakeBodyPart; private JButton bonusfood; private JTextArea scoreViewer; // Constants private final int SNAKE_RUNNING_SPEED

Java swing — Jpanel not rerendering/repainting itself

感情迁移 提交于 2019-12-24 16:04:22
问题 Im using a JPanel with propertyChangeListener and want it to rerender itself based on whenever a particular variable model changes. My code for the same is as follows -- public class LabelMacroEditor extends JPanel implements PropertyChangeListener { private static final long serialVersionUID = 1L; private LabelMacroModel model; public LabelMacroEditor(LabelMacroModel bean) { this.model = bean; model.addPropertyChangeListener(this); setupComponents(); validate(); setVisible(true); } public

Creating an animation using JApplet

泪湿孤枕 提交于 2019-12-24 14:28:00
问题 I am working on a Java program that uses a JApplet which makes a ball bounce up and down. I am able to paint the shape onto the JApplet and everything like that. I just can't seem to get it to move. I have looked into this and saw that I need to create a method that pauses the shape then clears it from the JApplet, changes coordinates, and then redraws the shape in the new area but for some reason it's just not working for me. Thank you in advance for the help. import java.awt.Color; import

Java - repaint(x, y, w, h) doesn't call paintComponent? [duplicate]

拥有回忆 提交于 2019-12-24 13:40:15
问题 This question already has an answer here : Closed 7 years ago . Possible Duplicate: Java - repaint(x, y, w, h) doesn't call paintComponent? (with SSCCE) I'm trying out this neato performance trick repaint(x, y, w, h) and it sure is helping performance a lot. Unfortunately, the special extras I've put into a paintComponent in the same class are now not being painted. I put a System.out.println() test at the beginning of paintComponent and it turns out it's not even called (as our astute

Refreshing a JFrame while in an Action Listener

那年仲夏 提交于 2019-12-24 13:22:34
问题 The code snippet below sets text in a JLabel, which is added to a JPanel, which is attached to a JFrame. No matter what I do though (such as repaint(), revalidate(), etc) I cannot get the UI to update the text until the Action Listener is done. I have never had this problem before, possible because I have never had to have several things happen in a single firing of Action Listener. What am I missing? TL;DR Why does the following not update the text on the screen until it has finished firing