How do u run applets in an html that do not extend the Japplet but something

  • Thread starter Thread starter deonejuan
  • Start date Start date
D

deonejuan

Guest
You would have to extend JApplet to put Swing components into the applet. To go hog wild like you're doing here, consider firing up an applet that then evokes a full-blown application that uses your JFrame. This is possible, but only on the machine that starts your masterpiece. An Applet that fires an Application from code stored on a server would be impossible (for good reason).

If you want to fire the applet that evokes the JFrame, look inside your JDK folder, demos/jfc/Java2D/Java2Demo.html for a complete example.
 
like JFrame.wat is the .class? 1 // Fig. 11.19: RadioButtonFrame.java
2 // Creating radio buttons using ButtonGroup and JRadioButton.
3 import java.awt.FlowLayout;
4 import java.awt.Font;
5 import java.awt.event.ItemListener;
6 import java.awt.event.ItemEvent;
7 import javax.swing.JFrame;
8 import javax.swing.JTextField;
9 import javax.swing.JRadioButton;
10 import javax.swing.ButtonGroup;
11
12 public class RadioButtonFrame extends JFrame
13 {
14 private JTextField textField; // used to display font changes
15 private Font plainFont; // font for plain text
16 private Font boldFont; // font for bold text
17 private Font italicFont; // font for italic text
18 private Font boldItalicFont; // font for bold and italic text
19 private JRadioButton plainJRadioButton; // selects plain text
20 private JRadioButton boldJRadioButton; // selects bold text
21 private JRadioButton italicJRadioButton; // selects italic text
22 private JRadioButton boldItalicJRadioButton; // bold and italic
23 private ButtonGroup radioGroup; // buttongroup to hold radio buttons
24
25 // RadioButtonFrame constructor adds JRadioButtons to JFrame
26 public RadioButtonFrame()
27 {
28 super( "RadioButton Test" );
29 setLayout( new FlowLayout() ); // set frame layout
30
31 textField = new JTextField( "Watch the font style change", 25 );
32 add( textField ); // add textField to JFrame
33
34 // create radio buttons
35 plainJRadioButton = new JRadioButton( "Plain", true );
36 boldJRadioButton = new JRadioButton( "Bold", false );
37 italicJRadioButton = new JRadioButton( "Italic", false );
38 boldItalicJRadioButton = new JRadioButton( "Bold/Italic", false );
39 add( plainJRadioButton ); // add plain button to JFrame
40 add( boldJRadioButton ); // add bold button to JFrame
41 add( italicJRadioButton ); // add italic button to JFrame
42 add( boldItalicJRadioButton ); // add bold and italic button
43
44 // create logical relationship between JRadioButtons
45 radioGroup = new ButtonGroup(); // create ButtonGroup
46 radioGroup.add( plainJRadioButton ); // add plain to group
47 radioGroup.add( boldJRadioButton ); // add bold to group
48 radioGroup.add( italicJRadioButton ); // add italic to group
49 radioGroup.add( boldItalicJRadioButton ); // add bold and italic
50
51 // create font objects
52 plainFont = new Font( "Serif", Font.PLAIN, 14 );
53 boldFont = new Font( "Serif", Font.BOLD, 14 );
54 italicFont = new Font( "Serif", Font.ITALIC, 14 );
55 boldItalicFont = new Font( "Serif", Font.BOLD + Font.ITALIC, 14 );
56 textField.setFont( plainFont ); // set initial font to plain
57
58 // register events for JRadioButtons
59 plainJRadioButton.addItemListener(
60 new RadioButtonHandler( plainFont ) );
61 boldJRadioButton.addItemListener(
62 new RadioButtonHandler( boldFont ) );
63 italicJRadioButton.addItemListener(
64 new RadioButtonHandler( italicFont ) );
65 boldItalicJRadioButton.addItemListener(
66 new RadioButtonHandler( boldItalicFont ) );
67 } // end RadioButtonFrame constructor
68
69 // private inner class to handle radio button events
70 private class RadioButtonHandler implements ItemListener
71 {
72 private Font font; // font associated with this listener
73
74 public RadioButtonHandler( Font f )
75 {
76 font = f; // set the font of this listener
77 } // end constructor RadioButtonHandler
78
79 // handle radio button events
80 public void itemStateChanged( ItemEvent event )
81 {
82 textField.setFont( font ); // set font of textField
83 } // end method itemStateChanged
84 } // end private inner class RadioButtonHandler
85 } // end class RadioButtonFrame





Figure 11.20. Test class for RadioButtonFrame.
(This item is displayed on page 542 in the print version)
1 // Fig. 11.20: RadioButtonTest.java
2 // Testing RadioButtonFrame.
3 import javax.swing.JFrame;
4
5 public class RadioButtonTest
6 {
7 public static void main( String args[] )
8 {
9 RadioButtonFrame radioButtonFrame = new RadioButtonFrame();
10 radioButtonFrame.setDefaultCloseOperatio... JFrame.EXIT_ON_CLOSE );
11 radioButtonFrame.setSize( 300, 100 ); // set frame size
12 radioButtonFrame.setVisible( true ); // display frame
13 } // end main
14 } // end class RadioButtonTest



This code compiles and runs corrctly but how to put it in the html code.
for ex
<applet code="class name. plz give me a sample code that extends JApplet. i think a simple code will work better.if i understand this one the rest of the classes will be OK.
 
Back
Top