package com.marinilli.b2.c10;
import javax.swing.*;
import java.awt.*;
import javax.jnlp.*;
import java.awt.event.*;
/**
 * Chapter 10 - A Simple Lazy Text Editor
 * @author Mauro Marinilli
 * @version 1.0
 */
public class LazyEditor extends JFrame {
  ClassLoader loader;
  JButton drawButton = new JButton();
  JButton otherButton = new JButton();
  JButton anotherButton = new JButton();
  public LazyEditor() {
    loader = getClass().getClassLoader();
    getContentPane().setLayout(new BorderLayout());
    getContentPane().add(getToolBar(), BorderLayout.NORTH);
    getContentPane().add(new TextArea(), BorderLayout.CENTER);
    setTitle("A Lazy Text Editor");
    addWindowListener(new java.awt.event.WindowAdapter() {
      public void windowClosing(WindowEvent e) {
        exit();
      }
    });
    setSize(400,300);
    setVisible(true);
  }

  private void showDrawEditor() {
    DrawEditor de = new DrawEditor(this);
  }

  private JToolBar getToolBar() {
    JToolBar jt = new JToolBar();
    drawButton.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        showDrawEditor();
      }
    });
    drawButton.setText("draw");
    otherButton.setText("other");
    anotherButton.setText("open");
    this.addWindowListener(new java.awt.event.WindowAdapter() {
      public void windowClosing(WindowEvent e) {
        System.exit(0);
      }
    });
    jt.add(anotherButton);
    jt.add(otherButton);
    jt.add(drawButton);
    return jt;
  }
  private void exit() {
    System.exit(0);
  }
  public static void main(String[] a) {
    LazyEditor led = new LazyEditor();
  }
}