Forcing applet to re-draw itself

Hi,
I'm wondering if there is a way to force my applet to re-draw itself multiple times. Here is what I want to do:
I have, in my start method, a bunch of tasks. After each task is completed, I want to write a message to my applet window indicating that the task is complete. So, for exmaple, I'd write "task 1 complete," then "task 2 complete," etc.
How do I do this? I tried using this.add(), but if I do that, then all of my messages just appear at once at the end. I want them to appear one at a time, while I am in my start method. Is there a way to do this?

Hi,
I tried putting stuff into a thread, but it still isn't working. I must be doing something wrong.
Here is a really simple example of what I want to do:
import javax.swing.*;
import java.awt.*;
public class SwingTest extends JApplet{
public void init() {
     //Execute a job on the event-dispatching thread:
     //creating this applet's GUI.
     try {
     javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
          public void run() {
               createGUI();
     } catch (Exception e) {
     System.err.println("createGUI didn't successfully complete");
private void createGUI() {
     JLabel label = new JLabel(
                    "You are successfully running a Swing applet!");
     label.setHorizontalAlignment(JLabel.CENTER);
     label.setBorder(BorderFactory.createMatteBorder(1,1,1,1,Color.black));
     getContentPane().add(label, BorderLayout.CENTER);
     JLabel label2 = new JLabel("testing 1 2 3");
     label2.setHorizontalAlignment(JLabel.CENTER);
     label2.setBorder(BorderFactory.createMatteBorder(1,1,1,1,Color.blue));
     try {
     Thread.sleep(6000);
     catch(Exception e) {
     System.out.println("interrupted!");
          getContentPane().add(label2, BorderLayout.CENTER);
What I'm hoping to see is the first message, "you are running a swing applet," and then, after some delay, the second message, "testing 1 2 3". Instead, I just see the second message. What am I missing here?

Similar Messages

  • How to force datagrid headerRenderer to redraw itself?

    Hi guys,
        I had datagrid headers that blinks however, I want to turn the blinking off by assigning a new value of a property inside the headerRenderer. The newly assigned value is indeed stored in the property. But my problem is how to force this headerRenderer to redraw itself so it will execute the "override public function prepare(hasBeenRecycled:Boolean)" function as it has the condition that turns the blinking on or off.
    Any ideas?
    I had this worked but I have to get all the columns object and assign it to an arrayList then set the datagrid's columns to null and apply the arrayList. This works so perfectly in turning on or off the blinking. But this also scrolls up the datagrid back to top which I don't want to happen in my case.
    Ideas are much appreciated.
    Thanks in advance.

    Flex harUI wrote:
    I would move the blink logic to a shared function and have the renderer listen for a change event on some property and run that function.
    Thanks for the idea. That indeed makes sense! However, how do I assign a new value to some property inside the headerRenderer when PropertyChangeEvent only supports collection classes and ObjectProxy?
    example:
    from
    myHeaderRenderer.properties = {blink: true};
    to
    myHeaderRenderer.properties = {triggerObject.blink: true} // or triggerObject['blink']: true doesn't work either.
    Unless there is a way for the headerRenderer to listen to a property change outside of itself (referencing to the parent objects)
    OR
    a way to call a function inside the headerRenderer from the main (parent) document.
    Thanks in advance for your reply Flex harUl.

  • How to keep HTML code in the applet source (.java) file itself?

    Hi,
    How to keep HTML code (APPLET tag) in the applet source (.java) file itself?
    Please give an example?
    thank you,

    R6i wrote:
    ...What I mean is without writing external HTML file, how to run an applet (during practice)?'Practice'? What does that mean? During development? If that is what you are referring to, add an applet tag at the top of YourApplet.java inside a Java comment area. Then AppletViewer (in recent SDKs) can then run it with just..
    prompt:javac YourApplet.java
    prompt:// the '.java' extension is not a mistake
    prompt:appletviewer YourApplet.javaIf you do not mean 'during development', then that brings us back to +"What advantages do you see that is bringing to the end user?".+

  • What is the best method to use for revealing the text on a jpg (as though the text is drawing itself?) Thanks.

    What is the best method to use for revealing the text on a jpg (as though the text is drawing itself?) Thanks.

    tacbob wrote:
    Are there any tutorials? I cannot find anything close.
    http://itunes.apple.com/de/podcast/write-on-effects-in-motion/id287113664?i=4883 4057
    The MacBreak Podcasts are an excellent source of info!
    Have a look on the others ..

  • How do you make a line appear to draw itself?

    I want to make a border appear to be "drawing itself" around
    a rounded rectangle on my site, how would I go about doing it? I'm
    sure it's easy but for the life of me I can't figure it out. Also,
    I want to have an X appear to draw itself on the site to cross out
    some text, how would I do this? (the X I want to use is a graphic,
    not a vector graphic).
    Thanks big time!

    xslamx wrote:
    > I want to make a border appear to be "drawing itself"
    around a rounded
    > rectangle on my site, how would I go about doing it? I'm
    sure it's easy but
    > for the life of me I can't figure it out. Also, I want
    to have an X appear to
    > draw itself on the site to cross out some text, how
    would I do this? (the X I
    > want to use is a graphic, not a vector graphic).
    http://www.mudbubble.com/db_tutorials/db_tut_write2.html
    Best Regards
    Urami
    !!!!!!! Merry Christmas !!!!!!!
    Happy New Year
    <urami>
    If you want to mail me - DO NOT LAUGH AT MY ADDRESS
    </urami>

  • Making a Drawing Draw itself

    Hi there,
    I'm new to Adobe Edge and wanted to know if anyone out there knows of a good tutorial or can tell me how to create a drawing that draws itself. I have a sketch that, when it loads, begins to draw itself until fully complete.
    Any help would be appreciated!

    Hi there,
      It sounds like you're looking to do a technique known as "masking". At this time, Edge Animate does not have masking functionality, but it is something that is being looked into for a future release. : )
      However, there are techniques that users have developed that provide a work around to achieve the effect you are looking for. Check out this thread below to see how to do the technique:
    http://forums.adobe.com/message/4720663
      At the bottom, the user aa_lique describes taking rectangles that are the same color as the background color and animating them to uncover the image behind them. I have also authored a tutorial that utilizes a similar technique to uncover a logo in a radial "wipe" looking effect:
    http://forums.adobe.com/docs/DOC-2536
    I hope this helps! Let me know if you need further clarification! If you'd like, I can make a sample project for you to show you how to do the masking workaround technique.

  • Forcing a canvas to draw off screen for printing.

    I have a process where I am trying to print a canvas that has not yet been shown.   So basically how do I force it to draw it's components without displaying it to the user.  If I add it to the print job it is blank.. If I first display it visually on the screen it is printed.  But only the visble portion is printed.. I have read up on printing and I understand why only the visble range is printed, but I would like to draw a custom sized canvas and then just print it..
    I have spent a couple of days on this and I feel like I am just missing something.
    I would like to do something like following:
    1.  Grab my canvas object
    2.  Set the height and width;
    3.  Instantiate the drawing routine.
    4.  Add it to the printJob.
    Thanks in advance.

    int() is always popular.

  • Custom component doesnt draw itself

    Hey
    Im relatively new to java, and especially to swing, heres the problem.
    Im trying to make a custom component (extends JComponent).Ive overwridden the paintComponent() method. But when i make a new component and add it to JPanel, it isnt drawn, although i can see that the paintComponent() method of the component is indeed invoked: heres the short code:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.event.MouseInputAdapter;
    import javax.swing.*;
    public class Test extends JFrame {
         static Test window;
         MouseOps mListener;
         JPanel drawingArea;
        public Test() {
              addWindowListener(new WindowAdapter() {
                  public void windowClosing(WindowEvent e) {
                   System.exit(0);
              drawingArea = new JPanel();
              drawingArea.setBackground(Color.white);
              getContentPane().add(drawingArea, BorderLayout.CENTER);
              mListener = new MouseOps();
              drawingArea.addMouseListener(mListener);
              drawingArea.addMouseMotionListener(mListener);
         class MouseOps extends MouseInputAdapter{
              public void mouseClicked(MouseEvent e) {
                   int x = e.getX();
                   int y = e.getY();
                   TestComp comp = new TestComp(x, y);
                   drawingArea.add(comp);
                   drawingArea.validate();
                   repaint();               
         public static void main(String[] args) {
              window = new Test();
              window.setTitle("Test");
              window.setSize(450, 260);
              window.setVisible(true);
    class TestComp extends JComponent {
         int x, y;
         TestComp(int x, int y){
              this.x = x;
              this.y = y;     
         public void paintComponent (Graphics g) {
              super.paintComponent(g);
              g.setColor(Color.blue);
              g.drawRect(x, y, 30, 30);
              System.out.println("Should be drawn at: " + x + " " + y);
    }

    Your component has zero size. The passed in graphics instance has its clip set
    to the components size, so you will never be able to draw anything.
    So you have two choices:
    * set the bounds of your component manually. To do this you will have to use
    a null LayoutManager: http://java.sun.com/docs/books/tutorial/uiswing/layout/index.html
    * or else do not use a separate component for each graphics object at all.
    Use a single container that overrides paintComponent() and iterates itself
    over the graphics objects and calls paint on them. Because the graphics
    objects are much more lightweight this approach scales better and is usually
    taken in graphics frameworks.
    Stephen

  • Forcing "headers" update before kernel itself [solved]

    Hello pals
    Is there some way that I could force pacman install first kernel headers before kernel "itself"?
    At this point I should install kernel, kernel-headers, and reinstall kernel to dkms compile it with nvidia driver
    Last edited by ilkyest (2014-05-15 02:19:03)

    thiagowfx wrote:
    clfarron4 wrote:When I asked Allan McCrae regarding the return of the SyncFirst option in /etc/pacman.conf, he said that it will not be happening.
    Hmmmm. Maybe one could easily do this with the future pacman hooks? A "SyncFirst"-like hook wouldn't do any harm...but I'm not sure about the difficulties of maintaining this.
    I think the dificulty is "analyse" each package to see what needs "be before" another

  • Applet won't repaint itself

    i have an applet that contains a jtexatrea 3 buttons and a jlabel.
    when i start it everuthing is just fine.
    however, my applet is supposed to open a file form the local filesystem (so it is signed) and after i click OK in the choose file dialog, my applet keeps the image of the dialog.
    what do i have to do in order to solve this ?
    p.s. and the same issue occurs when i minimiza the browswer and maximize it again. it just won't repaint.

    A potential solution occurred to me right after I posted, and I think it may be working. (Can't tell for sure until search engine cache's updated with this change.) Basically I expanded the .jar archive name:
    <script type='text/javascript'>
    <!--
    applet_fu.run(
      {'width':'850','height':'690'},
        'archive':'http://r0k.us/graphics/SIHwheel.jar',
        'code':'SIHwheel.class',
      '1.4.2',
      'Get Java for free at http://java.com/ '
    -->
    </script>Before the change, the archive line simply referenced 'SIHwheel.jar'.
    The one downside to this, assuming it works, is that I'll need two versions of the page. A local one on my hard drive for when I want to test before deploying, and the networked version with the full URL. That's a worthwhile trade-off, though.
    Edited by: RichF on Nov 27, 2010 10:39 AM
    PS: the link in first post still fails, but it seems to be accessing yesterday's version of the page (date on bottom). Also I note that the HTML for that Google-translated page and Bing's cache page contain:
    <base href=http://www.r0k.us/graphics/SIHwheel.html />That works well for accessing all the locally-referenced images on the page, but for some reason fails to find the .jar file without a complete URL. The [url http://r0k.us/graphics/applet-fu.js]applet-fu.js script does not appearing to be adorning the archive line in any way.

  • Force applet to reload

    ok, i have an applet running on a website, which is working fine. However, if i make a modification to the code, recompile and place the new class file on the website, without changing the name, then to get the applet to reload, i have to close all open browsers, open the java control panel, delete the class file from the java cache, open the browser again and reload the page, which is driving me nuts (only a short drive :) )
    is there an easier way? I tried using the cache_option = no idea, but with low confidence that i'm doing it right!!! here's the html code i've got at present...
    <HTML>
    <HEAD>
    </HEAD>
    <BODY BGCOLOR="000000">
    <CENTER>
    <APPLET
         code     = "FillRectTest.class"
         width     = "500"
         height     = "300"
         >
    <param name="cache_option" value="no">
    </APPLET>
    </CENTER>
    </BODY>
    </HTML>

    Is it possible that my applet is being cached somewhere inbetween the web server and my computer? After making a change to a class file on the server i delete all copies on my computer ( i did a search of the whole c drive for possible copies ) and reload the web page. But it still returns the old version of the applet!! is my internet service provider caching the class file after i load it say two times? this is driving me crazy... thanks for the disable cache idea, it would have worked quite neatly but for this other problem.

  • Need to force CD/DVD drawer open on G4 flat panel iMac

    Anybody know how to "force-open" the CD drawer on a flat panel iMac (G4 hemispherical base)? This one has a quirk - the eject button won't open the CD drawer until the OS has completely loaded. I just used software upgrade to update some apps and on restart, all I get is the spinning gear. I need to startup from the system CD, but I can't get the drawer open to insert it. Any ideas?

    Hello and Welcome to Apple
    Discussions. 
    You'll have to use the Open
    Firmware method that a brody links to in his post
    above.
    The manual button to open the drive is
    hidden on the iMac G4 and so not an option.
    mrtotes
    Since I'm getting a blank blue screen, Open Firmware is not an option. Any other ideas?

  • Multithreaded graphics applet gets NullPointerException

    Hi!
    This is a complex issue and the code's big, so i'll try
    to explain the main part.
    I have five classes.
    AppletClass (this one extends Applet)
    GraphicItem (just a little sprite which can draw itself)
    Thread1 (draws a bunch of GraphicItems in background on a Graphics which is set by setg() in this class)
    Thread2 (draw a random clolor text line in background
    on a Graphics which is set by setg() in this class)
    Drawer (a thread that draws an image set in
    the constructor ona graphics which is set by setg() in this class)
    What is it for: Well, this is a dubble buffering example,
    where two threads draw into one image which works
    as a buffer and then another thread draw that image
    into the applet area.
    The problem is that when Thread1 in run() calls
    gitem.draw(g) where g is Graphics i sometimes
    get NullPointerException, also, it happenes in some
    other place but i cannot pinpoint it. Also,it happenes
    always when i restart applet w/o reloading in
    JBuilder (nor the browser).
    The thing is that i do not use synchronized or
    imageUpdate() in the Drawer (imageUpdates() does
    nothing), so it is possible for two or more object to
    have access to the same Graphics object at the same
    time. Also, while Drawer draws the image, the other
    thread are drawing onto the image. So, there might
    be a conflict, i think. The other other is that when
    i comment out all Thread.sleep() the image get
    clobbered. That is, the GraphicItem is a cross of
    random color, so i shoudl see thousands of crosses of
    random color, but i thousands of crosses of pretty
    much the same color as it seems like Random is not
    working or drawing is broken.
    Anyway, any idea how to properly implement such
    thing? What precautions shoudl i take and which
    conflicts and how should i resolve?
    And, of course, in what cases NullPointerException is
    generated? I mean, what exxctly does it mean and
    when usually occurs?
    PS: Don't you think it is weird to get such
    exception in a language which officially
    has no pointers? :)

    Why it SOUNDS like is the Image you are drawing may not be completly loaded yet.. so the first few times it's blitted ( and possibly if it gets bumped out of memory ) attempting to draw it will throw a null pointer.
    I solved that in my own code by using a MediaTracker on the image when it was created to make sure that it is loaded and ready to be draw immediatly.

  • Centering text with drawString() in applet

    I want to draw a String in the center of my applet, is there a way to tell it to draw itself centered, or is there a way to find the width of the string to position it absolutely? Which would be easier? Thanks.

    You can use the graphics' font metrics (especially the stringWidth (String) method).
    Kind regards,
      Levi

  • Trying to create myRect class then draw giving problems

    Please help me I am Intro Java Student.
    Thanks
    My Rect class looks like following:
    import java.awt.*;
    import javax.swing.*;
    public class MyRect extends Object{
    private int x1=0,y1=0,w=0,h=0; // Coordinates of the Point
    /* No-arguments Constructor
    public MyRect()
    setMyRect(0,0,0,0);
    // Set x1,x2,y1,y2 Coordinates for the Rect
    public void MyRect (int a, int b, int c, int d)
    x1 = a;
    y1 = b;
    w = c;
    h = d;
    System.out.println("Values" + a b c +d);
    // get Coordinates
    public int getX1()
    return x1;
    public int getY1()
    return y1;
    public int getW()
    return w;
    public int getH()
    return h;
    public static void main(String arguments[]) {
    MyRect rect = new MyRect();
    Then created TestDraw.java
    import java.awt.*;
    import javax.swing.*;
    public class TestDraw extends JApplet {
    private MyLine line[]; // Array of line objects (ADT)
    private MyOval oval[]; // Array of oval objects (ADT)
    private MyRect rect[]; // Array of rectangle objects (ADT)
    public void initDraw() // Routine to intialize applet GUI
    line = new MyLine[ 5 ];
    line[ 0 ] = new MyLine( 100, 100, 200, 200 );
    line[ 1 ] = new MyLine( 200, 200, 100, 100 );
    line[ 2 ] = new MyLine( 300, 300, 100, 100 );
    line[ 3 ] = new MyLine( 400, 400, 0, 0 );
    line[ 4 ] = new MyLine( 100, 100, 300, 300 );
    oval = new MyOval[ 5 ];
    oval[ 0 ] = new MyOval( 100, 100, 200, 200 );
    oval[ 1 ] = new MyOval( 200, 200, 100, 100 );
    oval[ 2 ] = new MyOval( 300, 300, 100, 100 );
    oval[ 3 ] = new MyOval( 400, 400, 30, 200 );
    oval[ 4 ] = new MyOval( 100, 100, 300, 300 );
    rect = new MyRect[ 5 ];
    rect[ 0 ] = new MyRect( 100, 100, 200, 200 );
    rect[ 1 ] = new MyRect( 200, 200, 100, 100 );
    rect[ 2 ] = new MyRect( 300, 300, 100, 100 );
    rect[ 3 ] = new MyRect( 400, 400, 30, 200 );
    rect[ 4 ] = new MyRect( 100, 100, 300, 300 );
    // paint method called to draw applet GUI to the display
    public void paint( Graphics g )
    initDraw(); // Initialize line,oval, and rectangle objects
    // Ask each line object to draw itself
    for ( int i = 0; i < line.length; i++ )
         line[ i ].draw( g );
    // Ask each oval object to draw itself
    for ( int i = 0; i < oval.length; i++ )
         oval[ i ].draw( g );
    // Ask each rectangle object to draw itself
    for ( int i = 0; i < rect.length; i++ )
         rect[ i ].draw( g );
    It fails giving following error:
    TestDraw.java:32:cannot resolve symbol
    Symbol:class MyRect
    location:class TestDraw
    rect[4]=new MyRect<100,100,300,300>;

    I think your program is having trouble using MyRect as it is defined in an external file and it doesn't know where to get MyRect from.
    Try putting something in the following form in the first line of MyRect.java
    package <path>.<path>;
    Where <path> is a directory from you classpath which contains the classes you wish to access, that being MyRect in this case (this must be in this path of course).
    So if you classpath was c:/jdk1.3.1/ and your file to reference is in c:/jdk1.3.1/classes/myclasses you would use in MyRect.java:
    package classes.myclasses;
    Then in TestDraw.java you can import your package using:
    import classes.myclasses.*;
    Which will give you access to classes methods within the myclasses directory. Try this out and if it doesn't work send me the files in email and I'll try and look at them at home.
    Mark.

Maybe you are looking for

  • Access denied for folder when permissions set with WMI

    Hi, When I add/modify access rights based on the Win32_ACE class, there seems to be a difference in the result, then when setting it with the GUI in Windows. The situation is as follow: I want to set Modify access on a remote folder, but also want to

  • Unit conversion (days to hours)

    Hello, I have got a question concerning unit conversion in integrated planning. I created a key figure called "workload" and asigned the UnitInfoObject "0unit". Two input-ready queries are available in order to plan the workload in two different unit

  • Globaldevices file system

    Hi Solaris Cluster 3.3 u2 on Solaris 10 x86. I have dedicated slice for global device file system. During the cluster creation, i have not chosen the default method which is lofi method. For node "node1",     Is it okay to use this default (yes/no) [

  • How long after purchase can you get a free upgrade?

    For example if someone bought eLearning Suite 2.5 in June could they get a free upgrade to eLearning Suite 6?

  • Which video cameras directly record ProRes?

    I've gotten very used to recording directly to ProRes while tethered. I'd like to find a CCD (to avoid rolling shutter) camera that records ProRes 422 directly at 1920 x 1080, and is not interpolated up from some lesser resolution sensors. Or, is the