Education Menu

 

Features Menu

 

Additional Menu

 

Now Online

We have 102 guests online
 

@edulanka

 

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 (ජාවා වැඩසටහන්කරණය)

Java Swing Applets - Example
Saturday, 26 March 2011 22:49

Java Swing Applets - Examples

The Internet Foundation Classes (IFC) were a graphics library for Java originally developed by Netscape Communications Corporation and first released on December 16, 1996. On April 2, 1997, Sun Microsystems and Netscape Communications Corporation announced their intention to incorporate IFC with other technologies to form the Java Foundation Classes.

Swing introduced a mechanism that allowed the look and feel of every component in an application to be altered without making substantial changes to the application code. The introduction of support for a pluggable look and feel allows Swing components to emulate the appearance of native components while still retaining the benefits of platform independence. This feature also makes it easy to make an application written in Swing look very different from native programs if desired.

Here some Examples on Java Swing Applets:

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class ex extends JApplet implements ActionListener
{
JLabel lblSc,lblRed,lblGreen,lblBlue,lblYellow,lblChoice;
JTextField txtChoice,txtOutput;
JButton btnShow;
public void paint(Graphics a)
{a.drawRect(20,20,350,250);
}
public void init()
{
lblSc=new JLabel("Selecting Colors");
lblRed=new JLabel("1. Red");
lblGreen=new JLabel("2. Green");
lblBlue=new JLabel("3. Blue");
lblYellow=new JLabel("4. Yellow");
lblChoice=new JLabel("Choice");

txtChoice=new JTextField();
txtOutput=new JTextField();

btnShow=new JButton("Show");

setLayout(null);
lblSc.setBounds(30,30,200,20);
lblRed.setBounds(50,50,60,20);
lblGreen.setBounds(50,80,60,20);
lblBlue.setBounds(50,110,60,20);
lblYellow.setBounds(50,140,60,20);
lblChoice.setBounds(30,160,60,30);
txtChoice.setBounds(90,160,30,30);
txtOutput.setBounds(30,200,300,30);
btnShow.setBounds(180,160,100,30);

add(lblSc);
add(lblRed);
add(lblGreen);
add(lblBlue);
add(lblYellow);
add(lblChoice);
add(txtChoice);
add(txtOutput);
add(btnShow);

btnShow.addActionListener(this);
}

public void actionPerformed(ActionEvent e)
{
if(e.getSource()==btnShow)
{
int Choice=Integer.parseInt(txtChoice.getText());

if(Choice==1)
{ txtOutput.setBackground(Color.red);
txtOutput.setText("You have selected RED color");
} if(Choice==2)
{ txtOutput.setBackground(Color.green);
txtOutput.setText("You have selected GREEN color");
} if(Choice==3)
{ txtOutput.setBackground(Color.blue);
txtOutput.setText("You have selected BLUE color");
} if(Choice==4)
{ txtOutput.setBackground(Color.yellow);
txtOutput.setText("You have selected YELLOW color");
}

}
}
}

//<applet code="ex.class" width=450 height=250></applet>

Download All Programs,

 

Add comment

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


Security code
Refresh

2.jpg

Download Toolbar

 
 

Most Popular Articles

Latest Articles

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