DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   Java (http://www.daniweb.com/forums/forum9.html)
-   -   Adding components to JApplet (http://www.daniweb.com/forums/thread20177.html)

Dahlia Mar 14th, 2005 2:39 pm
Adding components to JApplet
 
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?

server_crash Mar 14th, 2005 5:49 pm
Re: Adding components to JApplet
 
It's basicly the same as adding to a framed application, without a few methods such as setDefaultCloseOperation() and setSize().

server_crash Mar 14th, 2005 5:53 pm
Re: Adding components to JApplet
 
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.

paradox814 Mar 14th, 2005 6:59 pm
Re: Adding components to JApplet
 
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.setBackground(Color.yellow);
      c.setLayout(new FlowLayout());

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

      jOptionConfirm.addActionListener(this);
      jOptionInput.addActionListener(this);
      jOptionMessage.addActionListener(this);

      c.add(jOptionConfirm);
      c.add(jOptionInput);
      c.add(jOptionMessage);
  }

  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.");
  }
}


All times are GMT -4. The time now is 12:25 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC