Home > Java > Java Program to write an Applet which handles user input and show output – Q54

Java Program to write an Applet which handles user input and show output – Q54

January 27, 2009 Leave a comment Go to comments

Q54: Java Program to write an applet, which shows one choice item and one list item. Add some items in both. Whenever user selects an item that message should be displayed on the screen.

import java.awt.*;
import java.awt.event.*;
import java.applet.*;

public class Ap_ListDemo extends Applet implements ActionListener {
	List os, browser;
	String msg = "";
	public void init(){
		os = new List(4,true);
		browser = new List(4,false);
		os.add("Windows 98/Xp");
		browser.add("netscape 3.x");
		browser.add("netscape 4.x");
		browser.add("netscape 5.x");
		browser.add("netscape 6.x");
		browser.add("internet explorer 4.0");
		browser.add("internet explorer 5.0");
		browser.add("internet explorer 6.0");
		browser.add("Lynx 2.4");
	public void actionPerformed(ActionEvent ae){
	public void paint(Graphics g){
		int idx[];
		msg = "current OS";
		idx = os.getSelectedIndexes();
		for(int i = 0; i < idx.length; i++)
			msg += os.getItem(idx[i]) + " ";
		msg = "current Browser: ";
		msg += browser.getSelectedItem();

… from College notes (BCA/MCA assignments):

Categories: Java Tags:
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: