java applet programming

event handling in java applet

Page 1 of 1

1 Replies - 1623 Views - Last Post: 28 August 2008 - 12:16 AM Rate Topic: -----

#1 gyanprakash  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 27-August 08

java applet programming

Post icon  Posted 27 August 2008 - 10:12 PM

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

	public class MyApplet extends JApplet 
	{
	int i=0;
	JButton b1;
	JComboBox cb1,cb2;
	JLabel l1,l2,l3;
	String st="Air",st1="Water";
	String st3="BLACK";
	public void init()
	{
	b1=new JButton("Start");
	cb1=new JComboBox();
	cb2=new JComboBox();
	l1=new JLabel("Medium 1");
	l2=new JLabel("Medium 2");
	l3=new JLabel(" ");
	cb1.addItem("Air");
	cb1.addItem("Water");
	cb1.addItem("Glass");
	cb1.addItem("Diamond");
	cb2.addItem("Air");
	cb2.addItem("Water");
	cb2.addItem("Glass");
	cb2.addItem("Diamond");
	setLayout(new FlowLayout());
	add(l1);
	add(cb1);
	cb1.addActionListener(new ChoiceClicked());
	add(l3);
	add(l2);
	add(cb2);
	cb2.addActionListener(new ChoiceClicked1());
	add(b1);
	   b1.addActionListener(new Buttonclicked());
	setVisible(true);
	}
	class ChoiceClicked implements ActionListener
	{
	public void actionPerformed(ActionEvent ev)
	{
	st=(String)cb1.getSelectedItem();
	repaint();
	}
	} 
	class ChoiceClicked1 implements ActionListener
	{
	public void actionPerformed(ActionEvent ev)
	{
	st1=(String)cb2.getSelectedItem();
	repaint();
	}
	} 	

		class Buttonclicked implements ActionListener
	{
	public void actionPerformed(ActionEvent ev)
	{
	public void paint(Graphics g1)
		{
	Graphics2D g = (Graphics2D) g1;
	Color c=new Color(239, 0, 0, 50);
	g.setBackground(c);
	g.setColor(Color.black);
	g.drawString("REFLECTION",220,45);
	g.drawString("REFRACTION",220,365);
	g.setColor(Color.pink);
	g.fillRect(100,50,300,150);
	g.setColor(Color.black);
	g.drawString(st,125,125);
	g.setColor(Color.cyan);
	g.fillRect(100,200,300,150);
	g.setColor(Color.black);
	g.drawString(st1,125,275);
	g.setColor(Color.black);
	g.drawLine(100,200,400,200);
	g.drawLine(250,50,250,350);
	g.setColor(Color.blue);
	try
	{
	for(i=0;i<150;i++)
	{
	g.drawLine(100,50,100+i,50+i);
	Thread.sleep(20);
	}
	for(i=0;i<150;i++)
	{
	g.drawLine(250,200,250+i,200-i);
	Thread.sleep(20);
	}
	for(i=0;i<75;i++)
	{
	g.drawLine(250,200,250+i,200+2*i);
	Thread.sleep(50);
	}
	}
	catch(InterruptedException e)
	{
	}
}
}
}		 



Is This A Good Question/Topic? 0
  • +

Replies To: java applet programming

#2 dineeshd  Icon User is offline

  • member icon

Reputation: 38
  • View blog
  • Posts: 619
  • Joined: 30-June 08

Re: java applet programming

Posted 28 August 2008 - 12:16 AM

Are you seeking any help or contributing a code? If contributing, post it in Snippets Section. Else you need to explain what is your issue with the code.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1