01: /*
02: * Copyright Javelin Software, All rights reserved.
03: */
04:
05: package com.javelin.examples.swinglets;
06:
07: import java.awt.event.*;
08: import java.awt.*;
09: import javax.servlet.http.*;
10:
11: import com.javelin.swinglets.*;
12: import javax.servlet.*;
13: import java.io.*;
14:
15: /**
16: * Hello World Swing Demo.
17: *
18: * @author Robin Sharp
19: */
20:
21: public class HelloWorld extends HttpServlet {
22: public static void main(String[] args) {
23: HelloWorld hw = new HelloWorld(
24: "com.javelin.swinglets.plaf.jfc.JFCLookAndFeel");
25: }
26:
27: public HelloWorld() {
28: super ();
29: }
30:
31: public HelloWorld(String lookAndFeel) {
32: SUIManager.setLookAndFeel(lookAndFeel);
33:
34: SFrame frame = getContents();
35: frame.setSize(200, 200);
36: frame.addWindowListener(new WindowAdapter() {
37: public void windowClosing(WindowEvent event) {
38: System.out.println("EXIT");
39: System.exit(0);
40: }
41: });
42:
43: frame.setVisible(true);
44: }
45:
46: public synchronized void doGet(HttpServletRequest request,
47: HttpServletResponse response) throws IOException,
48: ServletException {
49: PrintWriter out = response.getWriter();
50:
51: SFrame frame = getContents();
52: frame.paint(out);
53: response.setContentType(frame.getContentType());
54: }
55:
56: SFrame getContents() {
57: SFrame frame = new SFrame();
58: frame.setLayoutManager(new SFlowLayout());
59: frame.setTitle("Hello World Swing");
60: SFont font = SFont.getFont("Arial", SFont.PLAIN, 16);
61: frame.setFont(font);
62: frame.add(new SLabel("Hello World"));
63:
64: //frame.add( new SLabel( "!!!" ).setFont(SFont.getFont(null,SFont.ITALIC,0)) );
65:
66: return frame;
67: }
68:
69: public synchronized void init(ServletConfig config)
70: throws ServletException {
71: super .init(config);
72: SwingletManager.setDefaultRealPath(config.getServletContext()
73: .getRealPath(""));
74: }
75:
76: }
|