Ejemplo n.º 1
0
  /** Creates new form AdminWindow */
  public AdminWindow(Socket _socket, String username) {
    initComponents();
    setTitle("Admin window");
    AdminUsername.setText(username);
    socket = _socket;
    try {
      streamOut = new DataOutputStream(new BufferedOutputStream(socket.getOutputStream()));
    } catch (IOException e1) {
      // TODO Auto-generated catch block
      System.out.println("Failed to open output stream.");
      e1.printStackTrace();
    }

    adminWindowThread = new AdminWindowThread(this, socket);
    adminWindowThread.start();

    /* posalji serveru zahtjev za friend listom */
    send("GIVEREGUSERS");

    this.setVisible(true);
    this.addWindowListener(
        new java.awt.event.WindowAdapter() {
          public void windowClosing(java.awt.event.WindowEvent e) {
            if (socket != null)
              try {
                socket.close();
              } catch (IOException ioe) {
                System.err.println("Error closing socket: " + ioe.getMessage());
              }
            Login.main(null); /* starta se ispocetka Login
                                (mora se bas startati main metoda, jer je tamo dodan listener
                                pri zatvaranju prozora, da se zatvori i socket/stream */
          }
        });
  }
Ejemplo n.º 2
0
  /**
   * This method is called from within the constructor to initialize the form. WARNING: Do NOT
   * modify this code. The content of this method is always regenerated by the Form Editor.
   */
  @SuppressWarnings("unchecked")
  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  private void initComponents() {

    AdminUsername = new javax.swing.JLabel();
    jLabel1 = new javax.swing.JLabel();
    jScrollPane1 = new javax.swing.JScrollPane();
    ListOfUsersAdmin = new javax.swing.JList();
    DelUserAdminButton = new javax.swing.JButton();
    jLabel2 = new javax.swing.JLabel();
    MaxMessBuffSize = new javax.swing.JTextField();
    jSeparator1 = new javax.swing.JSeparator();
    jLabel3 = new javax.swing.JLabel();
    ServerIPAdmin = new javax.swing.JTextField();
    jLabel4 = new javax.swing.JLabel();
    ServerPortAdmin = new javax.swing.JTextField();
    jLabel5 = new javax.swing.JLabel();
    MaxUserNoAdmin = new javax.swing.JTextField();
    AddUserAdminButton = new javax.swing.JButton();
    SaveButtonAdmin = new javax.swing.JButton();
    CancelButtonAdmin = new javax.swing.JButton();
    jMenuBar1 = new javax.swing.JMenuBar();
    jMenu1 = new javax.swing.JMenu();
    AddUserAdminMenu = new javax.swing.JMenuItem();
    DelUserAdminMenu = new javax.swing.JMenuItem();
    jSeparator2 = new javax.swing.JPopupMenu.Separator();
    AdminCloseMenu = new javax.swing.JMenuItem();
    SetServerParamsMenu = new javax.swing.JMenu();
    jMenuItem3 = new javax.swing.JMenuItem();

    setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

    AdminUsername.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
    AdminUsername.setText("Username");

    jLabel1.setFont(new java.awt.Font("Tahoma", 0, 14));
    jLabel1.setText("List of all users:");

    jScrollPane1.setViewportView(ListOfUsersAdmin);

    DelUserAdminButton.setText("Delete user");
    DelUserAdminButton.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
            DelUserAdminButtonActionPerformed(evt);
          }
        });

    jLabel2.setText("Max message buffer size for user (in bytes):");

    MaxMessBuffSize.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
            MaxMessBuffSizeActionPerformed(evt);
          }
        });

    jLabel3.setText("IP address of the server:");

    jLabel4.setText("Server port:");

    ServerPortAdmin.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
            ServerPortAdminActionPerformed(evt);
          }
        });

    jLabel5.setText("Max number of users logged in:");

    AddUserAdminButton.setText("Add new user");
    AddUserAdminButton.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
            AddUserAdminButtonActionPerformed(evt);
          }
        });

    SaveButtonAdmin.setText("Save");
    SaveButtonAdmin.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
            SaveButtonAdminActionPerformed(evt);
          }
        });

    CancelButtonAdmin.setText("Cancel");

    jMenu1.setText("File");

    AddUserAdminMenu.setAccelerator(
        javax.swing.KeyStroke.getKeyStroke(
            java.awt.event.KeyEvent.VK_A, java.awt.event.InputEvent.CTRL_MASK));
    AddUserAdminMenu.setText("Add new user");
    jMenu1.add(AddUserAdminMenu);

    DelUserAdminMenu.setAccelerator(
        javax.swing.KeyStroke.getKeyStroke(
            java.awt.event.KeyEvent.VK_DELETE, java.awt.event.InputEvent.CTRL_MASK));
    DelUserAdminMenu.setText("Delete user");
    jMenu1.add(DelUserAdminMenu);
    jMenu1.add(jSeparator2);

    AdminCloseMenu.setAccelerator(
        javax.swing.KeyStroke.getKeyStroke(
            java.awt.event.KeyEvent.VK_Q, java.awt.event.InputEvent.CTRL_MASK));
    AdminCloseMenu.setText("Close");
    AdminCloseMenu.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
            AdminCloseMenuActionPerformed(evt);
          }
        });
    jMenu1.add(AdminCloseMenu);

    jMenuBar1.add(jMenu1);

    SetServerParamsMenu.setText("Edit");

    jMenuItem3.setText("Set server parameters");
    SetServerParamsMenu.add(jMenuItem3);

    jMenuBar1.add(SetServerParamsMenu);

    setJMenuBar(jMenuBar1);

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
        layout
            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(
                layout
                    .createSequentialGroup()
                    .addContainerGap()
                    .addGroup(
                        layout
                            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(
                                AdminUsername,
                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                386,
                                Short.MAX_VALUE)
                            .addGroup(
                                layout
                                    .createSequentialGroup()
                                    .addGroup(
                                        layout
                                            .createParallelGroup(
                                                javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(
                                                jScrollPane1,
                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                155,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(
                                                jLabel1,
                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                124,
                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGap(18, 18, 18)
                                    .addGroup(
                                        layout
                                            .createParallelGroup(
                                                javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(AddUserAdminButton)
                                            .addComponent(jLabel5)
                                            .addComponent(jLabel4)
                                            .addComponent(jLabel3)
                                            .addComponent(
                                                MaxMessBuffSize,
                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                75,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(
                                                jLabel2,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                Short.MAX_VALUE)
                                            .addComponent(DelUserAdminButton)
                                            .addComponent(
                                                jSeparator1,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                213,
                                                Short.MAX_VALUE)
                                            .addComponent(
                                                ServerIPAdmin,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                213,
                                                Short.MAX_VALUE)
                                            .addComponent(
                                                ServerPortAdmin,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                213,
                                                Short.MAX_VALUE)
                                            .addComponent(
                                                MaxUserNoAdmin,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                213,
                                                Short.MAX_VALUE)
                                            .addGroup(
                                                layout
                                                    .createSequentialGroup()
                                                    .addComponent(
                                                        SaveButtonAdmin,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        90,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                    .addGap(18, 18, 18)
                                                    .addComponent(
                                                        CancelButtonAdmin,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        90,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)))))
                    .addContainerGap()));
    layout.setVerticalGroup(
        layout
            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(
                layout
                    .createSequentialGroup()
                    .addContainerGap()
                    .addComponent(
                        AdminUsername,
                        javax.swing.GroupLayout.PREFERRED_SIZE,
                        35,
                        javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(18, 18, 18)
                    .addGroup(
                        layout
                            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(
                                jLabel1,
                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                28,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(AddUserAdminButton))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(
                        layout
                            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(
                                jScrollPane1,
                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                313,
                                Short.MAX_VALUE)
                            .addGroup(
                                layout
                                    .createSequentialGroup()
                                    .addComponent(DelUserAdminButton)
                                    .addGap(18, 18, 18)
                                    .addComponent(jLabel2)
                                    .addPreferredGap(
                                        javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(
                                        MaxMessBuffSize,
                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGap(18, 18, 18)
                                    .addComponent(
                                        jSeparator1,
                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                        10,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(
                                        javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(jLabel3)
                                    .addPreferredGap(
                                        javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(
                                        ServerIPAdmin,
                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(
                                        javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(jLabel4)
                                    .addPreferredGap(
                                        javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(
                                        ServerPortAdmin,
                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(
                                        javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(jLabel5)
                                    .addPreferredGap(
                                        javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(
                                        MaxUserNoAdmin,
                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(
                                        javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                                        28,
                                        Short.MAX_VALUE)
                                    .addGroup(
                                        layout
                                            .createParallelGroup(
                                                javax.swing.GroupLayout.Alignment.BASELINE)
                                            .addComponent(SaveButtonAdmin)
                                            .addComponent(CancelButtonAdmin))))
                    .addContainerGap()));

    pack();
  } // </editor-fold>//GEN-END:initComponents