| | |
Adding components to JApplet
![]() |
•
•
Join Date: Jun 2004
Posts: 2,108
Reputation:
Solved Threads: 18
One more thing, use this instead of the usual constructor:
also, you don't need a main method, as you will be calling it from an html file.
Java Syntax (Toggle Plain Text)
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
Java Syntax (Toggle Plain Text)
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."); } }
![]() |
Similar Threads
- Adding .COM Components to Visual Web Developer 2008 (ASP.NET)
- Deleting components in D2007 (Pascal and Delphi)
- Adding components at runtime ontop of a scrollable table (Java)
- Java GUI JOptionPane.showMessageDialog (Java)
- Subpanel problem (Java)
- How to position buttons/boxes in a JTabbed Pane? (Java)
Other Threads in the Java Forum
- Previous Thread: Constructor
- Next Thread: Number Rounding
| Thread Tools | Search this Thread |
911 actionlistener addressbook android api append applet application array arrays automation binary blackberry block bluetooth character chat class client code component consumer csv database desktop developmenthelp eclipse error fractal ftp game givemetehcodez graphics gui html ide image integer j2me j2seprojects japplet java javaarraylist javac javaee javaprojects jni jpanel julia lego linked linux list loops mac map method methods mobile netbeans newbie number objects online oriented panel printf problem program programming project projects properties recursion replaydirector reporting researchinmotion rotatetext rsa scanner se server set singleton sms sort sql string swing test textfields threads time title tree tutorial-sample ubuntu update windows working






