Adding components to JApplet

Reply

Join Date: Mar 2005
Posts: 1
Reputation: Dahlia is an unknown quantity at this point 
Solved Threads: 0
Dahlia Dahlia is offline Offline
Newbie Poster

Adding components to JApplet

 
0
  #1
Mar 14th, 2005
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?
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 2,108
Reputation: server_crash is on a distinguished road 
Solved Threads: 18
server_crash server_crash is offline Offline
Postaholic

Re: Adding components to JApplet

 
0
  #2
Mar 14th, 2005
It's basicly the same as adding to a framed application, without a few methods such as setDefaultCloseOperation() and setSize().
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 2,108
Reputation: server_crash is on a distinguished road 
Solved Threads: 18
server_crash server_crash is offline Offline
Postaholic

Re: Adding components to JApplet

 
0
  #3
Mar 14th, 2005
One more thing, use this instead of the usual constructor:

  1. public void init()
  2. {
  3. }

also, you don't need a main method, as you will be calling it from an html file.
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 348
Reputation: paradox814 is an unknown quantity at this point 
Solved Threads: 4
paradox814's Avatar
paradox814 paradox814 is offline Offline
Posting Whiz

Re: Adding components to JApplet

 
0
  #4
Mar 14th, 2005
here is a really simple example, i hope this helps

  1. import java.awt.*;
  2. import java.awt.event.*;
  3. import javax.swing.*;
  4.  
  5. public class GUIOneB extends JApplet implements ActionListener
  6. {
  7. JButton jOptionConfirm, jOptionInput, jOptionMessage;
  8. Container c;
  9.  
  10. public void init()
  11. {
  12. c = getContentPane();
  13. c.setBackground(Color.yellow);
  14. c.setLayout(new FlowLayout());
  15.  
  16. jOptionConfirm = new JButton("showConfirmDialog");
  17. jOptionInput = new JButton("showOptionInputDialog");
  18. jOptionMessage = new JButton("showOptionMessageDialog");
  19.  
  20. jOptionConfirm.addActionListener(this);
  21. jOptionInput.addActionListener(this);
  22. jOptionMessage.addActionListener(this);
  23.  
  24. c.add(jOptionConfirm);
  25. c.add(jOptionInput);
  26. c.add(jOptionMessage);
  27. }
  28.  
  29. public void actionPerformed(ActionEvent e)
  30. {
  31. String returnValue;
  32.  
  33. if(e.getSource() == jOptionConfirm)
  34. JOptionPane.showConfirmDialog(this, "Confirm Something");
  35. else if(e.getSource() == jOptionInput)
  36. returnValue = JOptionPane.showInputDialog("Enter Something.");
  37. else if(e.getSource() == jOptionMessage)
  38. JOptionPane.showMessageDialog(this, "Hi from a message dialog.");
  39. }
  40. }
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC