Advertisement
Guest User

Untitled

a guest
Oct 5th, 2017
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.19 KB | None | 0 0
  1. import java.awt.Color;
  2. import java.awt.Dialog;
  3. import java.awt.Font;
  4. import java.util.*;
  5. import java.awt.event.ActionEvent;
  6. import java.awt.event.ActionListener;
  7. import java.io.*;
  8. import javax.swing.*;
  9. import java.awt.*;
  10. import java.util.regex.*;
  11.  
  12. public class shtdwnatMainFrame {
  13.    
  14.     JFrame mainFrame;
  15.     static JTextField mainTxtFld;
  16.     JPanel mainPanel;
  17.     JLabel mainLabel;
  18.     static JLabel otherLabel;
  19.     JButton okBtn;
  20.     static String scr ="C:\\ProgramData\\shtdwnatFile.txt";
  21.     static File f = new File(scr);
  22.     static Scanner scan;
  23.     static PrintWriter pr;
  24.    
  25.    
  26.     public shtdwnatMainFrame(){
  27.         try {
  28.             scan = new Scanner(f);
  29.         } catch (FileNotFoundException e) {
  30.             e.printStackTrace();
  31.         }
  32.        
  33.         mainFrame = new JFrame();
  34.         mainFrame.setSize(500,200);
  35.         mainFrame.setLocationRelativeTo(null);
  36.         mainFrame.setLayout(null);
  37.         mainFrame.setResizable(false);
  38.         mainFrame.setAlwaysOnTop(true);
  39.         mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  40.        
  41.         okBtn = new JButton("OK");
  42.         okBtn.setBackground(Color.WHITE);
  43.         okBtn.setBounds(370,95,100,50);
  44.        
  45.         mainTxtFld = new JTextField();
  46.         mainTxtFld.setBounds(370,30,100,50);
  47.         mainTxtFld.setFont(new Font("Verdana", Font.BOLD, 25));
  48.         mainTxtFld.setDocument(new JTextFieldMaxLimit(5));
  49.         mainTxtFld.setMargin(new Insets(0,5,0,0));
  50.        
  51.         mainPanel = new JPanel();
  52.         mainPanel.setBackground(Color.gray);
  53.        
  54.         mainLabel = new JLabel();
  55.         mainLabel.setText("Wprowadź godzinę w postaci XX:XX");
  56.         mainLabel.setBounds(15,30,300, 50);
  57.         mainLabel.setFont(new Font("Verdana", Font.PLAIN, 16));
  58.        
  59.         otherLabel = new JLabel();
  60.         otherLabel.setBounds(25,100,300,50);
  61.         otherLabel.setFont(new Font("Comic Sans MS", Font.ITALIC, 15));
  62.        
  63.         mainFrame.add(otherLabel);
  64.         mainFrame.add(okBtn);
  65.         mainFrame.add(mainLabel);
  66.         mainFrame.add(mainTxtFld);
  67.         mainFrame.setVisible(true);
  68.        
  69.     }
  70.    
  71.     public static void setLabelTxt(int a, int b){
  72.         if(b == 0)
  73.         {
  74.             otherLabel.setText("aktualnie ustawiona godzina: "+a+":00");
  75.         }
  76.         if(b != 0)
  77.         {
  78.             otherLabel.setText("aktualnie ustawiona godzina: "+a+":"+b);
  79.         }
  80.         if(a==0)
  81.         {
  82.             otherLabel.setText("aktualnie ustawiona godzina: 00:"+b);
  83.         }
  84.         if((a==0&&b==0))
  85.         {
  86.             otherLabel.setText("aktualnie ustawiona godzina: 00:00");
  87.         }
  88.     }
  89.    
  90.    
  91.    
  92.    
  93.     public void getAndSet(){
  94.         String txt = mainTxtFld.getText();
  95.         //TODO
  96.         }
  97.    
  98.    
  99.    
  100.    
  101.    
  102.    
  103.     public void checkHour(){
  104.         Pattern pat = Pattern.compile("\\d{2}:\\d{2}");
  105.         Matcher mat = Pattern.matcher(mainTxtFld.getText());
  106.        
  107.         mat.matches();
  108.        
  109.        
  110.     }
  111.     public static void createFile() {
  112.         if(checkFileExist()==false)
  113.         {
  114.             try {
  115.                 f.createNewFile();
  116.             } catch (IOException e) {
  117.                 e.printStackTrace();
  118.             }
  119.         }
  120.         if(checkFileExist()==true)
  121.         {
  122.             return;
  123.         }
  124.     }
  125.    
  126.     public static boolean checkFileExist(){
  127.        
  128.         if(f.exists()){
  129.             return true;
  130.         }
  131.         else{
  132.             return false;
  133.         }
  134.     }
  135.     public static void deleteAndSaveToFile(int a, int b){
  136.        
  137.        
  138.         try {
  139.             pr = new PrintWriter(scr);
  140.         } catch (FileNotFoundException e1) {
  141.             e1.printStackTrace();
  142.         }
  143.        
  144.         f.delete();
  145.         try {
  146.             f.createNewFile();
  147.         } catch (IOException e) {
  148.             e.printStackTrace();
  149.         }
  150.        
  151.         pr.println(a+":"+b);
  152.         pr.close();
  153.        
  154.     }
  155.    
  156. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement