001: /*
002: * Copyright Javelin Software, All rights reserved.
003: */
004:
005: package com.javelin.examples.swinglets;
006:
007: import java.awt.event.*;
008: import java.awt.*;
009: import javax.servlet.http.*;
010:
011: import com.javelin.swinglets.*;
012: import javax.servlet.*;
013: import java.io.*;
014:
015: /**
016: * Hemo World Swing Demo.
017: *
018: * @author Robin Sharp
019: */
020:
021: public class LayoutServlet extends HttpServlet {
022: public static void main(String[] args) {
023: LayoutServlet layoutServlet = new LayoutServlet(
024: "com.javelin.swinglets.plaf.jfc.JFCLookAndFeel");
025: }
026:
027: public LayoutServlet() {
028: super ();
029: }
030:
031: public LayoutServlet(String lookAndFeel) {
032: SUIManager.setLookAndFeel(lookAndFeel);
033:
034: SFrame frame = getContents();
035: frame.setSize(200, 200);
036: frame.addWindowListener(new WindowAdapter() {
037: public void windowClosing(WindowEvent event) {
038: System.out.println("EXIT");
039: System.exit(0);
040: }
041: });
042:
043: frame.setVisible(true);
044: }
045:
046: public synchronized void doGet(HttpServletRequest request,
047: HttpServletResponse response) throws IOException,
048: ServletException {
049: PrintWriter out = response.getWriter();
050:
051: SFrame frame = getContents();
052:
053: frame.paint(out);
054: response.setContentType(frame.getContentType());
055: }
056:
057: SFrame getContents() {
058: SFrame frame = new SFrame();
059: frame.setLayoutManager(new SBorderLayout());
060: frame.setTitle("Border Layout");
061: frame.setFont(SFont.getFont("Arial", SFont.PLAIN, 16));
062:
063: frame.add(getFlowLayout(), SBorderLayout.CENTER);
064:
065: return frame;
066:
067: }
068:
069: public SPanel getFlowLayout() {
070: SPanel panel = new SPanel();
071: panel.setLayoutManager(new SFlowLayout());
072:
073: panel.add(new SLabel("NORTH").setBackground(SColor.red));
074: panel.add(new SLabel("WEST").setBackground(SColor.red));
075: panel.add(new SLabel("CENTER").setBackground(SColor.red));
076: panel.add(new SLabel("EAST").setBackground(SColor.red));
077: panel.add(new SLabel("SOUTH").setBackground(SColor.red));
078:
079: return panel;
080: }
081:
082: public SPanel getBorderLayout() {
083: SPanel panel = new SPanel();
084: panel.setLayoutManager(new SBorderLayout());
085:
086: panel.add(new SLabel("NORTH").setBackground(SColor.red),
087: SBorderLayout.NORTH);
088: panel.add(new SLabel("WEST").setBackground(SColor.red),
089: SBorderLayout.WEST);
090: panel.add(new SLabel("CENTER").setBackground(SColor.red),
091: SBorderLayout.CENTER);
092: panel.add(new SLabel("EAST").setBackground(SColor.red),
093: SBorderLayout.EAST);
094: panel.add(new SLabel("SOUTH").setBackground(SColor.red),
095: SBorderLayout.SOUTH);
096:
097: return panel;
098: }
099:
100: public synchronized void init(ServletConfig config)
101: throws ServletException {
102: super .init(config);
103: SwingletManager.setDefaultRealPath(config.getServletContext()
104: .getRealPath(""));
105: }
106:
107: }
|