Solved

Progress bar with a TextField (JDK 1.0.2)

Posted on 1998-12-14
1
275 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

688 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