Re: JFrame as JApplet?
- From: Andrew Thompson <SeeMySites@xxxxxxxxxxx>
- Date: Mon, 27 Jun 2005 11:21:52 GMT
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
.
- References:
- JFrame as JApplet?
- From: polsa
- JFrame as JApplet?
- Prev by Date: JFrame as JApplet?
- Next by Date: Re: JFrame as JApplet?
- Previous by thread: JFrame as JApplet?
- Next by thread: Re: JFrame as JApplet?
- Index(es):
Relevant Pages
|
|