java程序编译的时候显示Greating不是抽象的且未覆盖Runnable中的run(),大神帮我找一下错在哪 30
importjava.awt.*;importjavax.swing.*;importjava.util.*;publicclassGreetingextendsJFra...
import java.awt.*;
import javax.swing.*;
import java.util.*;
public class Greeting extends JFrame implements Runnable
{
Thread t1, t2;
int x1=0,x2=0;
public Greeting()
{
t1 = new Thread(this);
t2 = new Thread(this);
t1.start();
t2.start();
}
public void paint(Graphics g)
{
super.paint( g );
g.fillRect(0,50,30,30);
g.fillRect(0,80,30,30);
}
public void run(Graphics g)
{
super.paint( g );
try
{
while(true)
{
if(Thread.currentThread()==t1)
{
g.fillRect(x1++,50,30,30);
Thread.sleep(1000);
repaint();
}
else if(Thread.currentThread()==t2)
{
g.fillRect(x2++,80,30,30);
Thread.sleep(1000);
repaint();
}
}
}
catch(InterruptedException e){}
}
public static void main(String args[])
{
Greeting gre = new Greeting();
}
} 展开
import javax.swing.*;
import java.util.*;
public class Greeting extends JFrame implements Runnable
{
Thread t1, t2;
int x1=0,x2=0;
public Greeting()
{
t1 = new Thread(this);
t2 = new Thread(this);
t1.start();
t2.start();
}
public void paint(Graphics g)
{
super.paint( g );
g.fillRect(0,50,30,30);
g.fillRect(0,80,30,30);
}
public void run(Graphics g)
{
super.paint( g );
try
{
while(true)
{
if(Thread.currentThread()==t1)
{
g.fillRect(x1++,50,30,30);
Thread.sleep(1000);
repaint();
}
else if(Thread.currentThread()==t2)
{
g.fillRect(x2++,80,30,30);
Thread.sleep(1000);
repaint();
}
}
}
catch(InterruptedException e){}
}
public static void main(String args[])
{
Greeting gre = new Greeting();
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询