[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Progress bar with a TextField (JDK 1.0.2)

Posted on 1998-12-14
1
Medium Priority
?
287 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 400 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
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 will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Suggested Courses

649 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