C:\Users\Man\Desktop\IA_FinaL_Submission_000307-0092\Product\IA_Netbeans_Project\src\ia\man\Home.java |
1
2
3
4
5
6 package ia.man;
7
8 import chrriis.common.UIUtils;
9 import chrriis.dj.nativeswing.swtimpl.NativeInterface;
10 import chrriis.dj.nativeswing.swtimpl.components.JWebBrowser;
11 import static ia.man.Main.createContent;
12 import java.awt.BorderLayout;
13 import java.awt.Color;
14 import java.awt.Dimension;
15 import java.awt.FlowLayout;
16 import static java.awt.SystemColor.desktop;
17 import java.awt.Toolkit;
18 import java.awt.event.ItemEvent;
19 import java.awt.event.ItemListener;
20 import java.io.BufferedReader;
21 import java.io.BufferedWriter;
22 import java.io.File;
23 import java.io.FileReader;
24 import java.io.FileWriter;
25 import java.io.IOException;
26 import java.net.URI;
27 import java.net.URISyntaxException;
28 import java.text.DateFormat;
29 import java.text.SimpleDateFormat;
30 import java.util.Date;
31 import java.util.logging.Level;
32 import java.util.logging.Logger;
33 import javax.swing.BorderFactory;
34 import javax.swing.JCheckBox;
35 import javax.swing.JComponent;
36 import javax.swing.JFrame;
37 import javax.swing.JOptionPane;
38 import javax.swing.JPanel;
39
40
41 *
42 * @author Seksan.Ma
43 */
44 public class Home extends javax.swing.JFrame {
45
46 static{
47 //NativeInterface.open();
48 //UIUtils.setPreferredLookAndFeel();
49 //twPanel.add(createContent());
50 }
51 /**
52 * Creates new form NewJFrame
53 */
54 User iUser = new User();
55
56 public String isLogin = "";
57
58 public Home() {
59
60
61 //NativeInterface.open();
62 //UIUtils.setPreferredLookAndFeel();
63
64 initComponents();
65
66 Toolkit toolkit = getToolkit();
67 Dimension size = toolkit.getScreenSize();
68 setLocation(size.width/2 - getWidth()/2, size.height/2 - getHeight()/2);
69
70 try
71 {
72 //twPanel.add(createContent());
73 }
74 catch(Exception e)
75 {
76 //Nothing
77 }
78
79
80
81
82 }
83
84 public Home(String id,String user,String email,String pass) throws IOException {
85
86 NativeInterface.open();
87 UIUtils.setPreferredLookAndFeel();
88
89 initComponents();
90
91 iUser.AssingValue(id, user, email, pass);
92
93 Toolkit toolkit = getToolkit();
94 Dimension size = toolkit.getScreenSize();
95 setLocation(size.width/2 - getWidth()/2, size.height/2 - getHeight()/2);
96
97 try
98 {
99 twPanel.add(createContent());
100 }
101 catch(Exception e)
102 {
103 //Nothing
104 }
105
106 DateFormat dateFormat = new SimpleDateFormat("MM-dd");
107 DateFormat yearFormat = new SimpleDateFormat("yyyy");
108 Date date = new Date();
109
110 String year = yearFormat.format(date);
111 //int bc_year = Integer.parseInt(year) - 543;
112 int bc_year = Integer.parseInt(year);
113
114 String Current_Date = String.valueOf(bc_year) + "-" + dateFormat.format(date);
115
116 lblDate.setText(Current_Date);
117
118 setTitle(user);
119 getInfo(id,user,email,pass);
120
121 //twPanel.add(createContent());
122
123 new Thread(() ->
124 {
125
126 while(true)
127 {
128 checkReady(lblDate.getText());
129 try {
130 Thread.sleep(500);
131 } catch (InterruptedException ex) {
132 Logger.getLogger(Home.class.getName()).log(Level.SEVERE, null, ex);
133 }
134 }
135 }).start();
136
137 }
138
139 public void checkLogin()
140 {
141 if(isLogin.equals(""))
142 {
143 Login Login = new Login();
144 this.setVisible(false);
145 Login.setVisible(true);
146 }
147 }
148
149
460 private void btnSaveMouseClicked(java.awt.event.MouseEvent evt) {
461 // TODO add your handling code here:
462 try {
463 // TODO add your handling code here:
464 updateData();
465 } catch (IOException ex) {
466 Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
467 }
468 }
469
470 private void btnToTwitterMouseClicked(java.awt.event.MouseEvent evt) {
471 try {
472 // TODO add your handling code here:
473
474 URI uri = new URI("https://twitter.com");
475 java.awt.Desktop.getDesktop().browse(uri);
476
477 } catch (URISyntaxException ex) {
478 Logger.getLogger(Home.class.getName()).log(Level.SEVERE, null, ex);
479 } catch (IOException ex) {
480 Logger.getLogger(Home.class.getName()).log(Level.SEVERE, null, ex);
481 }
482
483 }
484
485 private void btnlolMouseClicked(java.awt.event.MouseEvent evt) {
486 try {
487 // TODO add your handling code here:
488 //String cmd = "C:\\Riot Games\\Riot Client\\RiotClientServices.exe\" --launch-product=league_of_legends --launch-patchline=live";
489 //try {
490 // Runtime.getRuntime().exec(cmd);
491 //} catch (IOException ex) {
492 // Logger.getLogger(Home.class.getName()).log(Level.SEVERE, null, ex);
493 //}
494
495 //desktop.open("C:/Windows/System32/cmd.exe");
496
497 //Process p = Runtime.getRuntime().exec(new String[] {"C:\\Windows\\System32\\cmd.exe"});
498 ProcessBuilder p = new ProcessBuilder("C:\\Program Files (x86)\\Garena\\Garena\\Garena.exe");
499 p.start();
500
501 } catch (IOException ex) {
502 Logger.getLogger(Home.class.getName()).log(Level.SEVERE, null, ex);
503 }
504
505 }
506
507 private void btnPowershellMouseClicked(java.awt.event.MouseEvent evt) {
508 // TODO add your handling code here:
509 String cmd = "%SystemRoot%\\system32\\WindowsPowerShell\\v1.0\\powershell.exe";
510 try {
511 Runtime.getRuntime().exec(cmd);
512 } catch (IOException ex) {
513 Logger.getLogger(Home.class.getName()).log(Level.SEVERE, null, ex);
514 }
515 }
516
517 private void btnAtomMouseClicked(java.awt.event.MouseEvent evt) {
518 // TODO add your handling code here:
519 String cmd = "C:\\Users\\Man\\AppData\\Local\\atom\\atom.exe";
520 try {
521 Runtime.getRuntime().exec(cmd);
522 } catch (IOException ex) {
523 Logger.getLogger(Home.class.getName()).log(Level.SEVERE, null, ex);
524 }
525 }
526
527 private void btnTerminalMouseClicked(java.awt.event.MouseEvent evt) {
528 // TODO add your handling code here:
529 String cmd = "system32\\cmd.exe";
530 try {
531 Runtime.getRuntime().exec(cmd);
532 } catch (IOException ex) {
533 Logger.getLogger(Home.class.getName()).log(Level.SEVERE, null, ex);
534 }
535 }
536
537 private void btnPlannerMouseClicked(java.awt.event.MouseEvent evt) {
538 // TODO add your handling code here:
539 String id,user,email,pass;
540
541 id = iUser.getID();
542 user = iUser.getUser();
543 email = iUser.getEmail();
544 pass = iUser.getPass();
545
546 Planner planner = new Planner(id,user,email,pass);
547 planner.setVisible(true);
548 }
549
550 /**
551 * @param args the command line arguments
552 */
553 public static void main(String args[]) {
554
555 /* Set the Nimbus look and feel */
556 //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
557 /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
558 * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
559 */
560
561 NativeInterface.open();
562 UIUtils.setPreferredLookAndFeel();
563
564 try {
565 for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
566 if ("Nimbus".equals(info.getName())) {
567 javax.swing.UIManager.setLookAndFeel(info.getClassName());
568 break;
569 }
570 }
571 } catch (ClassNotFoundException ex) {
572 java.util.logging.Logger.getLogger(Home.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
573 } catch (InstantiationException ex) {
574 java.util.logging.Logger.getLogger(Home.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
575 } catch (IllegalAccessException ex) {
576 java.util.logging.Logger.getLogger(Home.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
577 } catch (javax.swing.UnsupportedLookAndFeelException ex) {
578 java.util.logging.Logger.getLogger(Home.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
579 }
580 //</editor-fold>
581 //</editor-fold>
582 /* Create and display the form */
583 java.awt.EventQueue.invokeLater(new Runnable() {
584 public void run() {
585 new Home().setVisible(true);
586 }
587 });
588
589 NativeInterface.runEventPump();
590
591 }
592
593 public void setTitle(String name)
594 {
595 String title = null;
596 SimpleDateFormat dateFormat = new SimpleDateFormat("HH");
597 Date date = new Date();
598
599 if(Integer.parseInt(dateFormat.format(date)) >= 5 && Integer.parseInt(dateFormat.format(date)) < 12)
600 {
601 title = "Good Morning";
602 }
603 else if(Integer.parseInt(dateFormat.format(date)) >= 12 && Integer.parseInt(dateFormat.format(date)) < 17)
604 {
605 title = "Good Afternoon";
606 }
607 else
608 {
609 title = "Good Evening";
610 }
611
612 lblTitle.setText(title + " " + name);
613 }
614
615
616 public void getInfo(String id,String user,String email,String pass)
617 {
618 txtID.setText(id);
619 txtUser.setText(user);
620 txtEmail.setText(email);
621 txtPass.setText(pass);
622 }
623
624 public void updateData() throws IOException
625 {
626 String id,user,email,pass,line;
627
628 String pFile = "User.txt";
629 String pFileTemp = "User_temp.txt";
630
631 id = txtID.getText();
632 user = txtUser.getText();
633 email = txtEmail.getText();
634 pass = txtPass.getText();
635
636 int n = JOptionPane.showConfirmDialog(
637 null,
638 "User information updated!",
639 "Please restart application.",
640 JOptionPane.YES_NO_OPTION);
641 //System.out.print(n); // Use n for response
642
643 if(n==0)
644 {
645 File File = new File(pFile);
646 File FileTemp = new File(pFileTemp);
647
648 BufferedWriter bw = new BufferedWriter( new FileWriter(FileTemp) );
649 BufferedReader br = new BufferedReader( new FileReader(File) );
650
651 while((line = br.readLine()) != null)
652 {
653 String[] arrFile = line.split("\\|");
654
655 if(arrFile[0].equals(id))
656 {
657 bw.write(id+"|"+user+"|"+email+"|"+pass);
658 }
659 else
660 {
661 bw.write(line);
662 }
663 bw.flush();
664 bw.newLine();
665 }
666
667 bw.close();
668 br.close();
669
670 File.delete();
671 boolean success = FileTemp.renameTo(File);
672 }
673 }
674
675 public void checkReady(String date)
676 {
677 String path = "Planner.txt";
678
679 File file = new File(path);
680
681 String line = null,
682 taskdate = null,
683 status = null;
684
685 try {
686
687 //lblReady.setForeground(Color.green);
688
689 BufferedReader br = new BufferedReader(new FileReader(file));
690
691 int i = 0;
692 int allDone = 0;
693 while ((line = br.readLine()) != null)
694 {
695 String[] array = line.split("\\|");
696 taskdate = array[2];
697 status = array[7];
698
699 if(status.equals("No") && taskdate.equals(date))
700 {
701 allDone++;
702 i++;
703 }
704 array = null;
705 }
706 br.close();
707
708 if(allDone == 0)
709 {
710 lblReady.setVisible(true);
711 btnlol.setVisible(true);
712 }
713 else
714 {
715 lblReady.setVisible(false);
716 btnlol.setVisible(false);
717 lblReady.setForeground(Color.red);
718 lblReady.setForeground(Color.green);
719 lblReady.setForeground(Color.red);
720 lblReady.setForeground(Color.green);
721 lblReady.setForeground(Color.red);
722 lblReady.setForeground(Color.green);
723 lblReady.setForeground(Color.red);
724 }
725 } catch (IOException e) {
726 e.printStackTrace();
727 }
728 }
729
730 public static JComponent createContent() {
731
732 JPanel contentPane = new JPanel(new BorderLayout());
733 contentPane.setBounds(0, 0, 750, 660);
734 try{
735
736 JPanel webBrowserPanel = new JPanel(new BorderLayout());
737 webBrowserPanel.setBorder(BorderFactory.createTitledBorder("Twitter"));
738 //webBrowserPanel.setBounds(38, 34, 133, 500);
739
740 final JWebBrowser webBrowser = new JWebBrowser();
741 webBrowser.navigate("https://twitter.com");
742 webBrowserPanel.add(webBrowser);
743 contentPane.add(webBrowserPanel,BorderLayout.CENTER);
744
745 }catch(Exception e)
746 {
747 //Nothing
748 }
749 return contentPane;
750 }
751
752 // Variables declaration - do not modify
753 private javax.swing.JButton btnAtom;
754 private javax.swing.JButton btnPlanner;
755 private javax.swing.JButton btnPowershell;
756 private javax.swing.JButton btnSave;
757 private javax.swing.JButton btnTerminal;
758 private javax.swing.JButton btnToTwitter;
759 private javax.swing.JButton btnlol;
760 private javax.swing.JFrame jFrame1;
761 private javax.swing.JLabel jLabel1;
762 private javax.swing.JLabel jLabel2;
763 private javax.swing.JLabel jLabel3;
764 private javax.swing.JLabel jLabel4;
765 private javax.swing.JLabel jLabel5;
766 private javax.swing.JLabel jLabel6;
767 private javax.swing.JLabel jLabel7;
768 private javax.swing.JLabel jLabel8;
769 private javax.swing.JPanel jPanel2;
770 private javax.swing.JPanel jPanel3;
771 private javax.swing.JTabbedPane jTabbedPane1;
772 private javax.swing.JLabel lblDate;
773 private javax.swing.JLabel lblReady;
774 private javax.swing.JLabel lblTitle;
775 private java.awt.Panel panel1;
776 private java.awt.Panel twPanel;
777 private javax.swing.JTextField txtEmail;
778 private javax.swing.JTextField txtID;
779 private javax.swing.JTextField txtPass;
780 private javax.swing.JTextField txtPassConfirm;
781 private javax.swing.JTextField txtUser;
782 // End of variables declaration
783 }
784