1. PluginApplet.jsp
<jsp:plugin type="applet"
code="PluginApplet.class"
width="370" height="420">
</jsp:plugin>
2. PluginApplet.java
/** An applet that uses Swing and Java 2D and thus requires
* the Java Plug-in.
*/
public class PluginApplet extends JApplet {
public void init() {
UIManager.setLookAndFeel
(UIManager.getSystemLookAndFeelClassName());
setContentPane(new TextPanel());
}
}
3. Customized Panel
public class TextPanel extends JPanel
implements ActionListener {
private JComboBox fontBox;
private DrawingPanel drawingPanel;
public TextPanel() {
GraphicsEnvironment env =
GraphicsEnvironment.getLocalGraphicsEnvironment();
fontBox = new JComboBox(fontNames);
setLayout(new BorderLayout());
JPanel fontPanel = new JPanel();
fontPanel.add(new JLabel("Font:"));
fontPanel.add(fontBox);
JButton drawButton = new JButton("Draw");
...}
//event
public void actionPerformed(ActionEvent e) {
drawingPanel.setFontName((String)fontBox.getSelectedItem());
drawingPanel.repaint();
}
4.DrwaingPanel.java
class DrawingPanel extends JPanel {
private Ellipse2D.Double circle =
new Ellipse2D.Double(10, 10, 350, 350);
...}
<jsp:plugin type="applet"
code="PluginApplet.class"
width="370" height="420">
</jsp:plugin>
2. PluginApplet.java
/** An applet that uses Swing and Java 2D and thus requires
* the Java Plug-in.
*/
public class PluginApplet extends JApplet {
public void init() {
UIManager.setLookAndFeel
(UIManager.getSystemLookAndFeelClassName());
setContentPane(new TextPanel());
}
}
3. Customized Panel
public class TextPanel extends JPanel
implements ActionListener {
private JComboBox fontBox;
private DrawingPanel drawingPanel;
public TextPanel() {
GraphicsEnvironment env =
GraphicsEnvironment.getLocalGraphicsEnvironment();
fontBox = new JComboBox(fontNames);
setLayout(new BorderLayout());
JPanel fontPanel = new JPanel();
fontPanel.add(new JLabel("Font:"));
fontPanel.add(fontBox);
JButton drawButton = new JButton("Draw");
...}
//event
public void actionPerformed(ActionEvent e) {
drawingPanel.setFontName((String)fontBox.getSelectedItem());
drawingPanel.repaint();
}
4.DrwaingPanel.java
class DrawingPanel extends JPanel {
private Ellipse2D.Double circle =
new Ellipse2D.Double(10, 10, 350, 350);
...}
Comments
Post a Comment