Education Menu


Features Menu


Additional Menu


Now Online

We have 125 guests online



Follow US

Twitter You Tube Google Plus
Pinterest Facebook EduLanka Blog


Information Zone

eduLanka Sinhala

Welcome to eduLanka.LK, Largest online education web site in Sri Lanka & most popular educational web site among Sri Lankan students. EduLanka, Best nonprofit & educational website is provided large numbers of online lessons, education related course information, teachers information, E books, examination result alerts, goverment job alerts, tuition class information, career guide for school leavers and more resources related to education in Sri Lanka. Edulanka provides education related resources from primary education, O-Level & A-Level education, University & Postgraduate education and vocational training education.

EduLanka IDN Domains http://එඩියුලංකා.ලංකා http://எடியுலங்கா.இலங்கை

jobs Mathematics SLAS Exam Dharma Education Results


Inside Online School

Share Us

Home Page Information Technology Java Programing (ජාවා වැඩසටහන්කරණය)

Race Track and Latest Java Applet Codes
Wednesday, 09 March 2011 20:17


Java Applet Sample codes and graphical interface example

Java sample codes and jave swing applets sample codes. Java Swing applet graphics display create oval, line and graphical options Java Swing applet clock buttons and all swing applet component containing example.

import javax.swing.*;
import java.awt.geom.*;
import java.awt.*;
public class RaceTrack extends JFrame
private RaceTrackPanel animation;
private JLabel betLabel, potLabel, bankLabel, carLabel;
private JTextField betField, carField, potField, bankField, winnerField;
private JButton goButton;
private JPanel p;
public RaceTrack( )
mage Track = new ImageIcon("Track.gif").getImage();
Image Car1 = new ImageIcon("Redcar.gif").getImage();
Image Car2 = new ImageIcon("Bluecar.gif").getImage();
animation = new RaceTrackPanel(this, Track, Car1, Car2);
Container c = getContentPane();
c.setLayout(new BorderLayout( ));
p = new JPanel( );
GridBagLayout grid = new GridBagLayout();
betLabel = new JLabel("Enter Bet");
carLabel = new JLabel("Choose Car");
potLabel = new JLabel("Pot");
bankLabel = new JLabel("Bank");
betField = new JTextField(5);
carField = new JTextField(2);
potField = new JTextField(5);
bankField = new JTextField(7);
winnerField = new JTextField(20);
goButton = new JButton("Start Race");
GridBagConstraints gbc = new GridBagConstraints( );
gbc.fill = GridBagConstraints.BOTH;
gbc.insets = new Insets(5,5,5,5);
gbc.fill = GridBagConstraints.NONE;
gbc.anchor = GridBagConstraints.EAST;
gbc.anchor = GridBagConstraints.WEST;
gbc.anchor = GridBagConstraints.EAST;
gbc.anchor = GridBagConstraints.WEST;
gbc.anchor = GridBagConstraints.EAST;
gbc.anchor = GridBagConstraints.WEST;
gbc.anchor = GridBagConstraints.EAST;
gbc.anchor = GridBagConstraints.WEST;
gbc.anchor = GridBagConstraints.WEST;
c.add("Center", animation);
c.add("South", p);
private void gblAdd(Component c, GridBagLayout
grid,GridBagConstraints gbc, int x, int y, int w, int h)
gbc.gridx = x;
gbc.gridy = y;
gbc.gridwidth = w;
gbc.gridheight = h;
public static void main(String[] args)
JFrame f = new RaceTrack( );
f.setSize(700, 400);;
class RaceTrackPanel extends JPanel
RaceTrack holder;
Image Track, Car1, Car2;
int Xpos, Ypos;
public RaceTrackPanel(RaceTrack app, Image Track,
Image Car1, Image Car2)
his.Track = Track;
this.Car1 = Car1;
this.Car2 = Car2;
holder = app;
Xpos = 30;
Ypos = 30;
public void paintComponent(Graphics g)
int w;
int h;
w = Track.getWidth(this);
h = Track.getHeight(this);
if ((w>0) && (h>0))
g.drawImage(Track, Xpos, Ypos, this);
w = Car1.getWidth(this);
h = Car2.getHeight(this);
if ((w>0) && (h>0))
g.drawImage(Car1, Xpos, Ypos +25, this);
g.drawImage(Car2, Ypos, Ypos +130, this);

Download Sample Program codes from here:


Last Updated on Wednesday, 09 March 2011 20:50

Add comment

Add comments relevant to this Article. මෙම ලිපියට අදාලව පමණක් අදහස් එකතු කරන්න.

Security code


Download Toolbar


Most Popular Articles

Latest Articles

Copyright © 2005 - 2016 (ඉස්කෝලේ) eduLanka Online Education School of Sri Lanka