Re: JFrame as JApplet?



On 27 Jun 2005 03:56:20 -0700, polsa wrote:

> I was wondering if there is any way to write an application which can
> be run as well as a JFrame as as a JApplet.

Yes. It is fairly basic stuff [1].

> ..And if so: how can I figure
> out which way the application has been started?

- Tell your class ..
- in the constructor or
- through a method,
- hand it the parent UI and have it deternime,
- any number of other ways,
...depending upon you design, constraints and code.

[1] trivial example..
<sscce>
import javax.swing.*;

public class AppletApplicationGUI extends JApplet {

JLabel message;

public void init() {
getContentPane().add( getGUIPanel() );
setMessage("Applet Mode");
}

public JPanel getGUIPanel() {
message = new JLabel(" ");
JPanel p = new JPanel();
p.add(message);
return p;
}

public void setMessage(String text) {
message.setText(text);
}

public static void main(String[] args) {
JFrame f = new JFrame("Applet Application GUI");
AppletApplicationGUI aag = new AppletApplicationGUI();
f.getContentPane().add( aag.getGUIPanel() );
aag.setMessage("Application Mode");
f.pack();
f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
f.setVisible(true);
}
}
</sscce>

HTH

--
Andrew Thompson
http://www.PhySci.org/codes/ Web & IT Help
http://www.PhySci.org/ Open-source software suite
http://www.1point1C.org/ Science & Technology
http://www.LensEscapes.com/ Images that escape the mundane
.



Relevant Pages

  • Redraw in wron place after AffineTransform
    ... I have a JApplet from which I create a JPanel. ... If I set an AffineTransform before drawing the text, ... public void start{ ...
    (comp.lang.java.gui)
  • Re: dimensions of components...
    ... > I have this JApplet for a chat app window.. ... JPanel holdingPanel = new JPanel); ... JTextArea textAreaBottom = new JTextArea; ...
    (comp.lang.java.gui)
  • Re: program works but wont display in browser
    ... Using JApplet is a good idea, ... private JPanel buttonPanel; ... Font title, documentText; ... public void paintComponent{ ...
    (comp.lang.java.help)
  • Re: Firefox not exiting (JApplet)
    ... containing a JApplet I'm writing, unless I navigate off that page first. ... public void init() { ... This method initializes jContentPane ...
    (comp.lang.java.programmer)
  • Re: Applet - Creating new objects from a Button Listener
    ... JApplet is not) you can call revalidateon the container to have the ... If you are going to use JButtons, use a JApplet. ... public void actionPerformed{ ...
    (comp.lang.java.programmer)