question on closing applet

closing an applet via command button

Page 1 of 1

1 Replies - 2888 Views - Last Post: 06 December 2008 - 09:26 PM Rate Topic: -----

#1 xxsixseven  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 07-October 08

question on closing applet

Posted 06 December 2008 - 05:14 PM

I'm having problems programming my "Exit " JButton to actually close out the applet.....i'm finding that System.exit(0); is not working when it comes to closing an Extended type Applet....or JApplet...
can someone help me out...

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

public class WhiteBoard extends JApplet implements ActionListener

{
	private static int WIDTH = 550;
	private static int HEIGHT = 350;

	private int row = 10;
	private int col = 20;

		 //GUI components
	private JLabel headingL;
	private JTextField lineTF;
	private JTextArea whiteBoardTA;
	private JButton exitB, appendB;

	public WhiteBoard()
	{
		setSize(WIDTH,HEIGHT);

		headingL = new JLabel("Welcome to White Board");
		lineTF = new JTextField(20);

		whiteBoardTA = new JTextArea(row,col);
		exitB = new JButton("Exit");
		exitB.addActionListener(this);

		appendB = new JButton("Append");
		appendB.addActionListener(this);

		setLayout(null);

		headingL.setLocation(50, 20);
		lineTF.setLocation(20, 100);
		whiteBoardTA.setLocation(320, 50);
		appendB.setLocation(230, 100);
		exitB.setLocation(230, 250);

		headingL.setSize(200, 30);
		lineTF.setSize(200, 30);
		whiteBoardTA.setSize(200, 200);
		appendB.setSize(80, 30);
		exitB.setSize(80, 30);

		add(headingL);
		add(lineTF);
		add(whiteBoardTA);
		add(appendB);
		add(exitB);

		setVisible(true);
	} 

   public void actionPerformed(ActionEvent e)
   {
	   if(e.getActionCommand().equals("Append"))
		  whiteBoardTA.append(lineTF.getText());
	   else if(e.getActionCommand().equals("Exit")){
		   //THIS IS WHERE I'M HAVING THE PROBLEMS//
		   System.exit(0);
	   }

	}
}




Is This A Good Question/Topic? 0
  • +

Replies To: question on closing applet

#2 William_Wilson  Icon User is offline

  • lost in compilation
  • member icon

Reputation: 205
  • View blog
  • Posts: 4,807
  • Joined: 23-December 05

Re: question on closing applet

Posted 06 December 2008 - 09:26 PM

You cannot "exit" an applet. They are built into a webpage, so it is a web content issue that prevents this from being allowed. The applet must be removed from the page DOM, or redirect to another page.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1