package src;

import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.*;

public class Applet extends JApplet
{
	public static final String BOARD_FILE = "./src/mon.jpg";
	public static final String CAR = "./src/car.png";
	public static final int OFFSET_X = 10;
	public static final int OFFSET_Y = 10;
	private Point  [] coordArray;
	
	BufferedImage boardImage;
	BufferedImage carImage;
	
	
	public void init()
	{
		boardImage = getImage(BOARD_FILE);
		carImage = getImage(CAR);
		
	}
	
	@Override
	public void paint(Graphics g)
	{
	    
		int imgScale;
		
		super.paint(g);
		
		 
		
		if((getWidth() - 130) < getHeight())
			imgScale = getWidth() - 150;
		else
			imgScale = getHeight() - 20;
		
		coordArray = getPoints(imgScale);
		
		g.drawImage(boardImage, OFFSET_X, OFFSET_Y, imgScale, imgScale, null);
		//g.drawImage(carImage, OFFSET_X, OFFSET_Y, null);
		
		for(Point p: coordArray)
		{
		    g.drawImage(carImage, p.x, p.y,imgScale/20,imgScale/20 , null);
		}
		
	}
	
	private Point[] getPoints(int imageScale)
	{
	    Point [] tempCoord;
	    double divFactor;
	 
	    
	    tempCoord = new Point[40];
	    divFactor = (imageScale/10) * (0.825);
	    
	    
	    for(int i = 0; i < 11 ;i++)
	    {
	        tempCoord[i] = new Point( (int) (imageScale-divFactor*i -divFactor*1.5),(int) (imageScale-divFactor));
	    }
	    
	    for (int i = 11; i < 21; i++)
	    {
	        tempCoord[i] = new Point((int) divFactor/2,(int) (imageScale-divFactor*(i-10)-divFactor*1.5));
        }
	    
	    for (int i = 21; i < 31; i++)
        {
            tempCoord[i] = new Point((int) (divFactor*(i-20) +divFactor*1),(int) (divFactor/2));
        }
	    
	    for (int i = 31; i < 40; i++)
        {
            tempCoord[i] = new Point((int) (imageScale-divFactor),(int) (divFactor*(i-30)+divFactor*.9));
        }
	    
	    System.out.println("****************"+imageScale+"*******************************");
	    for(Point p: tempCoord)
	    {
	        p.x = p.x + OFFSET_X;
	        p.y = p.y + OFFSET_Y;
	        
	         
	        System.out.println((p.x) + " " + p.y);
	    }
	    System.out.println();
	    
	    
        return tempCoord;
	}
	
	public BufferedImage getImage(String fileName)
	{
		BufferedImage img;
		
		img = null;
		try 
		{
			img = ImageIO.read(new File(fileName));
		} 
		catch (IOException e)
		{
		}
		
		return img;
	}
}

@@ -26,16 +26,158 @@
 .awt.*;%0A
+import java.awt.event.ActionEvent;%0Aimport java.awt.event.ActionListener;%0Aimport java.awt.event.ItemEvent;%0Aimport java.awt.event.ItemListener;%0A
 import j
@@ -205,16 +205,16 @@
 dImage;%0A
-
 import j
@@ -343,16 +343,56 @@
  JApplet
+ implements ActionListener, ItemListener
 %0A%7B%0A%09publ
@@ -662,16 +662,61 @@
 mage;%0A%09%0A
+%09//JComponents%0A%09private JButton diceRoll; %0A%09%0A
 %09%0A%09publi
@@ -769,16 +769,16 @@
 _FILE);%0A
-
 %09%09carIma
@@ -797,16 +797,64 @@
 e(CAR);%0A
+%09%0A%09%09%0A%09%09diceRoll = new JButton(%22Roll Dice!%22);%0A%09%09%0A
 %09%09%0A%09%7D%0A%09%0A
@@ -2721,11 +2721,262 @@
  img;%0A%09%7D
+%0A%0A    @Override%0A    public void itemStateChanged(ItemEvent e)%0A    %7B%0A        // TODO Auto-generated method stub%0A        %0A    %7D%0A%0A    @Override%0A    public void actionPerformed(ActionEvent e)%0A    %7B%0A        // TODO Auto-generated method stub%0A        %0A    %7D
 %0A%7D%0A

Save Applet