Timer Event

//<applet code=app7 height=500 width=500></applet>
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class TimerSwingDemo extends JApplet {
	JPanel p1;
	JLabel l1;
	Timer time;
	int i;
	String str[] = { "one", "two", "three", "four", "five", "six", "seven",
			"eight", "nine", "ten" };
	int c1 = 10;
	int c2 = 20;
	int c3 = 30;

	@Override
	public void init() {
		p1 = new JPanel();
		l1 = new JLabel("");
		time = new Timer(1000, new myevent());
		getContentPane().add(p1);
		p1.add(l1);
		time.start();
		l1.setFont(new Font("Tohama", Font.BOLD, 40));
	}

	public class myevent implements ActionListener {
		@Override
		public void actionPerformed(ActionEvent evt) {
			l1.setText(str[i]);
			p1.setBackground(new Color(c1, c2, c3));
			c1 += 5;
			c2 += 5;
			c3 += 5;
			if (c1 > 240)
				c1 = 10;
			if (c2 > 240)
				c2 = 15;
			if (c3 > 240)
				c3 = 20;
			i++;
			if (i == 10)
				i = 0;
		}
	}
}

Download

Event handling in Java

Action Event with Menu Item
Action Event in Applet
Action Event
Adjustment Event
Focus Event
Item Event
Key Event
MOuse Event
Event with Timer
Window Event


Write your Comment

Name :
Email Id : [ We will not publish your email id ]
Your Comment : [ Maximum 200 chars ]
Enter Security code