import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.text.BadLocationException;
import javax.swing.JButton;
import javax.swing.JTextField;
import javax.swing.JLabel;
import javax.swing.JPasswordField;
import java.awt.CardLayout;
import javax.swing.JSplitPane;
import java.awt.event.ActionListener;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.awt.event.ActionEvent;
import javax.swing.JEditorPane;
import java.awt.Color;
import java.awt.Font;
import javax.swing.DropMode;
import javax.swing.JScrollBar;
import javax.swing.SwingConstants;
public class Program extends JFrame {
private JPanel contentPane;
private JTextField textField;
private JTextField textField_1;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Program frame = new Program();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*
* @throws BadLocationException
*/
public Program() throws BadLocationException {
double points = 0;
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(0, 0, 1200, 760);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JEditorPane dtrpnTypeTextHere = new JEditorPane();
dtrpnTypeTextHere.setContentType("type/normal");
dtrpnTypeTextHere.setToolTipText("");
dtrpnTypeTextHere.setFont(new Font("Arial", Font.PLAIN, 16));
dtrpnTypeTextHere.setForeground(Color.GREEN);
dtrpnTypeTextHere.setBackground(Color.BLACK);
dtrpnTypeTextHere.setBounds(10, 23, 1152, 671);
contentPane.add(dtrpnTypeTextHere);
int length = dtrpnTypeTextHere.getDocument().getLength();
String text = dtrpnTypeTextHere.getDocument().getText(0, length);
JLabel lblNewLabel = new JLabel("Power Text Editor");
lblNewLabel.setBackground(Color.BLACK);
lblNewLabel.setHorizontalAlignment(SwingConstants.CENTER);
lblNewLabel.setForeground(Color.GREEN);
lblNewLabel.setBounds(515, 0, 125, 14);
contentPane.add(lblNewLabel);
JLabel lblFileName = new JLabel("File Name:");
lblFileName.setBounds(660, 703, 75, 14);
contentPane.add(lblFileName);
JButton btnFinishEditing = new JButton("Finish editing");
btnFinishEditing.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
BufferedWriter writer = null;
try {
//create a temporary file
File logFile = new File("yas.txt");
// This will output the full path where the file will be written to...
System.out.println(logFile.getCanonicalPath());
writer = new BufferedWriter(new FileWriter(logFile));
writer.write(text);
} catch (Exception e1) {
e1.printStackTrace();
} finally {
try {
// Close the writer regardless of what happens...
writer.close();
} catch (Exception e1) {
}
System.out.println("Quit because of user exit");
System.exit(0);
}
}
});
btnFinishEditing.setForeground(Color.GREEN);
btnFinishEditing.setBackground(Color.BLACK);
btnFinishEditing.setBounds(532, 699, 108, 23);
contentPane.add(btnFinishEditing);
textField_1 = new JTextField();
textField_1.setBounds(726, 700, 131, 20);
contentPane.add(textField_1);
textField_1.setColumns(10);
}
}
There is the code, I'm having issues when making the file, I when I type things in, it appears inside the file as blank.