EditLive! 9 Documentation : Instantiation of a Swing Application Code
Created by Jessica Hardy, last modified by Kristin Repsher on May 21, 2012
/*
* Copyright (c) 2005 Ephox Corporation.
*/
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import com.ephox.editlive.*;
import com.ephox.editlive.applets.*;
import com.ephox.editlive.util.guiutils.*;
import javax.jnlp.*;
/** Class loads a JFrame with a single panel, containing the
* Ephox EditLive! Editor
*/
public class Instantiation extends JFrame{
/** html content to appear in the instance of EditLive! */
private static final String INITIAL_HTML = "<html><head><title>Initial Title</title></head><body><p></p></body></html>";
/** Base class for EditLive! */
private ELJBean editLiveBean = new ELJBean(INITIAL_HTML, "", 700, 570, getClass().getResource("sample_eljconfig.xml"), false);
/** Creates JFrame and adds all class properties. Adds action listener to JButtons in JFrame
*
*/
public Instantiation() throws Exception {
super("Tutorial - Instantiation");
this.getContentPane().setLayout(new FlowLayout());
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
// initialize EditLive!
editLiveBean.init();
}
});
// Create a JPanel to hold the ELJBean
JPanel editorHolder = new JPanel(new FlowLayout());
editorHolder.add(editLiveBean);
// Add the JPanel to the JFrame
this.getContentPane().add(editorHolder);
// Display the JFrame.
this.setSize(new Dimension(710, 620));
this.setVisible(true);
// Adding a listener to detect if the JFrame is closing, to close the application if needed.
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
/** Sets up the application and begins its execution
*
* @param args the command line arguments - ignored
*/
public static void main(String args[]) throws Exception {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch(Exception e) {
System.out.println("Unable to locate UIManager class");
e.printStackTrace();
}
new Instantiation();
}
}