Я пытаюсь печатать символы один за другим на анимированном баннере, но я не могу получить желаемый результат.Печатать строковый символ один за другим с помощью потоков
Я получаю результат с помощью своего кода, но не с тем, который я ищу. Я получаю баннер и результат персонажей.
Но эти символы перекрывают друг друга.
Пожалуйста, проверьте ниже кода
import java.awt.*;
import java.io.*;
//Banner class
class Banner extends Frame implements Runnable
{
boolean stop=false;
String str="Sreedhar Practice seassion";
//constructor
public Banner()
{
setLayout(null);
setBackground(Color.cyan);
setForeground(Color.blue);
}//end of constructor
//image paint settings methosd
public void paint(Graphics g)
{
Font f=new Font("Courier",Font.BOLD,40);
g.setFont(f);
for (int i=0;i<=str.length() ;i++)
{
char ch=str.charAt(i);
String c=String.valueOf(ch);
g.drawString("\t"+c,10,100);
try
{
Thread.sleep(100);
}
catch (InterruptedException ie)
{
}
//char ch=str.carAt(0);
//str=str.substring(1,str.length());
//str=str+ch;
if (stop)
{
return;
}
}
}//image paint settings methosd end
//start of run method
public void run()
{
if (stop)
{
return;
}
}
}//end of run method
//main method starting
public static void main(String[] args)throws IOException
{
Banner b=new Banner();
b.setSize(400,400);
b.setTitle("Sreedhar Banner");
b.setVisible(true);
Thread t=new Thread(b);
t.start();
System.in.read();
b.stop=true;
}//end of main method
}//end of class Banner
Это мой код, но я не получает желаемый результат, что я хочу.
@Pointy, спасибо за редактирование – sreeku24