Jeroen Mathon - 2013-01-19

This Script act's like an simple Diary

The GUI class File

import java.awt.Desktop;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.GroupLayout;
import javax.swing.JOptionPane;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JButton;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.JTextPane;
import javax.swing.filechooser.FileFilter;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.io.*;
import java.nio.file.Files;

public class GUI {

protected static final String String = null;
private JFrame frmJavaDiary;
JButton btnExitProgram = new JButton("Exit Program");
JButton btnSave = new JButton("Save");
JButton btnClear = new JButton("Clear");
String Empty = "";
public static JTextPane textPane = new JTextPane();
/**
 * Launch the application.
 */
public static void main(String[] args) {
    EventQueue.invokeLater(new Runnable() {
        public void run() {
            try {
                GUI window = new GUI();
                window.frmJavaDiary.setVisible(true);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
}

/**
 * Create the application.
 */
public GUI() {
    initialize();
}

/**
 * Initialize the contents of the frame.
 */
private void initialize() {
    frmJavaDiary = new JFrame();
    frmJavaDiary.setTitle("Java Diary");
    frmJavaDiary.setResizable(false);
    frmJavaDiary.setBounds(100, 100, 685, 523);
    frmJavaDiary.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    //clear button
    btnClear.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {

            textPane.setText(Empty);
        }

    });

    //exit button
    btnExitProgram.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            System.exit(-1);
        }
    });
    GroupLayout groupLayout = new GroupLayout(frmJavaDiary.getContentPane());
    groupLayout.setHorizontalGroup(
        groupLayout.createParallelGroup(Alignment.LEADING)
            .addGroup(Alignment.TRAILING, groupLayout.createSequentialGroup()
                .addComponent(btnClear)
                .addPreferredGap(ComponentPlacement.RELATED, 245, Short.MAX_VALUE)
                .addComponent(btnExitProgram)
                .addGap(178)
                .addComponent(btnSave))
            .addGroup(groupLayout.createSequentialGroup()
                .addGap(12)
                .addComponent(textPane, GroupLayout.DEFAULT_SIZE, 655, Short.MAX_VALUE)
                .addContainerGap())
    );
    //save button
    btnSave.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            // TODO Auto-generated method stub
             try{
                  // Create file 
                  FileWriter fstream = new FileWriter("c://websites.txt");
                  BufferedWriter out = new BufferedWriter(fstream);
                  out.write(textPane.getText());

                   //Close the output stream
                  out.close();
                  }catch (Exception e1){//Catch exception if any
                  System.err.println("Error: " + e1.getMessage());
                  }
             try {
                Desktop.getDesktop().open(new File("c:\\diary.txt"));
            } catch (IOException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
        }

    });
    groupLayout.setVerticalGroup(
        groupLayout.createParallelGroup(Alignment.LEADING)
            .addGroup(Alignment.TRAILING, groupLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(textPane, GroupLayout.DEFAULT_SIZE, 447, Short.MAX_VALUE)
                .addPreferredGap(ComponentPlacement.UNRELATED)
                .addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
                    .addComponent(btnSave)
                    .addComponent(btnClear)
                    .addComponent(btnExitProgram)))
    );
    frmJavaDiary.getContentPane().setLayout(groupLayout);
}

}

The Core class File

public class Core {
public static String IText = GUI.textPane.getText();
static void main(Strings args[]){
String IText = GUI.textPane.getText();
}

}

End