Solved

Progress bar with a TextField (JDK 1.0.2)

Posted on 1998-12-14
1
256 Views
Last Modified: 2012-06-21
Hi, right now I'm trying to build a simple Progress bar using a TextField (with JDK 1.0.2), it can fill well, but I don't know how to drain the StringBuffer content for refill it. This is what I have:

import java.awt.*;
import java.lang.*;
import java.util.*;
import java.applet.*;
import java.io.*;

public class miBarraProg2 extends java.applet.Applet {
  TextField progreso;
  Button inicio;
  Label porcen1;
  Label porcen2;
 
  StringBuffer llena;
  String llena2;
  String agrega;
 
  public void init() {
    llena = new StringBuffer(40);
    llena2 = "";
    agrega = "|";
   
    progreso = new TextField(8);
    progreso.setEditable(false);
    inicio = new Button("Start the progress!");
    porcen1 = new Label("0% ");
    porcen2 = new Label("100%");
    add(porcen1);
    add(progreso);
    add(porcen2);
    add(inicio);
  }
 
  public boolean action (Event evt, Object what) {
    Object target=evt.target;
        if(target == inicio) {
        progreso.setText("");
       
        llena2 = "";
        //How do I drain the content of the StringBuffer?
       
         for (int x=1; x<30; x++) {
          llena2 = llena.append(agrega).toString();
          progreso.setText(llena2);
          for (int y=1; y<200; y++) {}  //a delay
         }
       return true;
       }
   return false;
  }  

}

Could somebody help me?. Thanks.

  Deladier.
0
Comment
Question by:Deladier
1 Comment
 
LVL 1

Accepted Solution

by:
Hans_Klose earned 100 total points
ID: 1229506
public class miBarraProg2 extends java.applet.Applet
{
  TextField progreso;
  Button inicio;
  Label porcen1;
  Label porcen2;
   
  StringBuffer llena;
  String llena2;
  String agrega;
   
  public void init()
  {
    llena = new StringBuffer(40); // ? Why did you make it 40  
    llena2 = "";
    agrega = "|";
     
    progreso = new TextField(8);
    progreso.setEditable(false);
    inicio = new Button("Start the progress!");
    porcen1 = new Label("0% ");
    porcen2 = new Label("100%");
    add(porcen1);
    add(progreso);
    add(porcen2);
    add(inicio);
  }
   
  public boolean action (Event evt, Object what)
  {
    Object target=evt.target;
        if(target == inicio)
        {
           
                progreso.setText("");
         
                llena2 = "";
                //How do I drain the content of the StringBuffer?
         
                for (int x=1; x<30; x++)
                {
                    llena2 = llena.append(agrega).toString();
                    progreso.setText(llena2);
         
                    for (int y=1; y<900; y++) {}  //a delay
                }
           
           
            //  Here is a quick hack of what I think you could do.
            //  1. Start with a full buffer at the last position
            //  2. while you are above or equal to 0 change the char at x to space
            // Just be carefull with your indexes since you start at 1.
           
         
                System.out.println("Length of a buffer "+llena.length());
                for(int x= 28 ; x >= 0; x--)
                {
                    System.out.println("Here is x" + new Integer(x).toString() );
                   
                    llena.setCharAt(x,' ');
                    llena2 = llena.toString();
                    progreso.setText(llena2);
         
                    for (int y=1; y<900; y++) {}  //a delay    
                }
   
                return true;
               
    }
   return false;
 
  }
}

// I hope this works with 1.0.2 I have 1.2 but I attempted to make only the 1.0.2 api calls
0

Featured Post

ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
groupSum6 challenge 6 86
eclipse package explorer vs project explorer view 2 132
couple of eclipse 5 36
sql import cannot be resolved jsp 3 22
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
The viewer will learn how to implement Singleton Design Pattern in Java.
This video teaches viewers about errors in exception handling.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question