Click to See Complete Forum and Search --> : Applets and swing
asterix299
Jul 8th, 2007, 08:10 PM
I'm developing a web-based applet and I want it to open an external swing form that's stored in a separate class.
Basically can someone just show me how to open a blank JPanel that is stored in a separate class file from an applet running in a browser? I believe I can do anything beyond that on my own. Any tips would be appreciated though.
On another note:
I'm pretty advanced with Java but I just have very little experience with applets. Would you recommend using the java.applet.Applet class or the swing JApplet class for my applets? Is there any big difference?
ComputerJy
Jul 9th, 2007, 12:56 AM
I didn't understand your question very well.
I think to use a panel in your applet all you need is to include it's class path in the "classpath" when building the applet.
About your second question. If your applet uses animation it'd be better to use the java.applet.Applet. But if you'll be using it as a web form the javax.swing.JApplet would be better (it's just a graphics thing)
System_Error
Jul 10th, 2007, 02:04 PM
asically can someone just show me how to open a blank JPanel that is stored in a separate class file from an applet running in a browser? I believe I can do anything beyond that on my own. Any tips would be appreciated though.
extend JDialog and add the JPanel to it's container. It's just like a JFrame so you can customize the way it looks and you can easily call it from an Applet.
I'm pretty advanced with Java but I just have very little experience with applets. Would you recommend using the java.applet.Applet class or the swing JApplet class for my applets? Is there any big difference?
JApplet.
asterix299
Jul 11th, 2007, 03:30 PM
extend JDialog and add the JPanel to it's container. It's just like a JFrame so you can customize the way it looks and you can easily call it from an Applet.
Can you give me a quick code snippet maybe of how you're saying to set this up? I tried what you said and it's not working for me.
System_Error
Jul 12th, 2007, 07:43 PM
Here's a really crude example:
import javax.swing.*;
import java.awt.event.*;
public class Test extends JApplet implements ActionListener
{
private JButton btn;
public void init()
{
btn = new JButton("Test");
btn.addActionListener(this);
getContentPane().add(btn);
setVisible(true);
}
public void actionPerformed(ActionEvent ae)
{
if (ae.getSource() == btn) new TestBox();
}
}
class TestBox extends JDialog
{
public TestBox()
{
setSize(200,200);
setVisible(true);
}
}
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.