Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package aaa;
- import java.awt.event.WindowAdapter;
- import java.awt.event.WindowEvent;
- import java.io.FileNotFoundException;
- import java.io.IOException;
- import java.io.PrintWriter;
- import java.nio.file.Files;
- import java.nio.file.Paths;
- import java.text.SimpleDateFormat;
- import java.util.Calendar;
- import java.util.List;
- import javax.swing.JFrame;
- public class mmm extends JFrame {
- private static final long serialVersionUID = 1L;
- public mmm() {
- setTitle("NIEPOTRZEBNY frame :)");
- setSize(200, 200);
- addWindowListener(new CustomWindowAdapter(this));
- }
- private static void createAndShowGUI() {
- //Create and set up the window.
- JFrame frame = new mmm();
- //Display the window.
- frame.setVisible(false);
- }
- public static int getNumber(int i) { return i; }
- public static void main(String[] args) throws FileNotFoundException {
- //Schedule a job for the event-dispatching thread:
- String fileName = "C:/GodzinyLogowania.txt";
- String ooo = "";
- try
- {
- List<String> lines = Files.readAllLines(Paths.get(fileName));
- for (String line : lines)
- {
- System.out.println(line);
- ooo += line + "\r\n";
- }
- PrintWriter out = new PrintWriter(fileName);
- String Data = new SimpleDateFormat("dd-MM-yyyy").format(Calendar.getInstance().getTime());
- String Czas = new SimpleDateFormat("HH:mm:ss").format(Calendar.getInstance().getTime());
- out.print(ooo + Data + " Zalogowany o godzinie: "+ Czas + "\r\n");
- out.close();
- }
- catch (IOException e)
- {
- e.printStackTrace();
- }
- //creating and showing this application's GUI.
- javax.swing.SwingUtilities.invokeLater(new Runnable() {
- public void run() {
- createAndShowGUI();
- }
- });
- }
- class CustomWindowAdapter extends WindowAdapter {
- mmm window = null;
- CustomWindowAdapter(mmm window) {
- this.window = window;
- }
- // implement windowClosing method
- public void windowClosing(WindowEvent e) {
- String fileName = "C:/GodzinyLogowania.txt";
- String oooo = "";
- getNumber(7);
- try
- {
- List<String> liness = Files.readAllLines(Paths.get(fileName));
- for (String linee : liness)
- {
- System.out.println(linee);
- oooo += linee + "\r\n";
- }
- PrintWriter out = new PrintWriter(fileName);
- String Data = new SimpleDateFormat("dd-MM-yyyy").format(Calendar.getInstance().getTime());
- String Czas = new SimpleDateFormat("HH:mm:ss").format(Calendar.getInstance().getTime());
- out.print(oooo + Data + " Wylogowany o godzinie: " + Czas);
- out.close();
- }
- catch (IOException e1)
- {
- e1.printStackTrace();
- }
- System.exit(0);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement