/*********************************
 * Program Name: Task2.java      *		
 * Date: 27 Janauary 2008        *
 * Programmer: Dhanandjay MOTAH	 *
 *********************************/

 
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.Graphics.*;
import java.applet.Applet;


public class Task1 extends JApplet implements ActionListener
{
	JLabel lab1;		//label created
	JComboBox comb1;	//combo box created
	JButton but1;		//button created
	
	public void init()
	{
		

		
		//creates a container pane
		Container con=getContentPane();
		
		//uses pink as backgroud color
		con.setBackground( Color.pink );
		
		// uses a flowlayout as layout manager
		con.setLayout(new FlowLayout(FlowLayout.LEFT,10,10));
		
		lab1=new JLabel("Please choose an image here:::>");
		con.add(lab1);
			
		
		
		comb1=new JComboBox();
		
		//list of images
		comb1.addItem("Lake");
		comb1.addItem("Wood");
		comb1.addItem("Tree");
		comb1.addItem("Vienna");
		comb1.addItem("Mauritius");
		comb1.addItem("Canada");
		comb1.addItem("Fireworks");	
		comb1.addItem("NewYork");
		comb1.addItem("France");
		comb1.addItem("Switzerland");		
			
		con.add(comb1);
		
		//a picture in the button
		ImageIcon image =  new ImageIcon("exit.jpg");	
		
		//add a button with the button labelled
		but1=new JButton("Terminate",image);
		getContentPane().add(but1);
		
		but1.addActionListener(this);
		comb1.addActionListener(this);
	
	}
	

	

	//describes what hapens when actions are triggered
	public void actionPerformed(ActionEvent actevent)
	{
		

		if(actevent.getSource() == but1) 
	    
	   
	    
	    { 
		    
		  
		    lab1.setText("Program Terminated, Please Close the Viewer");
		    repaint();
	   		
	    } 
	    else if(actevent.getSource() == comb1)
	    	{
	    	repaint();
	 	 	}
	
	}
	
	
	
	
	//shows the selected inage from the combo box
	public void paint( Graphics gr ) 
  		{ 
  	 		Boolean n=true;
  	 			
  	 	
  	 	
  	 			super.paint(gr); 
	    	if (Image image = getImage( getCodeBase(), comb1.getSelectedItem().toString() + ".jpg")) 
					
					{
						
					
	   				//draws the images at these coordinates
	   				gr.drawImage( image,100,100,100,100, this ); 
					}
				
    	}
    	
   }

plz how ken i add in this applet a FileNotFound exception

plz help
thanks a lot

Member Avatar for iamthwee

Is your file in the same directory as where you applet is?

Is your file in the same directory as where you applet is?

ya its in the same directory... plz help me, i neeed it quick help.....

no, it's not urgent.
You claiming it is makes me withhold the answer, which I have.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.