repaint

Java - Calling paint method from different class?

霸气de小男生 提交于 2019-11-29 12:50:47
I have a class which extends JFrame and creates a window and it needs to call the paint() method which is in a different class. I understand that if they were in the same class, the setVisible(true) would call the paint method, but since they are in different classes, it does not. I have created objects of the Die class (the one painting), but I don't know how to use them to call the paint method. This is the class which creates the window: public class Game extends Frame { public void window() { setTitle("Roll"); // Title of the window setLocation(100, 100); // Location of the window setSize

<img /> vs background-image (css) in performance

天涯浪子 提交于 2019-11-28 21:10:51
I am building a site that is using a scrolling plugin that basically animates the scrolling. I am quite concern about performance as if I insert some images in the site, it looks quite choppy when scrolling/animating. The main problem I can detect with images is the reflow/repaint issue, when the image doesn't have the correct dimensions and therefore is scaled (I have to deal with this, I know about the best practice ). With this statement in mind (images will be scaled). What should be better, image element or divs with those images as backgrounds as for performance? I made this jsFiddles

Visual Artifacts appearing on JPanel

泪湿孤枕 提交于 2019-11-28 14:15:51
I am trying to create a program with 2 JPanel using BorderLayout . The center panel is for random drawing of rectangle while the south panel is for the buttons. I am getting a weird image of the button on the top left corner of the JFrame whenever I hover the mouse cursor over the North or South button. I did some research and found out that this could be the reason for having a transparent background. I tried using super.paintComponent(g) for the panel but the rest of the rectangles drawn earlier disappear. I need the rectangles to stay in the JPanel but not the weird image on the top left. I

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

时间秒杀一切 提交于 2019-11-28 13:13:55
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) { super(title); this.setFocusable(true); this.addKeyListener(this); } @Override public void paint(Graphics

Can't repaint my JFrame/JPanel

断了今生、忘了曾经 提交于 2019-11-28 10:23:37
问题 I have created a program that just moves a ball across a screen. I used to have it all in one class, but decided that it looked too messy so I split it up into three different classes: Main... initializes everything, Game... which paints everything and is a JPanel, and AL which is a KeyListener (which is also where the problem is). The problem is that I can't get the program to repaint from my AL class no matter what I try to pass into it. Can anyone help with this? Here are my three classes:

How to remove all components from a JFrame in Java?

自闭症网瘾萝莉.ら 提交于 2019-11-28 06:48:34
I'm writing a program where I have a JFrame and I want to remove all components from it, then add just one component to it and repaint the frame. What I have so far is something like the code below (called in an object that implements JFrame, where StartPanel implements JPanel): removeAll(); startPanel = new StartPanel(); startPanel.setVisible(true); add(startPanel); revalidate(); repaint(); However, when I run the code it shows an empty window (not the startPanel) and when I minimize/resize the window, the window turns black. If I leave out the removeAll() and there are not elements already

Java - Calling paint method from different class?

我的梦境 提交于 2019-11-28 06:15:46
问题 I have a class which extends JFrame and creates a window and it needs to call the paint() method which is in a different class. I understand that if they were in the same class, the setVisible(true) would call the paint method, but since they are in different classes, it does not. I have created objects of the Die class (the one painting), but I don't know how to use them to call the paint method. This is the class which creates the window: public class Game extends Frame { public void window

Change Panel size on button click

元气小坏坏 提交于 2019-11-28 04:11:59
问题 I have the following code: package in.res.num.tapb.ui; import java.awt.BorderLayout; import java.awt.CardLayout; import java.awt.Dimension; import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.BorderFactory; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; class MainClass extends JPanel { public MainClass() { Registration registration = new Registration(); ButtonPanel

How to search subfolders and repaint a jTable with new data in Java?

时光毁灭记忆、已成空白 提交于 2019-11-28 02:27:11
I'm having a couple problems with my program. I wanted a jTable to display various data points added to its TableModel, but I can't seem to get the table to update with the new data. Also, it seems my search for png images within a directory has fallen short of actually searching the directory completely for all png images and stops only at the first folder's contents. I've placed all data points into appropriate ArrayLists for their data types and converted them to Object arrays before placing them within the TableModel of my jTable. It's not worked, and I've come short of solving these

Simple animation using Thread.sleep() in ActionListener

人走茶凉 提交于 2019-11-28 02:16:33
I'm having trouble with this code I am using to create a roulette wheel. The goal is to spin the wheel when I click the "SPIN!" button. I have done this by creating a for loop that should change the status of the wheel from true to false, which changes the orientation. This, when done fast enough, should create the illusion of movement. THE PROBLEM I AM HAVING : is that my wheel is only repainting after the whole for loop is done, despite my placement of the repaint(). So, it only spins one tick. Here is some sample code of my ActionListener: public class spinListener implements ActionListener