01: /*
02: * Copyright Javelin Software, All rights reserved.
03: */
04:
05: package com.javelin.examples.swinglets;
06:
07: import java.net.*;
08: import java.util.*;
09: import java.io.*;
10: import java.awt.*;
11: import java.text.*;
12:
13: import javax.swing.*;
14: import javax.servlet.*;
15: import javax.servlet.http.*;
16:
17: import com.javelin.swinglets.*;
18: import com.javelin.swinglets.event.*;
19:
20: /**
21: * Servlet to display a demo Scripting.
22: *
23: * @author Robin Sharp
24: */
25:
26: public class ScriptServlet extends HttpServlet {
27: public synchronized void init(ServletConfig config)
28: throws ServletException {
29: super .init(config);
30: SUIManager
31: .setLookAndFeel("com.javelin.swinglets.plaf.javascript.JSLookAndFeel");
32: SwingletManager.setDefaultRealPath(config.getServletContext()
33: .getRealPath(""));
34: SwingletManager.setDefaultImagePath("/images/");
35:
36: }
37:
38: public synchronized void doGet(HttpServletRequest request,
39: HttpServletResponse response) throws IOException,
40: ServletException {
41: ServletManager servletManager = ServletManager
42: .getManager(request);
43:
44: PrintWriter out = response.getWriter();
45:
46: SFrame frame = new SFrame();
47: frame.setTitle("Script Servlet");
48:
49: frame.addScript(new SScript(SScript.JAVASCRIPT)
50: .setScript("function welcome() { alert('Welcome'); }"));
51: frame.setLayoutManager(new SGridLayout(2, 2, 50));
52:
53: frame.add(new SButton("Press Me")
54: .addMouseListener(new ScriptedMouseListener(
55: SScript.JAVASCRIPT)
56: .setMousePressedScript("welcome()")));
57:
58: frame.add(new SIcon("about/robin.gif", 100, 120)
59: .addMouseListener(new ScriptedMouseListener(
60: SScript.JAVASCRIPT)
61: .setMouseEnteredScript("welcome()")));
62:
63: frame.add(new STextField()
64: .addKeyListener(new ScriptedKeyListener(
65: SScript.JAVASCRIPT)
66: .setKeyTypedScript("welcome()")));
67:
68: frame.paint(out);
69: response.setContentType(frame.getContentType());
70: }
71: }
|