repaint

Java 2D Game: repaint(); makes window grey

孤街醉人 提交于 2019-12-17 20:42:33
问题 I'm trying to make a 2D game in Java, but when I call the repaint() method in a thread there's an odd grey-only window. Here's the source code I have so far: Spaceshooter.java package spaceshooter; import javax.swing.*; import java.awt.*; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; public class Spaceshooter extends JFrame implements KeyListener, Runnable { private Player player = new Player(5, 186, this); private boolean up, down; public Spaceshooter(String title) {

Java GUI repaint() problem?

痴心易碎 提交于 2019-12-17 09:48:21
问题 I have a JFrame. This JFrame contains a JButton. I click the JButton and 10 JTextFields are created. the problem: I cannot see them until "I force a repaint()" by resizing the window. Only then do I see the JTextFields created. CODE: JPanel points = new JPanel(); //Creating the JTextFields: for (int i=0; i<10; i++) { JTextField textField = new JTextField(); points.add(textField); } repaint(); this.repaint(); super.repaint(); points.repaint(); THANK YOU - after the for loop, I just called

javafx listview and treeview controls are not repainted correctly

与世无争的帅哥 提交于 2019-12-17 02:24:26
问题 i am trying to put elements on a listview and treeview with javafx, but both controls wont refresh theyre content. i am using an obvservable list to control the items and every time i delete one item, the listview or treeview removes it from the datasource. but the view is not updating. i am still seeing all the items. the only difference is, the removed item can not be selected any more. for example link 2 shows the collaped item list. image 1 shows the items before they are collaped. the

JPanel not displaying in JFrame after paint is called

℡╲_俬逩灬. 提交于 2019-12-13 20:51:19
问题 I am currently imlementing a simple GUI interface to interact with a Lego Mindstorm NXT. My current issue resides with a paint issue on my interface. When my MainUI loads it calls a method called GirdPanel() which sets up my GridPanel. The MainUI, which extends JFrame, then adds this panel to it's JFrame calling. Here is the full code for MainUI that matters for this problem. public MainUI(){ setSize(700, 600); PathPanel pathPanel = new PathPanel(controller); add(pathPanel, BorderLayout.WEST)

Graphics2D not clearing transparent image

北慕城南 提交于 2019-12-13 15:15:07
问题 I have the following snippet of code which should increment a counter on a transparent background on the first monitor. When the image shows 0 it renders fine, but after that (as soon as 1 is hit) the window redraws with an opaque background. Silly example in practice I know, just broken a real use case down to a simpler piece of code. It seems the key might be in the paintComponent method of TestCanvas: g.setColor(new Color(0, 0, 0, 0)); g.clearRect(0, 0, getWidth(), getHeight()); From what

Grid DFS visualization

≡放荡痞女 提交于 2019-12-13 10:17:03
问题 Hello guys I am working on a project where I am trying to create a maze generator. So far I have a gird that is a 2D array of a Cell class and a JPanel that paints the grid to a JFrame and a function which uses Depth first Search to visit each Cell in the grid. When the Cell has been visited the Cell color changes to black on the grid. My problem is the repaint on the grid is too fast is there anyway I can slow the time or set a timer to repaint after a number of seconds. Here is the code

Java snake game

 ̄綄美尐妖づ 提交于 2019-12-13 09:55:17
问题 Well starting off i must admit there are countless snake questions out there, though every Programmer even if newbie or expert writes his code differently so i decided to open another one case, import java.awt.Color; import java.awt.Graphics; import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; import javax.swing.JFrame; public class Game1 extends JFrame { float x; float y; int[][] tileKati = new int[30][30]; int keyCode; int body; boolean Right = true; boolean Left = false;

Java repaint() method doesn't always work

廉价感情. 提交于 2019-12-13 08:08:32
问题 There is a problem with the repaint() method in Java. I made a new thread that constantly repaints the screen. When I release the spacebar I want my player to fall smoothly by setting its position and then waiting for 50 milliseconds and looping that 20 times. Instead, it waits the whole amount of time in the loop, then repaints. I am wondering why it doesn't constantly repaint the changes in the players co-ordinates. Thank you. (Edit) Thanks everyone for the help. This is my first time using

Trouble with JApplets and calling paint/paintComponent

孤街浪徒 提交于 2019-12-13 06:27:42
问题 So I'm just doing some studying for finals here, and I'm having trouble getting this to work. What I have always done previously is call paintComponent(Graphics g) and things have worked just peachy. But now I'm getting a "paintComponent has protected access in JComponent" error when I go to compile. The only way I could get it to compile was to tell it to call paint. But even if it compiles, paint never gets called in the applet window. What am I not seeing here? public class LineDraw

Repaint() method doesn't invoke paint() & paintComponent() methods one by one, only paintComponent () method is working

♀尐吖头ヾ 提交于 2019-12-13 04:08:50
问题 My application can crop images. What I want to achieve is rectangle to be drawn before image is cut according to the coordinates taken from the MouseListeners. This is my code: public class ImageScreenShot extends JPanel implements MouseListener, MouseMotionListener { ImagePanel im; int drag_status = 0, c1, c2, c3, c4; public int getC1() { return c1; } public int getC2() { return c2; } public int getC3() { return c3; } public int getC4() { return c4; } public void cut() { im = new ImagePanel(