Refresh graphics in applet....
hi,
I have an panel in my applet that draw shapes on it.
In my panel (a class that extends JPanel) I have some draw functions:
class x extends JPanel{
public void draw_function1(Graphics g){..}
public void draw_function2(Graphics g){..}
public void draw_function3(Graphics g){..}
My panel does not update graphics when I minimize the window or anything that requires refresh.
I CAN'T insert all my functions inside paint() method because the shapes are not drawn at the same time, it depends on the user events...
how can I restore the previous graphics and draw more graphics ???
thanks.
Try the update(g) for the Applet.
Similar Messages
-
How to make graphics in Applet not to repaint after I click "refresh"
Hi, pals
I have some interactive graphics inside an Applet. User can drag and
move the graphic objects. The problem is when user click "Refresh"
button of the web browser, those objects return to their original
positions. What I hope is to make those objects still lie on the new
position that user has moved them to after they click "refresh" or
"back" and "forward" button to return to the applet page.
do I need to write some thread control?
Think when you type new URL in the browser showing the applet and go to the new web page. The system will call
Applet.stop() and destory() to destroy the applet resource used by the
Applet webpage. When you go back to the applet page, the system will
call Applet.init() and start() to recreate it. All previous object
positions and states manipulated by user will return to original.
For example, there's a circle centered at (50,50), you move it to
center (100,100). Then you go to another webpage in the same web
browser frame. When you use "Back" button to return to the Applet, the
circle will be redraw at center (50,50). (why? because the browser call applet.init() and do all process as first time the applet download to your computer) What I hope is the circle still keeps
at its last center (100,100) . This seems impossible to me
since the applet has lost its memory about the center position
(100,100) last time when you go to another page and the system call
destory() to delete the applet.
Any suggestion?I think you can disable page refreshing with javascript, but how, I do not know.
I wish this is helpfull.
Ahmad Elsafty -
Wrong image refresh in java applet AND Windows 7
I'm managing since few days a java applet that takes an image from an industrial product and shows it in a browser (simple web server).
There is following issue: the image is not correctly loaded and refreshed in its own window if just opened but only if the applet is running on Windows 7. The issue is solved as soon as I reduce the window to icon (minimize) and then resize it. I'm looking into java documentation on how to manage the image rendering, maybe I have to override some update or redraw method more, but it is taking time and I'm still learning. NOTE that the window opened does show the issue only when the windows size is not completely shown in the monitor.
Meanwhile I'm wandering if some of you faced and solved similar problem.
Thank you in advance,
ElenaThank you Nitin for your quick reply!
These are the calling of the functions in the code. As you can see, before to show the image, we are managing a zoom/unzoom by mouse wheel and an addition of writings data on the image itself. All is working fine except on W7:
public void paint(Graphics g)
//System.out.println("[ImageFrame::paint my paint!!!]");
this.PaintImage(g);
public void update(Graphics g)
// System.out.println("[ImageFrame::update]");
this.repaint();
public void PaintImage(ImageInfo imageInfo, float fps)
if (imageInfo != null)
if (this.getImageInfoRef() == null){
this.setVisible(true);
this.setTitle("Image Viewer (" + imageInfo.bufferedImage.getWidth() + "x" + imageInfo.bufferedImage.getHeight() + ") ");
this.resizeImageFrame((int) (imageInfo.bufferedImage.getWidth() * zoomFactor), (int) (imageInfo.bufferedImage.getHeight() * zoomFactor));
this.lastFps = fps;
this.setImageInfoRef(imageInfo);
//System.out.println("this.getWidth(): " + this.getWidth() + " this.getHeight(): " + this.getHeight() + " zoomFactor: " + zoomFactor);////
this.PaintImage(this.getGraphics());
public synchronized void PaintImage(Graphics g)
ImageInfo locImageInfo = getImageInfoRef();
if (locImageInfo != null)
try
this.resizeImageFrame((int) (locImageInfo.bufferedImage.getWidth() * zoomFactor), (int) (locImageInfo.bufferedImage.getHeight() * zoomFactor));
BufferedImage bufferedImage = this.resizeBufferedImage(locImageInfo.bufferedImage, zoomFactor);
this.overlayCodeInfo(bufferedImage, locImageInfo.decInfoStruct, zoomFactor);
this.overlayPointerInfo(bufferedImage, locImageInfo.scaling, zoomFactor, this.crossX, this.crossY);
this.overlayFrameRateInfo(bufferedImage, this.lastFps);
Image img = Toolkit.getDefaultToolkit().createImage(bufferedImage.getSource());
boolean retdraw;
retdraw = g.drawImage(img, frameUpperBondarySizeX, frameUpperBondarySizeY, this);
catch (Exception ex)
System.out.println("[ImageFrame::PaintImage] Exception: " + ex);
Thank you again
Elena -
Graphics in applet not showing
Hi
I am new to applet making. I am using some jpgs in my applet for menu purposes.
I have put the images in the jar file in the correct directory but the images are not showing up.
but if i actually put the jpgs in the directory of the jar files it shows up.
my question is .. how can I make the images show up with out having to actually have them in a folder but just have them in the jar files.
ThanksJust use the archive attribute of the applet tag point
to your jar file e.g
<applet code=someclass archive="somejar.jar" width=xx
height=xx>
</applet>I am using the archive attribute.
and I made sure my graphics are in the right directory.
I also tried putting them in same directory as the classes and changing my code.
But they still don't show up.
Thanks for you help! -
Hi there,
I just started in implementing my first abap programms.
I created a dynpro with a cl_gui_alv_grid and a cl_gui_gp_pres.
What I wanted to have was a selection from the cl_gui_alv_grid which makes draw some correspondent lines in cl_gui_gp_pres.
So far so good, I written a handler for handling doubleclicks, which makes the whole GFW initialization similar to the GFW tutorial in a FORM.
(http://www.the-blue-orb.com/link/sap-db2/disk1/doc/sap/17/b9677b48ba11d396a100a0c9308b1f/content.htm)
Works fantastic!
Then comes my problem: selecting an other entry, I would like to have the graphic refreshed. But nothing happens!
I get the new values fetched, and the whole GFW initialization is redone by calling the FORM again which uses now the new values.
Unfortunately the GFW stuff seems cached somehow. It doesn't change at all!
So I tried to destroy, free this thing before reinitiatlizing it, but then I get a short dump.
I' am quite sure there must be an easy way, to get this custom control, gfw stuff refreshed, but me as a beginner was not able to find it :-).
Do you have asimple idea for me?
Many thanks and best regards!Hi Marek,
Take a look at REFRESH method in CL_ALV_GRAPHICS.
Sri -
Repaint method not refreshing graphics
I have an application that draws a number of lines (Line2D). It does this by running through an ArrayList of Line2D objects and draws them in the paintComponent method of a particular panel (which works fine).
Now, I have a functionality that allows the user to right click on the line, which brings up a JPopupMenu and allows the user to change the colour of that line. At the end of the mouseClicked method i have a call to area.repaint(), but only the part the popup menu covered is ever repainted... until i cause another mouse event). Either that or i have to force the graphics to be redrawn by minimising/max the window or messing about with the scrollbars.
Does anyone have a better solution, please?
Thanks in advance.The problem is that the mouseClicked method exits
before the color is chosen. You should make the call
to repaint() in the same method that you change the
color of the line.Hi eewest... Yes, I've tried this too -- doesn't work as well, I'm afraid!
I haven't tried this yet but I've just been told that repeated calls to repaint() concatenate into a single call in the 'AWT thread' (?) and sometimes this can take a while for it to be executed (apparently repaint calls revalidate() and paint() in that order according to that thread --- somehow...). Anyway, the solution i'm told is to do something like this
public void mouseClicked(MouseEvent ev)
//put whatever functionality here
try
Thread.sleep(100);
catch(InterruptedException e){}
finally
myJPanel.repaint();
I'll let you folks know if this actually works tomorow!!
Cheers. -
JBuilder 2005 & graphics in applets
In JBuilder 2005 I run the following code:
package gif;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class GIFApplet
extends JApplet implements ItemListener {
JComboBox cb;
Image img;
public void init() {
cb = new JComboBox();
Container c = getContentPane();
c.setLayout(new FlowLayout());
cb.addItem("1-ое изображение");
cb.addItem("2-ое изображение");
cb.addItem("3-ье изображение");
cb.addItemListener(this);
c.add(cb);
img = getImage(getCodeBase(), "1.gif");
public void paint(Graphics g) {
g.drawImage(img, 100, 100, this);
public void itemStateChanged(ItemEvent ie) {
}As a result:
1) I can't see combobox on the form as it's painted over when the form repaints.
2) I jhave animated GIF-image. When the animation is showing, it does not redraw the whole picture, so it leaves rubbish on the screen frame by frame.
How can I correct this problems?> public void init() {
addKeyListener(this); -
Refreshing a text field in an applet
I wrote a program which produced a lot of numbers as output. I installed this program into an applet by calling it from the start() override and converting the number to a string then placing it in a text field. However, it only seems to display the last number. I am getting the impression that the display is only refreshed when the applet finishes. Is this generally the case? I have put in a call to repaint() after each output but it doesn't seem to make any difference. I know the program is working because the numbers appear in the OUTPUT window in IDE too, as I have done a System.out.print.
Here is my crazy programme. I put a sleep in but no difference. If I append to the buffer then all goes on the same line, which is not what I want. Also all appear at once when the program completes, but I want to watch this thing running. It produces prime numbers and increasing mp makes it produce lots and lots of them.
* SimpleScrolling.java
* Created on 21 March 2002, 15:00
* @author me
import java.awt.* ;
import java.applet.Applet;
import java.awt.TextField ;
public class SimpleScrolling extends java.applet.Applet {
TextField field;
public void init() {
initComponents();
//Create the text field and make it uneditable.
field = new TextField();
field.setEditable(false);
//Set the layout manager so that the text field will be
//as wide as possible.
setLayout(new java.awt.GridLayout(1,0));
//Add the text field to the applet.
add(field);
validate(); //this shouldn't be necessary
addItem("initializing... 1");
addItem("initializing... 2");
addItem("initializing... 3");
addItem("initializing... 4");
addItem("initializing... 5");
addItem("initializing... 6");
addItem("initializing... 7");
public void start() {
addItem("starting... ");
addItem("starting...2 ");
addItem("starting...3 ");
addItem("starting...4 ");
addItem("starting...5 ");
primes() ;
public void stop() {
addItem("stopping... ");
public void destroy() {
addItem("preparing for unloading...");
void addItem(String newWord) {
String t = field.getText();
System.out.println(newWord);
field.setText(newWord);
try {
repaint() ;
Thread.sleep(100) ;}
catch (InterruptedException e) {}
public void primes()
String primeString ;
long i=3 ;
int j, k=0, t=0 ;
final int mp = 10 ;
long[] primes; // declare an array of integers
primes = new long[mp]; // create an array of integers
for (j = 0 ; j < mp ; j = j + 1 ) primes[j] = 0 ;
primes[0] = 2 ;
while (t!=2)
j = 0 ;
t = 0 ;
while ( t == 0)
if (j>=mp) {t=2; break;}
if ((primes[j] * primes[j]) > i) {t = -1 ; break;}
if (i % primes[j] == 0 ) {t = 1 ; break;}
j = j + 1 ;
if (t == -1)
k = k + 1 ;
if (k < mp) { primes[k] = i ; } ;
if (k % 1 == 0)
primeString = String.valueOf((int) i) ;
addItem(primeString);
validate();
i = i + 2 ;
/** This method is called from within the init() method to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
private void initComponents() {
setLayout(new java.awt.BorderLayout());
// Variables declaration - do not modify
// End of variables declaration -
Applet in Apple Mac OSX problem
Hi all,
have developing an applet long while using WinXP platform, everthing seem ok, but when i try over Apple Mac OSX, i has a loading problem saying that init failed to load ArrayList as error message said:
ArrayIndexOutOfBound, 0...
but when i debug print out the ArrayList content and its length, i'm sure that this ArrayList is NOT NULL and its length is NOT ZERO either. what is happening here? oh, ya, this only happen in Safari, in FireFox for Mac no problem, even Camino also pass the test, why? anyone have idea about this? because i'm new to Apple Mac.
also, there is another question whereby, when i use FireFox for Mac to load the applet, the applet load seem no problem but it just can't display properly. what i mean is that in Windows platform (IE6), this applet show entire applet successfully, but when i try it in Mac, it show only a part of applet without any error, but when i try to refresh the page, applet is now successfully show, why?
lastly, when a button of an applet being click and this will bring a new window with some parameters value, its work on IE in Windows platform, why it won't work for FireFox or Safari for Mac? i see prompt out saying is security problem, is there any workout of this? thanks. to summary out of junk above:
_______________________________FireFox_____Safari_____IE
_______________________________Win | Mac_____Mac____Win
1. load applet for 1st time___________OK_|_NO_____FAIL____OK
2. refresh applet after 1st load failed___OK_|_OK_____FAIL____OK
3. when applet button click (security)___OK_|_NO_____-_______OK
p/s: all above test was using same applet with same parameter and value.
below is the sample i capture from Apple Mac just now:
http://img.photobucket.com/albums/v660/ahbeng78/Apple_Mac.png
Message was edited by:
ahbeng78i has a loading problem saying that
init failed to load ArrayList as error message
said:
ArrayIndexOutOfBound, 0...Well, post the stack trace.
but when i debug print out the ArrayList content and
its length, i'm sure that this ArrayList is NOT NULL
and its length is NOT ZERO either. You can still get an out of bounds exception with those conditions. The list could exist, its length could be N, but you're trying to dereference position N + 5, for example.
try it in Mac, it show only a part of applet without
any error, but when i try to refresh the page, applet
is now successfully show, why?My guess is that you're not calling repaint() when you should, but that's just a guess.
lastly, when a button of an applet being click and
this will bring a new window with some parameters
value, its work on IE in Windows platform, why it
won't work for FireFox or Safari for Mac? i see
prompt out saying is security problem, is there any
workout of this? thanks. to summary out of junk
above:Often you can sign applets so they can do things that unsigned applets aren't allowed to do.
Maybe you're making some kind of security mistake that Firefox and Safari are (properly) catching but IE isn't. In any event, post the error message. -
DoubleBuffering problem with applet
Hi,
We are developing an applet with multiple screens. CardLayout is being used to flip between different panels in the systems. The applet contains huge JTable and chart components and huge amount of data, which makes the refreshing of the applet very slow. We tried the DoubleBuffering concept to reduce the flickering in the JApplet class.
Now the questions are:
1) Do we need to do double buffering for all the panels that are used in the system ?
2) Is there any other better way that Sun suggests to avoid flickering problems ?
Any help will be much appreciated. Also with the email content and problem definition thread is going on, any feedback about this email is also welcomed.
Thanks
AnoopOne solution is to put all the packages in a jar file.
-
Win98 need to resize applet viewer to see forms client
Is there any work around that will aliviate the problem of needing resize the applet viewr (JInitiator) manually to see the java applet?
This is consistent bug and it seems to appear on all of our Win98 clients (WinNT works fine) in both IE 5.0 and Netscape 4.0There is a work around for this problem by using the resize_window(FORMS_MDI_WINDOW, height, width) you can force the refresh of the applet window. The ability to use the resize_window on the MDI window web deployed was supposedly just made available with patch 5. I had the same problem and this fixed it for me.
-
Hello everybody,
when we scroll down in the internet explorer so that parts of an applett are out of the screen and scroll up again, some parts of an applet is black.
This is the part which was outside of the screen.
You can see this here:
[http://img268.imageshack.us/img268/3797/appleta.jpg]
Does somebody know why this happens and how we can solve this problem?
(IE 7, MII 12.0.7, Java 1.6)
Thank you.
Regards MatthiasHello,
We called some functions (ie. change the query template) on the applet but only after it is loaded completly and we also made a refresh of the applet with java-script.
But: Clearing the cache (and restarting the IE) helped.
Thank you.
Regards
Matthias -
Hi Guys,
I have an applet that builds a panel and a button on the panel. When I move the applet of course it disappears how can I get the applet to repaint the panel in my following code:
import java.awt.*;
import javax.swing.*;
import javax.swing.border.*;
* box.java
* Created on November 22, 2002, 11:06 AM
public class Box1 extends JApplet {
private int x = 0;
private int y = 0;
private int w = 0;
private int h = 0;
public Box1 (int x, int y, int w, int h) {
this.x = x;
this.y = y;
this.w = w;
this.h = h;
public Box1(){
public void init()
JPanel p = new JPanel();
JButton b = new JButton();
setSize(400,400);
p.setSize(200,200);
p. setBorder (new BevelBorder (BevelBorder.RAISED));
b.setSize (75,75);
b.setVisible (true);
p.add(b);
p.setVisible (true);
getContentPane().add(p);
setVisible(true);
public void paint(Graphics g)
}Also I have tried to put the code that creates the panel and button in the paint method but nothing happens, why?
My goal is to create a box class that can create a panel that will reside in another applet. But right now I am testing the box class in an Applet. Later I will seperate the two. This is unreal why is creating graphics in applets such a pain in the kester.
Thanks,
JJ
Thanks in Advance,
JJEither take the paint method out entirely or put the line
super.paint(g)
in it. By having this empty method in your code, you the method which actually handles the painting isn't being called. -
Hi all
When iam using applets iam really confused how can we use methods of a class with out creating a object yes if its static then its fine ,
look at below
public void paint(Graphics g){
g.drawString("hello",10,10);
Now how can i use draw sting method with out creating object and interestingly Graphics is a Abstract class and drawstiring is a abstract method. It is same with evenr listeners also...
Plese make me clear about it.
thanks
JeevanGraphics g is a reference to not an abstract class that extends Graphics. Applet container (if you use a web browser container is built in) creates not an abstract class that extends Applet or JApplet. And this class calls paint(Graphics g) with parameter of a Graphics instance associated with an applet.
-
I have made an applet that runs under the applet viewer.
In netscape the button, labels, and textfields show,
but the button doesn't produce the remainder of the run,
as evidenced by no painting, like it does in the other situations.
It also runs as an application on a frame.
Where do I look for problems?
These are all of my imports:
import java.awt.TextArea;
import java.awt.TextField;
import java.awt.Label;
import java.awt.Frame;
import java.applet.Applet;
import java.awt.Toolkit;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.Button;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.Graphics;
dewayneMy Applet is really kind of neat and on one applet panel,
and I want to share it on the browser in the classroom.
My Applets used to work with Netscape on my computer.
Thinking that I probably lost a plugin,
I read as much as I could about plugins.
But I am really lost.
It seems unfortunate that one
has to know so much about things
peripherally to what one is trying to do.
It makes programming much harder
than it used to be a few years ago.
Can someone help me with some suggestions?
Or does the lack of responses mean that others don't know?
Or are they snubbing me? I give up.
dewayne
Maybe you are looking for
-
Can we both use the same iTunes but get all our music ect into one? Or can we share our separate accounts between devices? We both have iPod touch, iPhone 4 and an iPad each. At the moment I can't seem to get to my iTunes as it come up that it will d
-
Client Proxy : How to Call Outbound Generated Proxy in ABAP report ?
Dear SDNrs. I have already created a Scenario for Client/ Outbound Proxy in XI . I have already Generated Client/ Outbound Proxy in ECC . Now Question is How to call this generated Proxy in report ? Please Guide ..... I dont have any idea ... 1. bef
-
Financial Reporting Studio not allowing to connect to Essbase server
Hi All, I have installed 11.1.2.2 HFR studio (32 bit installed via workspace) on my machine and After logging in the Studio, when I try to create the Essbase connection in it, it throws me following error: "Failed to Connect to server" "Error connect
-
I began to usa JDK1.4 this afternoon, but I found a little trouble occured during my jounery in JAVA. When I compile my first "HelloWorldApp.java" programme, the JDK works well; and when I compile the second "HelloWorldApplet.java", it shows me that
-
One of the standard PCR form scenarios (SPPD - Internal Transfer - Enhanced) does not have a "Change Form" follow-up function. Does anyone know why it does not have the function, as other similar scenarios do have this follow-up function? We are on