How To Tell Another Class To Repaint

Jan 24, 2014

It has to be from another class because the other class controls the fps timer, and I want it to repaint() the panel every tick. However, I cannot seem to find a way to do this because repaint() is not static, and therefor can not be called in any way from another class.

View Replies


ADVERTISEMENT

Repaint Window From Another Class?

Mar 31, 2014

I am trying to repaint a window from another class. the class Window handles an interface that displays pictures of movies. Via a JMenuBar you can add a new movie and its picture but in order for it to show in the Window i need to repaint certain aspects in the Window class GUI;

The window class constructor:

public Window() {
addComponents();
configurFrame();
addMenu();
}

The functions i want to repaint:

public void repaintWindow() {
this.getContentPane().validate();
this.getContentPane().repaint();
}

From my other class where i add a movie to an ArrayList i have made a "private Window myWindow;" there i call the function repaintWindow via mywindow.repaintWindow(); But this gives me an NullPointerException related to the repaintWindow function.

View Replies View Related

Repaint Won't Call PaintComponent

Oct 25, 2014

Java Code:

package com.cjburkey.games.war.g;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;

[code]....

Why is paintComponent not being called by repaint();? Also, paintComponent is called twice when the program starts, that works, repaint is the thing that doesn't work.

View Replies View Related

GUI - Swap Bar Arrays And Repaint

Nov 13, 2014

So as of right now, I'm trying to swap my bar arrays and repaint it. For now, I'm using the index 5 and swapping it with index 23. When I click the shuffle button, It swaps, but the highest bar still remains the same.

Here's my code.

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
public class AssortedAssortmentsOfSorts extends JFrame

[Code] ......

View Replies View Related

Swing/AWT/SWT :: Trigger A Repaint From Another Method?

Mar 5, 2014

I have two classes. One constructs my a rectangle using Graphics2D (the class is called Rectangles). The second takes a user input for the triangle, which I am passing back to the first class. I am trying to trigger a repaint of class one from the action listener I have on a button in the second class. how to trigger this event?

View Replies View Related

Swing/AWT/SWT :: Repaint Causes Stack Over Flow

Feb 26, 2014

I have the following code where I call panel repaint method from the action listener of the calc button but it causes stack over flow but when I modify it to call paint component method and removing the super term, the program executes. here is the code

import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Box;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.BoxLayout;

[Code] .....

View Replies View Related

Swing/AWT/SWT :: Drawing Various Shapes - Repaint Not Working

Jan 16, 2015

I'm trying to make a simple program that will feature some graphics. It will have a JCombobox that the user selects to draw various shapes. I can't get the repaint function to work however.

package selectingshapes;
import java.awt.Graphics;
import java.awt.Color;
import javax.swing.JPanel;
import java.awt.Graphics2D;

[Code] .....

View Replies View Related

Swing/AWT/SWT :: JTable - How To Repaint With Updated Data

Jun 5, 2014

Here's what I would like to happen:

Java/Swing dialog box appears on the user's screenIt allows the user to enter 2 values into labelled text fields (fname/sname)They select a "Click Me" push button which I hope will write the data into the table. But the table does not get refreshed.

If I minimise the dialog box and then open it again, the data still does not appear.

The code I originally built using eclipse/WindowBuilder. I've cut it back and tried to isolate the issue. But I still cannot figure it out.

I've added some diagnostic log messages to ensure that I am seeing the various events I think I need to see and have put code in the action callbacks etc.

import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import java.awt.GridBagLayout;

[Code] .....

View Replies View Related

Repaint Work In Combination With PaintComponent (Graphics)?

Oct 3, 2014

I am teaching myself AWT/Swing ... It concerns an application that creates dynamic graphics using the Graphics class. I understand that the code that creates graphics should be put in a "paintComponent" method of a (descendant of a) JPanel class. And that when you want to change something on this panel outside "paintComponent", you have to call the "repaint" method, that somehow causes "paintComponent" to be invoked.

However, I don't fully understand the explanation of the example at [URL]... . It concerns an application that moves a red square when a mouse button is clicked. The code can be found at the link, but I also repeat it below.

package painting;
import javax.swing.SwingUtilities;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.BorderFactory;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.event.MouseEvent;

[Code]...

This code indeed works. However, I don't understand why. The explanation at the Oracle site is the following.

Because we are manually setting the clip, our moveSquare method invokes the repaint method not once, but twice. The first invocation tells Swing to repaint the area of the component where the square previously was (the inherited behavior uses the UI Delegate to fill that area with the current background color.) The second invocation paints the area of the component where the square currently is.

However, what I don't understand: when repaint is first invoked, squareX and squareY still have their old values. If the invocation of repaint simply causes an invocation of paintComponent, then paintComponent should draw a red square at (squareX, squareY). Just like the second invocation of repaint causes paintComponent to draw a red suare at the new values of (squareX, squareY). Instead, the first invocation results in the red square being wiped out by the background color.

So apparently, the first invocation of repaint does not simply cause an invocation of paintComponent. What does it do?

View Replies View Related

JavaFX 2.0 :: JFreeChart - When Zoom In Or Out Repaint Works Not Well

May 8, 2015

I have a problem using JFreeChart with JavaFX. I wrote a small program here . At first the graph likes this:

I use fullScreen function to display the JFreeChart Line Chart Demo 2. Here I use SwingNode, ChartPanel to embedded JFreeChart into JavaFX Panel.(Detail part will be included in code later)

Then I press ESC to exit fullScreen. Then it looks like this:

So far, it's as expected. Then I use mouse drag to enlarge the window. Here comes the problem, as the following picture.
 
Can you see that, seems like appear another graph. And I must click on the window, then everything will become good. I wish the graph shows well even when I drag the window to enlarge, is there something I missed? And here is my code:

package testxychart; 
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

[Code] ....

I think, when I use several graphs in one JavaFX Panel, this will becomes a big problem.

View Replies View Related

Swing/AWT/SWT :: Repaint Method Is Automatically Erasing Old Circle?

Feb 19, 2014

This code is shown to eliminate "smearing":

public void paintComponent (Graphics g) {
g.setColor(Color.white);
g.fillRect(0,0,this.getWidth(), this.getHeight());
g.setColor(Color.green);
g.fillOval(x, y, 40, 40);
}

I had done all the previous code (in my own style) and found that the background rectangle was either being redrawn on its own, or there was something else removing the old circles from the screen. I then typed in the code from the previous page exactly as it was, to see if I had some change in syntax that would cause this, and it did the same thing.

Here's my code:

import javax.swing.*;
import java.awt.*;
public class SimpleAnimation {
int x, y;
private static final int HEIGHT = 600;
private static final int WIDTH = 600;

[Code] .....

Is this because I'm using JRE7? I can't find any documentation that indicates the repaint() method has changed since Java 5.

View Replies View Related

Swing/AWT/SWT :: How To Update JPanel Rather Than Refresh It Every Time On Calling Repaint

Jan 4, 2015

I would like to be able to draw things onto the panel (via paintComponent), but I'd like it to draw 'on top' of what's already there. The default seems to be that it resets every time I call repaint.

View Replies View Related

Swing/AWT/SWT :: Call Repaint 200 Times In Loop And It Only Calls PaintComponent Once?

Dec 2, 2014

I have been baffled by the functioning of repaint() - and the SwingPaintDemo3 with the moving square seems mysterious - you call repaint(x,y,w,h) twice and the first time it clears the clip area and the 2nd time it paints the red box. The code in paintComponent tells it to paint the box both times, yet somehow it ignores the initial box and only paints the 2nd one.

I've been writing code to bounce some balls in a box to try and understand the behavior. I set up an array of ball objects, loop through them, move them adjusting for collisions with walls and each other, then repaint(). I call repaint x2 for each ball, just like in the example. In my paintComponenet code, if I try to just paint the current ball only one ball will move, even if I send a different ball object each time. The only way to get all the balls to show up is to put a loop in paintComponenet that goes through all 100 balls every time I call it. I was worried that to move 100 balls I was painting 100x100 times.

So I put some System.out.println commands in my ball move loop, inside my object ball draw commands, and inside the paint component.

private void calculateMoveBall(BoxBalls oneBall) {
System.out.printf("
Entering calculateMoveBall [%1$2d]
",

[Code].....

So even though I called repaint() 200 times (twice for each ball), repaint was actually only called once, drew all the balls at once, and then went back. And I just noticed it appears to have waited until I exited the calculateMoveBall loop to go into paintComponent! The spooky things is how does it know to do that? Does the Java machine 'see' that it is inside of a loop, and perhaps also sees the loop inside of paintComponent, and somehow correctly guesses that it doesn't have to do it 200 times, but can wait and do it once? If I attempt to do the same thing in code, take the loop out of paintComponent() and call repaint() with the current ball, expecting the machine to do exactly what I tell it, it refuses and does it's own thing, waiting to call paintComponent on the 100th ball, drawing only the last ball (so I guess the loop inside paintComponent is not in the logic).

So a call to repaint() is a request for a higher being to decide if it has the time or energy to repaint the clip. If not, it ignores the call, or stacks them up for later (maybe I should try a million and see if it has room for that!) - well so far up to 4000 it behaves the same. This is useful if you are happy with "this is how it works so use it that way". However I really don't like having some kind of hidden logic that I have to trust to work the right way. If I don't want it to wait until later I'm not sure what to do. And I don't trust the machine to do whatever whenever. How do you debug that???

Questions: Is there documentation to know what repaint() will do or how it decides when to call paintComponent? The Swing tutorial gives the example but not the why. "By now you know that the paintComponent method is where all of your painting code should be placed. It is true that this method will be invoked when it is time to paint" "An important point worth noting is that although we have invoked repaint twice in a row in the same event handler, Swing is smart enough to take that information and repaint those sections of the screen all in one single paint operation. In other words, Swing will not repaint the component twice in a row, even if that is what the code appears to be doing." (What the code appears to be doing - now we have to guess what it is doing)

Is there a way to force repaint() to call paintComponent on a clip rectangle (not just on the whole thing?) I would think invalidate() would force repainting of the whole componenet.

Perhaps this is when you draw to a bitmap in memory and paint the whole thing on the screen...

View Replies View Related

Declaring Methods For A Class In Its Own Class Whilst Objects Of Class Declared Elsewhere?

Mar 5, 2015

How do you declare methods for a class within the class whilst objects of the class are declared else where?

Say for instance, I have a main class Wall, and another class called Clock, and because they are both GUI based, I want to put a Clock on the Wall, so I have declared an instance object of Clock in the Wall class (Wall extends JFrame, and Clock extends JPanel).

I now want to have methods such as setClock, resetClock in the Clock class, but im having trouble in being able to refer to the Clock object thats been declared in the Wall class.

Is this possible? Or am I trying to do something thats not possible? Or maybe I've missed something really obvious?

View Replies View Related

Inheritance In Java - Child Class Get Copy Of Methods And Variables Of Parent Class?

Mar 1, 2015

Does child class gets a copy of the methods and variables of parent class?

public class test1 {
public static void main(String a[]) {
Child c = new Child();
c.print();

[Code] ....

why is the output 1?

View Replies View Related

Access Getter / Setter Of Bean Class Where It Defined As Member In Another Class?

Feb 18, 2014

Class UserAssessBean{
private String username;
private int userid;
private ArrayList<ModuleBean> module;
--{get/set}--

[Code] ....

How can i access the getters/setters of module bean, when it was returned as array list in UserAssessBean?

View Replies View Related

Servlets :: Calling DoGet Of Child Class From Service Of Parent Class

May 28, 2014

Regarding the lifecycle of servlet , in headfirst servlet i can find :

You normally will NOT override the service() method, so the one from HttpServlet will run. The service() method figures out which HTTP method (GET, POST, etc.) is in the request, and invokes the matching doGet() or doPost() method. The doGet() and doPost() inside HttpServlet don’t do anything, so you have to override one or both. This thread dies (or is put back in a Container-managed pool) when service() completes.

How can I call the doGet method of the subclass from the superclass. i am not getting this .

View Replies View Related

Declare Array Of Parent Class But Instantiate Index To Sub Class Using Polymorphism

Apr 14, 2015

I have a quick polymorphism question. I have a parent class and a sub class that extends the parent class. I then declare an array of parent class but instantiate an index to the sub class using polymorphism. Do I have to have all the same methods in the child class that I do in the parent class? Here is an example of what I mean.

public class ParentClass
{
public ParentClass(....){ }
public String doSomething(){ }
}
public class ChildClass extends ParentClass
{
public ChildClass(....)

[Code] ....

Is polymorphism similar to interfaces where the child class needs all the same methods?

View Replies View Related

Accessing Parent Class Method Using Child Class Object?

Feb 4, 2015

I want to know is there any way we can call parent class method using child class object without using super keyword in class B in the following program like we can do in c++ by using scoop resolution operator

class A{
public void hello(){
System.out.println("hello");
}
}
class B extends A{
public void hello(){
//super.hello();
System.out.println("hello1");

[code]....

View Replies View Related

Current Execution Time Of A Class In Java By Running Another Class

Jul 14, 2014

i want to write a class in such a way that i should get the current execution time of another class which is running. I searched in net but it shows only how to calculate the time duration of the current class which is running. But as per my way, i need the execution time of one class from another class. How to do this ?

View Replies View Related

Pass Private Final Class Object To Another Class Constructor

Aug 28, 2014

can we pass private final class object to another class constructor?

View Replies View Related

Methods From Original Class Receiving Error When In Test Class

Jul 5, 2014

I am working on a program that simulates a bug moving along a horizontal line, My code works correctly when I test it in it's own class but when I tried testing my constructor and methods in a test class I received an error saying, "package stinkBug does not exist" on lines with my methods. However, stinkbug is not a package.

Java Code:

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

[code]....

View Replies View Related

Error Passing Value Of A Variable From One Class To Main Method Of Another Class

Jan 8, 2014

I've 3 classes.

1. Circle
2. GetInputFromUser
3. testCircle

package ABC;
public class Circle {
private double radius;
public double getRadius() {
return radius;

[Code] .....

In the testCircle class, in the line: getRadius = ui1.GetInput();

It's showing the error: The method GetInput(float) in the type GetInputFromUser is not applicable for the arguments ()

And when I do: getRadius = ui1.GetInput(rad);

It's showing the error: rad cannot be resolved

View Replies View Related

How To Create Object For Multiple Class Inside Single Class

Apr 22, 2015

How to create object for "class B" and call the "function_B" from other different class D where class D has no connection with class A? Here is my program.

public class A(){
void print(){}
}
class B{
void function_B(){}
}
class C{
void function_C(){}
}

Here, A, B, C are in the same package. But class D is in different package.

View Replies View Related

Declaring Class In Main Class - Constructor Cannot Applied To Given Types

Aug 1, 2014

So i declared a class in main class but it seems there's error when i compile:

constructor xx in class xx cannot applied to given types

This is my java class:

public class trainer extends person{
String classType;
public trainer(String name, String gender, String address, int id, String classType) {
super(name,gender,address,id);
this.classType=classType;

[Code] ....

And this is the way i declared in main class:

trainer tr = new trainer();

And what i want to do is:

tr.toString();

View Replies View Related

Interface Class And Object Class Is Compiling Symbol Errors

Nov 16, 2014

I am a beginner here at JAVA and I am trying to program a Gratuity Calculator using both interface class and object class but it keeps on compiling with errors saying "cannot find symbol".I tried everything to fix it but it just keeps on stating symbol.

[CODE]
public class GratuityCalculator extends JFrame
{
/* declarations */
 
// color objects
Color black = new Color(0, 0, 0);
Color white = new Color(255, 255, 255);
Color light_gray = new Color(192, 192, 192);
 
[code]....

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved