Advertisement
Guest User

Untitled

a guest
Sep 17th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.58 KB | None | 0 0
  1. package greyknights;
  2.  
  3. import java.awt.event.*;
  4. import java.sql.Time;
  5. import java.util.*;
  6. import javax.swing.*;
  7.  
  8. public class GUI extends JFrame implements ActionListener {
  9.  
  10. private JMenuBar menubar;
  11. private JMenu file, info;
  12. private JMenuItem logout, close, help;
  13. private JTextField untf, pwtf;
  14. private JLabel unl, pwl;
  15. private JButton login, post;
  16. private JTextArea ta1, ta2;
  17. private JScrollPane sp1, sp2;
  18. private String un = "Gert-Jan";
  19. private String pw;
  20. private String total;
  21. private ArrayList<String> list;
  22. Calendar cal = Calendar.getInstance();
  23. Date date = new Date();
  24. Time time = new Time(date.getTime());
  25. int day = cal.get(Calendar.DATE);
  26. int month = cal.get(Calendar.MONTH) + 1;
  27. int year = cal.get(Calendar.YEAR);
  28.  
  29. public GUI() {
  30. setSize(700, 500);
  31. setTitle("Grey Knights Guild Application");
  32. setLayout(null);
  33.  
  34. list = new ArrayList<String>();
  35.  
  36. unl = new JLabel("Username:");
  37. unl.setBounds(160, 170, 200, 20);
  38. add(unl);
  39.  
  40. pwl = new JLabel("Password:");
  41. pwl.setBounds(160, 210, 200, 20);
  42. add(pwl);
  43.  
  44. untf = new JTextField();
  45. untf.setBounds(250, 170, 200, 20);
  46. add(untf);
  47.  
  48. pwtf = new JTextField();
  49. pwtf.setBounds(250, 210, 200, 20);
  50. add(pwtf);
  51.  
  52. login = new JButton("Login");
  53. login.setBounds(340, 250, 110, 20);
  54. login.addActionListener(this);
  55. add(login);
  56.  
  57. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  58. setVisible(true);
  59. }
  60.  
  61. public void mainScreenBuild() {
  62. menubar = new JMenuBar();
  63. setJMenuBar(menubar);
  64.  
  65. file = new JMenu("File");
  66. menubar.add(file);
  67. logout = new JMenuItem("Logout");
  68. logout.addActionListener(this);
  69. file.add(logout);
  70. close = new JMenuItem("Close");
  71. close.addActionListener(this);
  72. file.add(close);
  73.  
  74. ta1 = new JTextArea(200, 200);
  75. ta1.setEditable(false);
  76. sp1 = new JScrollPane(ta1);
  77. sp1.setBounds(10, 10, 660, 240);
  78. add(sp1);
  79.  
  80. ta2 = new JTextArea(200, 100);
  81. ta2.setBounds(10, 290, 660, 80);
  82. add(ta2);
  83.  
  84. post = new JButton("Post");
  85. post.setBounds(550, 380, 110, 20);
  86. post.addActionListener(this);
  87. add(post);
  88. }
  89.  
  90. public void Login(Boolean logscreen, Boolean mainscreen) {
  91. untf.setVisible(logscreen);
  92. pwtf.setVisible(logscreen);
  93. pwl.setVisible(logscreen);
  94. unl.setVisible(logscreen);
  95. login.setVisible(logscreen);
  96. if (!mainscreen) {
  97. menubar.removeAll();
  98. post.setVisible(false);
  99. sp1.setVisible(false);
  100. ta1.setVisible(false);
  101. ta2.setVisible(false);
  102. }
  103.  
  104. }
  105.  
  106. public void update() {
  107. for (String s : list) {
  108. if (s != null) {
  109. // s += "\n";
  110. total += s;
  111. }
  112. }
  113. ta1.setText(total);
  114. }
  115.  
  116. public void actionPerformed(ActionEvent e) {
  117. if (e.getSource() == login) {
  118. Login(false, true);
  119. mainScreenBuild();
  120. }
  121. if (e.getSource() == logout) {
  122. Login(true, false);
  123. }
  124. if (e.getSource() == close) {
  125. System.exit(0);
  126. }
  127. if (e.getSource() == post) {
  128. list.add("[" + day + "-" + month + "-" + year + "]: " + un + " - " + ta2.getText());
  129. update();
  130. }
  131. }
  132. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement