Solved

Progress bar with a TextField (JDK 1.0.2)

Posted on 1998-12-14
1
249 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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This video teaches viewers about errors in exception handling.

757 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now