Advertisement
Guest User

Untitled

a guest
May 29th, 2015
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.73 KB | None | 0 0
  1. package aaa;
  2.  
  3. import java.awt.event.WindowAdapter;
  4. import java.awt.event.WindowEvent;
  5. import java.io.FileNotFoundException;
  6. import java.io.IOException;
  7. import java.io.PrintWriter;
  8. import java.nio.file.Files;
  9. import java.nio.file.Paths;
  10. import java.text.SimpleDateFormat;
  11. import java.util.Calendar;
  12. import java.util.List;
  13.  
  14. import javax.swing.JFrame;
  15.  
  16. public class mmm  extends JFrame {
  17.  
  18.     private static final long serialVersionUID = 1L;
  19.  
  20.     public mmm() {
  21.         setTitle("NIEPOTRZEBNY frame :)");
  22.  
  23.   setSize(200, 200);
  24.         addWindowListener(new CustomWindowAdapter(this));
  25.     }
  26.  
  27.     private static void createAndShowGUI() {
  28.  
  29.   //Create and set up the window.
  30.  
  31.   JFrame frame = new mmm();
  32.  
  33.   //Display the window.
  34.  
  35.   frame.setVisible(false);
  36.  
  37.     }
  38.    
  39.     public static int getNumber(int i) { return i; }
  40.  
  41.     public static void main(String[] args) throws FileNotFoundException {
  42.   //Schedule a job for the event-dispatching thread:
  43.         String fileName = "C:/GodzinyLogowania.txt";
  44.         String ooo = "";
  45.        
  46.         try
  47.         {
  48.             List<String> lines = Files.readAllLines(Paths.get(fileName));
  49.             for (String line : lines)
  50.             {
  51.                 System.out.println(line);
  52.                 ooo += line + "\r\n";
  53.             }
  54.             PrintWriter out = new PrintWriter(fileName);
  55.             String Data = new SimpleDateFormat("dd-MM-yyyy").format(Calendar.getInstance().getTime());
  56.             String Czas = new SimpleDateFormat("HH:mm:ss").format(Calendar.getInstance().getTime());
  57.             out.print(ooo + Data + "   Zalogowany o godzinie: "+ Czas + "\r\n");
  58.             out.close();
  59.         }
  60.         catch (IOException e)
  61.         {
  62.             e.printStackTrace();
  63.         }
  64.        
  65.   //creating and showing this application's GUI.
  66.  
  67.   javax.swing.SwingUtilities.invokeLater(new Runnable() {
  68.  
  69. public void run() {
  70.  
  71.     createAndShowGUI();
  72.  
  73. }
  74.  
  75.   });
  76.     }
  77.  
  78.     class CustomWindowAdapter extends WindowAdapter {
  79.  
  80.         mmm window = null;
  81.        
  82.  
  83.         CustomWindowAdapter(mmm window) {
  84.             this.window = window;
  85.         }
  86.  
  87.         // implement windowClosing method
  88.         public void windowClosing(WindowEvent e) {
  89.             String fileName = "C:/GodzinyLogowania.txt";
  90.             String oooo = "";
  91.             getNumber(7);
  92.            
  93.             try
  94.             {
  95.                 List<String> liness = Files.readAllLines(Paths.get(fileName));
  96.                 for (String linee : liness)
  97.                 {
  98.                     System.out.println(linee);
  99.                     oooo += linee + "\r\n";
  100.                 }
  101.                 PrintWriter out = new PrintWriter(fileName);
  102.                 String Data = new SimpleDateFormat("dd-MM-yyyy").format(Calendar.getInstance().getTime());
  103.                 String Czas = new SimpleDateFormat("HH:mm:ss").format(Calendar.getInstance().getTime());
  104.                 out.print(oooo + Data + "   Wylogowany o godzinie: " + Czas);
  105.                 out.close();
  106.             }
  107.             catch (IOException e1)
  108.             {
  109.                 e1.printStackTrace();
  110.             }
  111.            
  112.             System.exit(0);
  113.         }
  114.     }
  115.  
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement