Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Color;
- import java.awt.Dialog;
- import java.awt.Font;
- import java.util.*;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.io.*;
- import javax.swing.*;
- import java.awt.*;
- import java.util.regex.*;
- public class shtdwnatMainFrame {
- JFrame mainFrame;
- static JTextField mainTxtFld;
- JPanel mainPanel;
- JLabel mainLabel;
- static JLabel otherLabel;
- JButton okBtn;
- static String scr ="C:\\ProgramData\\shtdwnatFile.txt";
- static File f = new File(scr);
- static Scanner scan;
- static PrintWriter pr;
- public shtdwnatMainFrame(){
- try {
- scan = new Scanner(f);
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- }
- mainFrame = new JFrame();
- mainFrame.setSize(500,200);
- mainFrame.setLocationRelativeTo(null);
- mainFrame.setLayout(null);
- mainFrame.setResizable(false);
- mainFrame.setAlwaysOnTop(true);
- mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- okBtn = new JButton("OK");
- okBtn.setBackground(Color.WHITE);
- okBtn.setBounds(370,95,100,50);
- mainTxtFld = new JTextField();
- mainTxtFld.setBounds(370,30,100,50);
- mainTxtFld.setFont(new Font("Verdana", Font.BOLD, 25));
- mainTxtFld.setDocument(new JTextFieldMaxLimit(5));
- mainTxtFld.setMargin(new Insets(0,5,0,0));
- mainPanel = new JPanel();
- mainPanel.setBackground(Color.gray);
- mainLabel = new JLabel();
- mainLabel.setText("Wprowadź godzinę w postaci XX:XX");
- mainLabel.setBounds(15,30,300, 50);
- mainLabel.setFont(new Font("Verdana", Font.PLAIN, 16));
- otherLabel = new JLabel();
- otherLabel.setBounds(25,100,300,50);
- otherLabel.setFont(new Font("Comic Sans MS", Font.ITALIC, 15));
- mainFrame.add(otherLabel);
- mainFrame.add(okBtn);
- mainFrame.add(mainLabel);
- mainFrame.add(mainTxtFld);
- mainFrame.setVisible(true);
- }
- public static void setLabelTxt(int a, int b){
- if(b == 0)
- {
- otherLabel.setText("aktualnie ustawiona godzina: "+a+":00");
- }
- if(b != 0)
- {
- otherLabel.setText("aktualnie ustawiona godzina: "+a+":"+b);
- }
- if(a==0)
- {
- otherLabel.setText("aktualnie ustawiona godzina: 00:"+b);
- }
- if((a==0&&b==0))
- {
- otherLabel.setText("aktualnie ustawiona godzina: 00:00");
- }
- }
- public void getAndSet(){
- String txt = mainTxtFld.getText();
- //TODO
- }
- public void checkHour(){
- Pattern pat = Pattern.compile("\\d{2}:\\d{2}");
- Matcher mat = Pattern.matcher(mainTxtFld.getText());
- mat.matches();
- }
- public static void createFile() {
- if(checkFileExist()==false)
- {
- try {
- f.createNewFile();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- if(checkFileExist()==true)
- {
- return;
- }
- }
- public static boolean checkFileExist(){
- if(f.exists()){
- return true;
- }
- else{
- return false;
- }
- }
- public static void deleteAndSaveToFile(int a, int b){
- try {
- pr = new PrintWriter(scr);
- } catch (FileNotFoundException e1) {
- e1.printStackTrace();
- }
- f.delete();
- try {
- f.createNewFile();
- } catch (IOException e) {
- e.printStackTrace();
- }
- pr.println(a+":"+b);
- pr.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement