Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package greyknights;
- import java.awt.event.*;
- import java.sql.Time;
- import java.util.*;
- import javax.swing.*;
- public class GUI extends JFrame implements ActionListener {
- private JMenuBar menubar;
- private JMenu file, info;
- private JMenuItem logout, close, help;
- private JTextField untf, pwtf;
- private JLabel unl, pwl;
- private JButton login, post;
- private JTextArea ta1, ta2;
- private JScrollPane sp1, sp2;
- private String un = "Gert-Jan";
- private String pw;
- private String total;
- private ArrayList<String> list;
- Calendar cal = Calendar.getInstance();
- Date date = new Date();
- Time time = new Time(date.getTime());
- int day = cal.get(Calendar.DATE);
- int month = cal.get(Calendar.MONTH) + 1;
- int year = cal.get(Calendar.YEAR);
- public GUI() {
- setSize(700, 500);
- setTitle("Grey Knights Guild Application");
- setLayout(null);
- list = new ArrayList<String>();
- unl = new JLabel("Username:");
- unl.setBounds(160, 170, 200, 20);
- add(unl);
- pwl = new JLabel("Password:");
- pwl.setBounds(160, 210, 200, 20);
- add(pwl);
- untf = new JTextField();
- untf.setBounds(250, 170, 200, 20);
- add(untf);
- pwtf = new JTextField();
- pwtf.setBounds(250, 210, 200, 20);
- add(pwtf);
- login = new JButton("Login");
- login.setBounds(340, 250, 110, 20);
- login.addActionListener(this);
- add(login);
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- setVisible(true);
- }
- public void mainScreenBuild() {
- menubar = new JMenuBar();
- setJMenuBar(menubar);
- file = new JMenu("File");
- menubar.add(file);
- logout = new JMenuItem("Logout");
- logout.addActionListener(this);
- file.add(logout);
- close = new JMenuItem("Close");
- close.addActionListener(this);
- file.add(close);
- ta1 = new JTextArea(200, 200);
- ta1.setEditable(false);
- sp1 = new JScrollPane(ta1);
- sp1.setBounds(10, 10, 660, 240);
- add(sp1);
- ta2 = new JTextArea(200, 100);
- ta2.setBounds(10, 290, 660, 80);
- add(ta2);
- post = new JButton("Post");
- post.setBounds(550, 380, 110, 20);
- post.addActionListener(this);
- add(post);
- }
- public void Login(Boolean logscreen, Boolean mainscreen) {
- untf.setVisible(logscreen);
- pwtf.setVisible(logscreen);
- pwl.setVisible(logscreen);
- unl.setVisible(logscreen);
- login.setVisible(logscreen);
- if (!mainscreen) {
- menubar.removeAll();
- post.setVisible(false);
- sp1.setVisible(false);
- ta1.setVisible(false);
- ta2.setVisible(false);
- }
- }
- public void update() {
- for (String s : list) {
- if (s != null) {
- // s += "\n";
- total += s;
- }
- }
- ta1.setText(total);
- }
- public void actionPerformed(ActionEvent e) {
- if (e.getSource() == login) {
- Login(false, true);
- mainScreenBuild();
- }
- if (e.getSource() == logout) {
- Login(true, false);
- }
- if (e.getSource() == close) {
- System.exit(0);
- }
- if (e.getSource() == post) {
- list.add("[" + day + "-" + month + "-" + year + "]: " + un + " - " + ta2.getText());
- update();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement