Hi everyone,i really hope you can assist with the following problem that i have been having,how do i add components to JApplets,what are the methods tha i should use for the task?

It's basicly the same as adding to a framed application, without a few methods such as setDefaultCloseOperation() and setSize().

One more thing, use this instead of the usual constructor:

public void init()

also, you don't need a main method, as you will be calling it from an html file.

here is a really simple example, i hope this helps

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

public class GUIOneB extends JApplet implements ActionListener
   JButton jOptionConfirm, jOptionInput, jOptionMessage;
   Container c;

   public void init()
      c = getContentPane();
      c.setLayout(new FlowLayout());

      jOptionConfirm = new JButton("showConfirmDialog");
      jOptionInput = new JButton("showOptionInputDialog");
      jOptionMessage = new JButton("showOptionMessageDialog");



   public void actionPerformed(ActionEvent e)
      String returnValue;

      if(e.getSource() == jOptionConfirm)
         JOptionPane.showConfirmDialog(this, "Confirm Something");
      else if(e.getSource() == jOptionInput)
         returnValue = JOptionPane.showInputDialog("Enter Something.");
      else if(e.getSource() == jOptionMessage)
         JOptionPane.showMessageDialog(this, "Hi from a message dialog.");
This article has been dead for over six months. Start a new discussion instead.