protectedstaticfinalStringString=null;privateJFramefrmJavaDiary;JButtonbtnExitProgram=newJButton("Exit Program");JButtonbtnSave=newJButton("Save");JButtonbtnClear=newJButton("Clear");StringEmpty="";publicstaticJTextPanetextPane=newJTextPane();/** * Launch the application. */publicstaticvoidmain(String[]args){EventQueue.invokeLater(newRunnable(){publicvoidrun(){try{GUIwindow=newGUI();window.frmJavaDiary.setVisible(true);}catch(Exceptione){e.printStackTrace();}}});}/** * Create the application. */publicGUI(){initialize();}/** * Initialize the contents of the frame. */privatevoidinitialize(){frmJavaDiary=newJFrame();frmJavaDiary.setTitle("JavaDiary");frmJavaDiary.setResizable(false);frmJavaDiary.setBounds(100,100,685,523);frmJavaDiary.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//clearbuttonbtnClear.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEvente){textPane.setText(Empty);}});//exitbuttonbtnExitProgram.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEventarg0){System.exit(-1);}});GroupLayoutgroupLayout=newGroupLayout(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()));//savebuttonbtnSave.addActionListener(newActionListener(){@OverridepublicvoidactionPerformed(ActionEvente){//TODOAuto-generatedmethodstubtry{//CreatefileFileWriterfstream=newFileWriter("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(IOExceptione1){//TODOAuto-generatedcatchblocke1.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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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 {
}
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