I have a custom class which extends JPanel and overrides the paintComponent() method. Here's what that looks like: @Override protected void paintComponent(Graphics g) { if(redrawRequested) { g.setColor(ETCH_BACKGROUND_COLOR); g.fillRect(0, 0, owner.getAppWidth(), owner.getAppHeight()); redrawRequested = false; } g.setColor(Color.BLACK); g.fillRect(pointX, pointY, PIXEL_SIZE, PIXEL_SIZE); } The same custom class also implements KeyListener. I am listening for some keys, and more specifically Space which calls a method requestRepaint(). Here's what that method looks like: public void requestRepaint() { redrawRequested = true; revalidate(); repaint(); } My problem is, when the program starts, whats in the if block inside paintComponent get's fired but the fillRect doesn't work(?) …

Member Avatar
Member Avatar
+0 forum 17

Hi. I have a JFrame with a JLayeredPane. On the first layer there is a table, then above it there is black transparent layer that allows me options and what-not. I animate the arrival of this transparent layer. However when I do this the panel seems to loose it's transparency, that is until I interact with the base layer, THEN I see through the transparent layer again. Sometimes, when I start interacting with the textfield or button on the transparent level, it starts displaying pieces and bits of the lower layer on the Transparent layer. Am I missing the need …

Member Avatar
Member Avatar
+0 forum 2

Hi everyone, I was writing a program to show visually some vectors I was implementing with Java but I ran into an issue. My program has 3 classes, a driver, a Vector class and a VectorDisplay. The driver and vector class are self explanatory, but here is the code. Driver: import phys.*; import java.util.*; public class Driver { public static Vector1 vect1 = new Vector1(50, 70); public static void dispVectStats() { vect1.dispVect(); vect1.drawVect(); } public static void main(String[] args) { System.out.print("\f"); dispVectStats(); } } Vector: package phys; import java.util.*; public class Vector1 { private int x; private int y; public …

Member Avatar
Member Avatar
+0 forum 3

Hello, I'm trying to make a JPanel with JFrame capabilities, such as resizing, and moving, Everything seems to work fine, altough there are minor flickering inside the JPanel, I have numeral repaints and I have a method called update(), which uses absolute position to arrange Containers and Components. Whenever the JPanel is resized, update() is called. This is a 2 part problem. 1. Flickering. 2. Cant get a container from another class to get resized within the JPanel. Is there any way to resolve these problems? [CODE]import java.awt.*; import java.awt.event.*; import javax.swing.*; public class sys_windows extends JPanel implements ActionListener, MouseMotionListener, …

Member Avatar
Member Avatar
+0 forum 11

Hello everyone. I just started on 'converting' my multiplayer text RPG into a graphical form. What I am trying to do is this: Create a title window, basicly just a JPanel with one image filling the space. To this JPanel I add a MouseListener. When a user clicks the window and thus the panel, I change the Image to draw to just the background image, ie no text, and then call repaint(); However what happens, is that I have to click the panel twice for the background Image to appear. After the first click I just get the JPanel's background …

Member Avatar
Member Avatar
+0 forum 11

Hi Guys, I have developed a program which continuously draws a circle using a timer. Now every time the circle gets displays it flickers and which is because i have used me.refresh. Is there any other way to avoid this flickering. here is my code [CODE]Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As EventArgs) Handles Timer1.Tick Me.sweepAngle += 1 If Me.sweepAngle = 360 Then Me.Timer1.Stop() End If If sweepAngle = 90 Then change = 1 End If If sweepAngle = 180 Then change = 2 End If 'Me.Invalidate() Me.Refresh() 'Me.SetStyle(ControlStyles.AllPaintingInWmPaint, True) 'Me.SetStyle(ControlStyles.UserPaint, True) 'Me.SetStyle(ControlStyles.DoubleBuffer, True) End Sub Public Sub …

Member Avatar
Member Avatar
+0 forum 4

Hello everyone on Daniweb!:) I'm all new with working with swing and I'm having some problems making my paint method work:/. Atm I'm just tryin to make it write a ball, which I can control into different directions. Right now there is quite alot of unnecessary stuff in my code but please don't bother about that:P. Here's the code: [CODE]import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.lang.*; import java.awt.event.KeyEvent.*; import java.awt.event.KeyListener.*; import java.awt.Graphics.*; public class Boll { JFrame frame=new JFrame("hej"); JLabel panel=new JLabel(); private int x=250, y=250; private boolean ball=true; private boolean jump=false; private final int MAXX=500, MAXY=500; private int …

Member Avatar
Member Avatar
+0 forum 14

HI I am working on a project to animate user-defined algos. I am still at the very beginning but I am practicing code in swing and here is an Array class that the user can use in his user defined algo: [CODE] import java.awt.*; import javax.swing.*; public class Array1 extends JPanel { int size = 0; int count = 0; int[]hold; public Array1(int[]arr) { size=arr.length; hold = arr; } public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D) g; for(int i=1; i<=size; i++) { g2d.drawRect((i*30), 30, 30, 50); } for(int i=1; i<=size; i++) { g2d.drawString(Integer.toString(hold[i-1]), (i*30)+15, 55); } } …

Member Avatar
Member Avatar
+0 forum 1

The End.