| Welcome to Webforumz.com. |
|
Apr 20th, 2007, 22:59
|
#1 (permalink)
|
Join Date: Jul 2006
Location: Devon, England
Posts: 567
|
Help need with 2 progress bars
I need to make an applet that has 2 progress bars.
The top progress bar needs to move twice as fast as the bottom progress bar.
I have got the top progress bar to work but no matter what I try, I can't get the second progress bar to move slower than the first one. I can get them to move at the same time which is no good.
Does anyone know how I can do this? I did try using a nested loop but I think I messed it up. Any help would be very much appreciated.
I know this code isn't perfect but it's the only example that i was able to work from.
- Code: Select all
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
public class Progress1 extends Applet implements Runnable
{
Thread runner;
myCanvas ca = new myCanvas();
Choice ch = new Choice();
Label la;
Button a;
TextField tf;
int xpos;
int BarHeight = 30;
int TopBarWidth = 2;
int BottomBarWidth = 1;
public void init()
{
setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
ch.addItem("IEEE 802.11a");
ch.addItem("IEEE 802.11b");
ch.addItem("IEEE 802.11g");
ch.addItem("IEEE 802.11n");
ch.addItem("IHomeRF");
c.gridx = 0;
c.gridy = 0;
add(ch, c);
la = new Label("Enter amount of data (Mbits) to be transferred");
c.gridwidth = 2;
c.gridx = 1;
c.gridy = 0;
add(la, c);
tf = new TextField("",12);
c.gridwidth = 2;
c.gridx = 1;
c.gridy = 2;
add(tf, c);
a = new Button("Transfer");
c.gridx = 3;
c.gridy = 2;
add(a, c);
ca.setBackground(Color.white);
ca.resize(400,150);
c.gridwidth = 4;
c.gridx = 0;
c.gridy = 3;
add(ca,c);
start();
}
public void start()
{
if(runner==null)
{
runner= new Thread(this);
runner.start();
}
repaint();
}
public void run()
{
}
public class myCanvas extends Canvas
{
public void paint(Graphics g)
{
g.setColor(Color.black);
g.drawString("Theoretical Transfer Speed",0,25);
g.drawString("Realistic Transfer Speed",0,85);
g.setColor(Color.red);
g.drawRect (0, 30, 370, 30);
g.fillRect (1, 31, 369, 29);
g.drawRect (0, 90, 370, 30);
g.fillRect (1, 91, 369, 29);
for(xpos=1; xpos<=369; xpos+=1)
{
g.setColor(Color.green);
g.fillRect(xpos-1,31,BottomBarWidth,BarHeight);
g.fillRect(xpos,31,BottomBarWidth,BarHeight);
g.setColor(Color.black);
g.drawString("Theoretical Transfer Speed",0,25);
g.drawRect (0, 30, 370, 30);
g.drawString("Realistic Transfer Speed",0,85);
g.drawRect (0, 90, 370, 30);
try
{
Thread.sleep(100);
}
catch (InterruptedException e)
{
}
}
}
}
}
|
|
|
| Thread Tools |
|
|
| Rate This Thread |
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|