Task 1 ....................................Complete Task 2 ....................................Complete
For some reason, it writes the strings and periods first, THEN outputs the image, and then writes the strings again...Any ideas why?
import javax.swing.JApplet;
import java.awt.*;
import java.applet.*;
public class myApplet extends JApplet
{
Image image;
public void init()
{
getContentPane().setBackground( Color.black );
image = getImage(getCodeBase(), "picture.jpg");
}
public void paint (Graphics g)
{
super.paint(g);
int column=180;
int doneposition=350;
g.drawImage(image,170,10,this);
WaitNmilliseconds(2000);
Font font = new Font("Arial",Font.PLAIN,20);
g.setFont(font);
String message;
g.setColor(Color.white);
WaitNmilliseconds(2000);
g.drawString ("Task1", 5, 380);
PeriodBar(g,column, 380);
g.drawString ("Complete.", 700, 380);
WaitNmilliseconds(2000);
g.drawString ("Task2", 5, 410);
PeriodBar(g, column, 410);
g.drawString ("Complete.", 700, 410);
}
void PeriodBar(Graphics g, int columnnum, int row)
{
for(int i = 0; i<=34; i++)
{
g.drawString(".", columnnum, row);
columnnum=columnnum+15;
WaitNmilliseconds(300);
}
}
void WaitNmilliseconds(int n)
{
try
{
// Sleep at least n milliseconds.
// 1 millisecond = 1/1000 of a second.
Thread.sleep( 300 );
}
catch ( InterruptedException e )
{
System.out.println( "awakened prematurely" );
}
}
}

New Topic/Question
Reply



MultiQuote








|