0

hi, im new to java...and the rest like swing and all that stufss. i got a code but i want to change the applet a bit , i mean the way it is diplayed. ken u help. and yes i want wen i click exit button the applets closes and the browser too.

mport 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;
	JComboBox comb1;
	JButton but1;
	
	public void init()
	{
		
		
		Container con=getContentPane();
		con.setLayout(new FlowLayout());
		
		lab1=new JLabel("Please choose an image here:::>/t");
		con.add(lab1);
			
		
		
		comb1=new JComboBox();
		comb1.addItem("Lake");
		comb1.addItem("Wood");
		comb1.addItem("Tree");


		
		con.add(comb1);
		ImageIcon image =  new ImageIcon("ajay.jpg");	
		 but1=new JButton("Exit",image);
		getContentPane().add(but1);
		
		but1.addActionListener(this);
		comb1.addActionListener(this);
	
	}
	

	
	public void paint( Graphics g ) 
  	{ 
	    super.paint( g ); 
	    Image image = getImage( getCodeBase(), comb1.getSelectedItem().toString() + ".jpg");  
	   
	   	g.drawImage( image,100,100,100,100, this ); 
    }

	
	public void actionPerformed(ActionEvent ae)
	{
		if(ae.getSource() == but1) 
	    { 
		    //lab1.setText("Thanks for using this program, close the browser!   ");
		    //repaint();
	   		destroy();
	    } 
	    else if(ae.getSource() == comb1)
	    {
	    	repaint();
	    }
	}
}

tkx

3
Contributors
2
Replies
3
Views
9 Years
Discussion Span
Last Post by electron33
0

Hi. Try with System.exit(0) after you call destroy in your code.
Mark: You will need Security rights to do so.

Visit Sun to find out more about this topic.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.