[img][/img]
почему у второй рокетки отображается черный квадрат?
Код
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.awt.event.ActionListener;
import java.util.List;
import java.util.Random;
import javax.swing.*;
public class lab extends JFrame implements
KeyListener, MouseMotionListener
{
Random o=new Random();
JLabel lab=new JLabel("");
JLabel lab2=new JLabel("");
JLabel lab12=new JLabel("");
int count=0,count2=0;
JLabel lab3=new JLabel(count+":"+count2);
JLabel bool1=new JLabel("");
JLabel fon1=new JLabel("");
JPanel pan=new JPanel();
int x=bool1.getX(),y=bool1.getY(),ea=1,r=0;
Icon up=new ImageIcon("рокетка2_и_мяч.gif");
Icon g=new ImageIcon("рокетка1.gif");
Icon left=new ImageIcon("рокетка1_и_мяч.gif");
Icon bool=new ImageIcon("мяч.gif");
ImageIcon fon=new ImageIcon("фон.gif");
Icon g1=new ImageIcon("рокетка2_право.gif");
Icon g2=new ImageIcon("рокетка2_лево.gif");
Timer right=new Timer(1, new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
bool1.setIcon(bool);
switch(ea)
{
case 1:
x++;
y--;
if (x>=775)
ea=2;
if (y<=0)
{count+=1;
right.stop();
bool1.setIcon(null);
r=1;
}
if (((x+50>=lab.getX())&&(x<=lab.getX()+100) && (y<=lab.getY()+30)))
ea=3;
break;
case 2:
x--;
y--;
if (((x+50>=lab.getX())&&(x<=lab.getX()+50) && (y<=lab.getY()+30)))
ea=3;
if (y<=0)
{count+=1;
right.stop();
bool1.setIcon(null);
r=1;}
if (x<=0)
ea=1;
break;
case 3:
x--;
y++;
if (x<=0)
{ea=4;
}
if (y+50>761)
bool1.setIcon(null);
if (((x+50>=lab2.getX())&&(x<=lab2.getX()+50)) && (y+50>=lab2.getY()+30))
ea=2;
if (x<0)
ea=4;
if (y>=761)
r=2;
break;
case 4:
x++;
y++;
if (((x>=lab2.getX())&&(x<=lab2.getX()+100)) && (y+50>=lab2.getY()+30))
ea=1;
if (y+50>=761)
{right.stop();
count2+=1;
bool1.setIcon(null);}
if (x>761)
{ea=3;
r=2;}
break;
}
lab3.setText(count+":"+count2);
bool1.setLocation(x,y);
}
});
public lab()
{
super("ping-pong");
setSize(800,800);
pan.setLayout(null);
setContentPane(pan);
pan.setSize(900,800);
pan.add(bool1);
pan.add(lab);
lab.setSize(100,100);
lab.setLocation(0,0);
lab.addKeyListener(this);
lab.setFocusable(true);
lab.setIcon(g);
pan.add(lab2);
lab2.setSize(100,30);
lab2.setLocation(0,700);
lab2.addKeyListener(this);
lab2.setFocusable(true);
lab2.setIcon(g1);
pan.add(fon1);
fon1.setSize(800,800);
fon1.setLocation(0,0);
fon1.setIcon(fon);
pan.add(lab12);
lab12.setSize(100,30);
lab12.setLocation(lab2.getX()+50,lab2.getY());
lab12.setIcon(g2);
pan.add(lab3);
lab3.setSize(200,30);
lab3.setLocation(40,0);
lab3.addKeyListener(this);
pan.addMouseMotionListener(this);
}
public void keyPressed(KeyEvent a) {
switch(a.getKeyCode())
{
case KeyEvent.VK_A:
lab.setLocation(lab.getX()-20, lab.getY());
if ((lab.getX()+100)<0)
lab.setLocation(lab.getX()+900, lab.getY());
break;
case KeyEvent.VK_D:
lab.setLocation(lab.getX()+20, lab.getY());
if (lab.getX()>800)
lab.setLocation(lab.getX()-900, lab.getY());
break;
case KeyEvent.VK_S:
Random ran=new Random();
int it=ran.nextInt(2)+1;
if (r==0)
{x=lab2.getX();
y=lab2.getY();}
else
if (r==1)
{x=lab2.getX();
y=lab2.getY();}
else
if (r==2)
{x=lab2.getX();
y=lab2.getY();}
right.start();
int ea=o.nextInt(2)+1;
bool1.setSize(50,50);
bool1.setIcon(bool);
bool1.setLocation(x,y);
break;
}
}
@Override
public void keyReleased(KeyEvent b) {
// TODO Auto-generated method stub
}
@Override
public void keyTyped(KeyEvent c) {
// TODO Auto-generated method stub
}
@Override
public void mouseDragged(MouseEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void mouseMoved(MouseEvent r) {
lab2.setLocation(r.getX(),680);
lab12.setLocation(lab2.getX(),lab2.getY());
}
}