How move icon in buttone in This programe ?
i need move train in road
how i need code code bleaz
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class MoveCar4 extends JFrame implements ActionListener
{
JPanel screen, area , controlroom ;
JButton[] street , keybord;
String s[] = {"Start","Stop","Fast","Slow" ,"Rest","Check"};
String img[] = {"images/UpRight.jpg","images/RightDown.jpg","images/Vert.jpg","images/DownRight.jpg","images/Horiz.jpg",
"images/TrainDown.jpg","images/RightUp.jpg"};
String notrack[] = {"images/NoTrack.jpg"};
ImageIcon icon;
JLabel labelInfo;
Color colors[] =
{Color.red , Color.blue ,Color.green ,Color.yellow ,
Color.white , Color.lightGray };
public MoveCar4 ()
{
screen = new JPanel(new GridLayout(1,1));
Font f =new Font ("Sanserif",Font.BOLD,18);
labelInfo = new JLabel("WELCOM" ,JLabel.CENTER);
labelInfo.setFont(f);
for (int i =0; i<6; i++ )
screen.setBackground(Color.red);
screen.add(labelInfo);
getContentPane().add(BorderLayout.NORTH,screen );
street = new JButton[25];
area = new JPanel (new GridLayout(5,5));
for (int i=0; i<25; i++ )
{
if (i== 0 )
{
icon = new ImageIcon(img[0]);
street = new JButton("", icon);
}
else if(i== 1 )
{
icon = new ImageIcon(img[1]);
street = new JButton("", icon);
}
else if(i== 5 )
{
icon = new ImageIcon(img[2]);
street = new JButton("", icon);
}
else if(i== 6 )
{
icon = new ImageIcon(img[3]);
street = new JButton("", icon);
}
else if(i== 7 )
{
icon = new ImageIcon(img[4]);
street = new JButton("", icon);
}
else if(i== 8 )
{
icon = new ImageIcon(img[1]);
street = new JButton("", icon);
}
else if(i== 10 )
{
icon = new ImageIcon(img[2]);
street = new JButton("", icon);
}
else if(i== 13 )
{
icon = new ImageIcon(img[5]);
street = new JButton("", icon);
}
else if(i== 15 )
{
icon = new ImageIcon(img[2]);
street = new JButton("", icon);
}
else if(i== 16 )
{
icon = new ImageIcon(img[0]);
street = new JButton("", icon);
}
else if(i== 17 )
{
icon = new ImageIcon(img[4]);
street = new JButton("", icon);
}
else if(i== 18 )
{
icon = new ImageIcon(img[6]);
street = new JButton("", icon);
}
else if(i== 20 )
{
icon = new ImageIcon(img[3]);
street = new JButton("", icon);
}
else if(i== 21 )
{
icon = new ImageIcon(img[6]);
street = new JButton("", icon);
}
else
icon = new ImageIcon(notrack[0]);
street= new JButton("",icon);
street.addActionListener(this);
area.add(street);
}
getContentPane().add(BorderLayout.CENTER,area );
keybord = new JButton[6];
controlroom = new JPanel(new GridLayout(3,3));
for (int i=0; i <6; i++)
{
keybord = new JButton(s);
keybord.addActionListener(this);
controlroom.add(keybord);
}
getContentPane().add(BorderLayout.SOUTH,controlroom );
}
public void actionPerformed(ActionEvent e)
{
for (int i=0; i<25; i++ )
{
if (e.getSource() == street )
{
System.out.println(i+" ");
}
else if (i<6)
{
if(e.getSource() == keybord )
labelInfo.setText(s);
}
}
}
}
and this Test code
import java.awt.event.*;
public class TestMoveCar4
{
public static void main(String[] args)
{
MoveCar4 c= new MoveCar4 ();
c.setTitle("Car");
c.setSize(421,550);
c.setVisible(true);
c.addWindowListener (
new WindowAdapter ()
{
public void
windowClosing(WindowEvent e )
{ System.exit(0); }
} );
}
}
this folder foto
Download file
http://www.4shared.com/file/13555551/ff070bf/images.html
blez i dont more learnng in java :)
Thanks

