Ejemplo n.º 1
0
    BusinessPane() {
      setLayout(null);
      add(info_label);
      info_label.setBounds(10, 10, 300, 20);
      info_label.setFont(new Font("TimesRoman", Font.BOLD, 12));
      add(info_scroll);
      info_scroll.setBounds(5, 35, 615, 400);
      info_name.add(columnName[0]);
      info_name.add(columnName[1]);
      info_name.add(columnName[2]);
      info_name.add(columnName[3]);
      DefaultTableModel info_model = new DefaultTableModel(info_data, info_name);
      info_table.setModel(info_model);
      info_table.getColumnModel().getColumn(0).setWidth(25);
      info_table.addMouseListener(
          new MouseAdapter() {
            public void mouseClicked(MouseEvent e) {
              if (e.getClickCount() == 1) { // click to trigger the event
                // show_selected();
                // System.out.print(table_selected(0));
              }
            }
          });

      add(B_refresh);
      B_refresh.setMargin(new java.awt.Insets(1, 1, 1, 1));
      B_refresh.setBounds(530, 440, 90, 25);
      B_refresh.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent event) {
              update_table();
            }
          });
    }
Ejemplo n.º 2
0
  public aboutsw() {
    b1 = new JButton();
    l1 = new JLabel();
    l2 = new JLabel();
    l3 = new JLabel();
    l4 = new JLabel();
    l5 = new JLabel();

    getContentPane().setLayout(null);
    setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    setResizable(false);
    setUndecorated(true);

    getAccessibleContext().setAccessibleName("About");

    b1.setText("Close");
    getContentPane().add(b1);
    b1.setBounds(250, 180, 80, 25);
    b1.addActionListener(new closeListener());

    l1.setFont(new Font("Microsoft Sans Serif", 0, 20));
    l1.setForeground(new java.awt.Color(153, 153, 255));
    l1.setText("Plateform  : ");
    getContentPane().add(l1);
    l1.setBounds(50, 70, 120, 20);

    l2.setText("Gift Sales & Management System");
    l2.setFont(new Font("Century Schoolbook", 1, 16));
    l2.setForeground(new java.awt.Color(255, 51, 51));
    getContentPane().add(l2);
    l2.setBounds(34, 10, 410, 30);

    l3.setForeground(new Color(0, 0, 153));
    l3.setText("Windows 98 / 2000 / XP / Vista / 7");
    getContentPane().add(l3);
    l3.setBounds(100, 95, 200, 20);

    l4.setText("Powered by :");
    l4.setFont(new Font("Microsoft Sans Serif", 0, 18));
    l4.setForeground(new java.awt.Color(153, 153, 255));
    getContentPane().add(l4);
    l4.setBounds(50, 120, 130, 20);

    l5.setText("Amit Kumar Sah");
    l5.setFont(new Font("Microsoft Sans Serif", 0, 18));
    getContentPane().add(l5);
    l5.setBounds(100, 150, 190, 20);
    l5.setForeground(new Color(100, 100, 51));

    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    setBounds((screenSize.width - 400) / 2, (screenSize.height - 220) / 2, 450, 240);

    setVisible(true);
  }
Ejemplo n.º 3
0
  // Method to build the dialog box for help.
  private void buildDialogBox() {
    // Set the JDialog window properties.
    setTitle("Stack Trace Detail");
    setResizable(false);
    setSize(dialogWidth, dialogHeight);

    // Append the stack trace output to the display area.
    displayArea.append(eStackTrace);

    // Create horizontal and vertical scrollbars for box.
    displayBox = Box.createHorizontalBox();
    displayBox = Box.createVerticalBox();

    // Add a JScrollPane to the Box.
    displayBox.add(new JScrollPane(displayArea));

    // Define behaviors of container.
    c.setLayout(null);
    c.add(displayBox);
    c.add(okButton);

    // Set scroll pane bounds.
    displayBox.setBounds(
        (dialogWidth / 2) - ((displayAreaWidth / 2) + 2),
        (top + (offsetMargin / 2)),
        displayAreaWidth,
        displayAreaHeight);

    // Set the behaviors, bounds and action listener for the button.
    okButton.setBounds(
        (dialogWidth / 2) - (buttonWidth / 2),
        (displayAreaHeight + offsetMargin),
        buttonWidth,
        buttonHeight);

    // Set the font to the platform default Font for the object with the
    // properties of bold and font size of 11.
    okButton.setFont(new Font(okButton.getFont().getName(), Font.BOLD, 11));

    // The class implements the ActionListener interface and therefore
    // provides an implementation of the actionPerformed() method.  When a
    // class implements ActionListener, the instance handler returns an
    // ActionListener.  The ActionListener then performs actionPerformed()
    // method on an ActionEvent.
    okButton.addActionListener(this);

    // Set the screen and display dialog window in relation to screen size.
    setLocation((dim.width / 2) - (dialogWidth / 2), (dim.height / 2) - (dialogHeight / 2));

    // Display JDialog.
    show();
  } // End of buildDialogBox method.
Ejemplo n.º 4
0
 /** sets this user to be an admin */
 public void setAdmin() {
   admin = true;
   popup.add("kick user").addActionListener(myAction);
   if (chanAdmin) {
     butCreate.setEnabled(true);
   }
 }
Ejemplo n.º 5
0
 /**
  * used to manage the connection icons to signify connection and secure status
  *
  * @param b true if connected
  */
 public void setConnected(boolean b) {
   if (b) {
     conIcon.setIcon(conYes);
     conIcon.setToolTipText("Connected");
     secIcon.setIcon(secYes);
     secIcon.setToolTipText("Secure Connection");
     butChannel.setEnabled(true);
   } else {
     conIcon.setIcon(conNo);
     conIcon.setToolTipText("Not Connected");
     secIcon.setIcon(secNo);
     secIcon.setToolTipText("Connection not Secured");
     butChannel.setEnabled(false);
     butCreate.setEnabled(false);
     butInvite.setEnabled(false);
   }
 }
Ejemplo n.º 6
0
 ToolPanel() {
   this.setRollover(true);
   this.setFloatable(false);
   addSeparator();
   add(button_connect);
   button_connect.setToolTipText("Connect");
   button_connect.addActionListener(
       new ActionListener() {
         public void actionPerformed(ActionEvent event) {
           // device_Initial();
         }
       });
   add(button_disconnect);
   button_disconnect.setToolTipText("Disconnect");
   button_disconnect.setEnabled(false);
   button_disconnect.addActionListener(
       new ActionListener() {
         public void actionPerformed(ActionEvent event) {
           // device_close();
         }
       });
 }
Ejemplo n.º 7
0
  private void initialise() {
    setSize(180, 120);
    setLocation(300, 200);
    setTitle("Working...");
    setVisible(false);
    setModal(true);
    setResizable(false);
    setDefaultCloseOperation(0);
    _stopped = false;
    getContentPane().setLayout(new BorderLayout());

    JPanel topPanel = new JPanel();
    topPanel.setLayout(new BorderLayout());

    busyTextLabel = new JLabel("Busy - please wait");
    topPanel.add(busyTextLabel, "Center");

    busyIcon = FTAUtilities.loadImageIcon("busy.gif");
    busyIconLabel = new JLabel(busyIcon);
    topPanel.add(busyIconLabel, "West");

    progressBar = new JProgressBar();
    topPanel.add(progressBar, "South");

    getContentPane().add(topPanel);

    stopButton = new JButton("Stop");
    stopButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            // System.out.println("'Stop' button pressed");
            _stopped = true;
          }
        });
    this.addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            _stopped = true;
          }
        });

    // create panel to hold buttons
    JPanel buttonPanel = new JPanel(new FlowLayout());
    buttonPanel.add(stopButton);

    getContentPane().add(buttonPanel, BorderLayout.SOUTH);
  }
Ejemplo n.º 8
0
    // Method to build the dialog box for help.
    private void buildDialogBox() {
      // Set the JDialog window properties.
      setTitle("Learning about Java");
      setResizable(false);
      setSize(dialogWidth, dialogHeight);

      // Define behaviors of container.
      c.setLayout(null);
      c.setBackground(Color.cyan);
      c.add(image);
      c.add(okButton);

      // Set the bounds for the image.
      image.setBounds(
          (dialogWidth / 2) - (imageWidth / 2),
          (top + (offsetMargin / 2)),
          imageWidth,
          imageHeight);

      // Set the behaviors, bounds and action listener for the button.
      okButton.setBounds(
          (dialogWidth / 2) - (buttonWidth / 2),
          (imageHeight + (int) 1.5 * offsetMargin),
          buttonWidth,
          buttonHeight);

      // Set the font to the platform default Font for the object with the
      // properties of bold and font size of 11.
      okButton.setFont(new Font(okButton.getFont().getName(), Font.BOLD, 11));

      // Set foreground and background of JButton(s).
      okButton.setForeground(Color.white);
      okButton.setBackground(Color.blue);

      // The class implements the ActionListener interface and therefore
      // provides an implementation of the actionPerformed() method.  When a
      // class implements ActionListener, the instance handler returns an
      // ActionListener.  The ActionListener then performs actionPerformed()
      // method on an ActionEvent.
      okButton.addActionListener(this);

      // Set the screen and display dialog window in relation to screen size.
      dim = tk.getScreenSize();
      setLocation((dim.width / 2) - (dialogWidth / 2), (dim.height / 2) - (dialogHeight / 2));

      // Display the dialog.
      show();
    } // End of buildDialogBox method.
  /// Constructor of WindowApplication class
  public WindowApplication(String title) throws IOException {
    /// Add title and specify size of window
    super(title);
    setSize(850, 700);
    addWindowListener(new WindowDestroyer());

    /// Initialize list and data
    String S[] = {"Source 1", "Source 2", "Source 3"};
    String D[] = {"Dest. 1", "Dest. 2", "Dest. 3", "Dest. 4"};
    String R[] = new String[13];
    String P[] = {"Audio", "Video", "Text"};

    for (int i = 0; i < 13; i++) {
      R[i] = "Router" + String.valueOf(i + 1);
    }

    /// Initialize variables for displaying data on window
    src = new JLabel("Select Source");
    dst = new JLabel("Select Destination");
    rter = new JLabel("Select Router");

    /// List display
    sourceList = new JList();
    routerList = new JList();
    destList = new JList();
    Source = new JScrollPane(sourceList);
    Dest = new JScrollPane(destList);
    Router = new JScrollPane(routerList);

    sourceList.setListData(S);
    destList.setListData(D);
    routerList.setListData(R);

    /// Router info display
    changePrior = new JLabel("Change Priority (0: Highest - 2: Lowest)");
    audio = new JLabel("AUDIO");
    audioVal = new JTextField("");
    aPlus = new JButton("+");
    aMinus = new JButton("-");
    video = new JLabel("VIDEO");
    videoVal = new JTextField("");
    vPlus = new JButton("+");
    vMinus = new JButton("-");
    text = new JLabel("TEXT");
    textVal = new JTextField("");
    tPlus = new JButton("+");
    tMinus = new JButton("-");

    /// Packet type display
    packTypeLabel = new JLabel("Packet Type");
    packTypeList = new JList();
    packType = new JScrollPane(packTypeList);
    packTypeList.setListData(P);

    /// Loss, delay, throughput display
    lossLabel = new JLabel("Loss");
    lossVal = new JTextField("");
    delayLabel = new JLabel("Delay (ms)");
    delayVal = new JTextField("");
    throuLabel = new JLabel("Throughput (Mbps)");
    throuVal = new JTextField("");

    /// Initialize data variable for manipulating lists
    sourceList.addListSelectionListener(new ListHandler());
    destList.addListSelectionListener(new ListHandler());
    routerList.addListSelectionListener(new ListHandler());
    packTypeList.addListSelectionListener(new ListHandler());

    /// Initialize drawing field
    drawTest = new DrawingTester(this);

    /// Initialize data variable for manipulating buttons
    aPlus.addActionListener(new ActionHandler());
    aMinus.addActionListener(new ActionHandler());
    vPlus.addActionListener(new ActionHandler());
    vMinus.addActionListener(new ActionHandler());
    tPlus.addActionListener(new ActionHandler());
    tMinus.addActionListener(new ActionHandler());

    /// Define layout display
    getContentPane().setLayout(null);
    getContentPane().add(drawTest);

    getContentPane().add(src);
    getContentPane().add(dst);
    getContentPane().add(rter);
    getContentPane().add(Source);
    getContentPane().add(Dest);
    getContentPane().add(Router);

    getContentPane().add(changePrior);
    getContentPane().add(audio);
    getContentPane().add(audioVal);
    getContentPane().add(aPlus);
    getContentPane().add(aMinus);
    getContentPane().add(video);
    getContentPane().add(videoVal);
    getContentPane().add(vPlus);
    getContentPane().add(vMinus);
    getContentPane().add(text);
    getContentPane().add(textVal);
    getContentPane().add(tPlus);
    getContentPane().add(tMinus);

    getContentPane().add(packTypeLabel);
    getContentPane().add(packType);

    getContentPane().add(lossLabel);
    getContentPane().add(lossVal);
    getContentPane().add(delayLabel);
    getContentPane().add(delayVal);
    getContentPane().add(throuLabel);
    getContentPane().add(throuVal);

    /// Set bound for display components
    drawTest.setBounds(10, 10, 650, 500);

    src.setBounds(700, 10, 150, 30);
    Source.setBounds(700, 40, 80, 60);

    dst.setBounds(700, 110, 150, 30);
    Dest.setBounds(700, 140, 80, 80);

    rter.setBounds(100, 520, 150, 30);
    Router.setBounds(100, 550, 80, 100);

    changePrior.setBounds(320, 520, 260, 30);
    audio.setBounds(320, 550, 80, 25);
    aPlus.setBounds(380, 550, 45, 25);
    audioVal.setBounds(430, 550, 50, 25);
    aMinus.setBounds(485, 550, 45, 25);

    video.setBounds(320, 585, 80, 25);
    vPlus.setBounds(380, 585, 45, 25);
    videoVal.setBounds(430, 585, 50, 25);
    vMinus.setBounds(485, 585, 45, 25);

    text.setBounds(320, 620, 80, 25);
    tPlus.setBounds(380, 620, 45, 25);
    textVal.setBounds(430, 620, 50, 25);
    tMinus.setBounds(485, 620, 45, 25);

    lossLabel.setBounds(700, 250, 80, 30);
    lossVal.setBounds(700, 280, 100, 30);
    delayLabel.setBounds(700, 320, 80, 30);
    delayVal.setBounds(700, 350, 80, 30);
    throuLabel.setBounds(700, 390, 120, 30);
    throuVal.setBounds(700, 420, 80, 30);

    packTypeLabel.setBounds(620, 520, 80, 30);
    packType.setBounds(620, 550, 60, 60);

    /// Display all the components
    setVisible(true);
  }
Ejemplo n.º 10
0
  // Method builds button action listeners.
  private void buildButtonActionListeners() {
    /*
    || Section adds action listeners for buttons:
    || ==========================================
    ||  - sendButton
    ||  - receiveButton
    ||  - JDBCButton
    ||  - fileButton
    ||  - rSendButton
    ||  - rReceiveButton
    */

    // Send button.
    sendButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            // Send message.
            setMessage(sender, receiver);
          } // End of actionPerformed() method.
        }); // End of sendButton action listener.

    // Receive button.
    receiveButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            // Receive message.
            getMessage(receiver);
          } // End of actionPerformed() method.
        }); // End of receiveButton action listener.

    // JDBC button.
    JDBCButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            // Print message until implemented.
            System.out.println("Database Connection .... ");
          } // End of actionPerformed() method.
        }); // End of JDBCButton action listener.

    // File button.
    fileButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            // Print message until implemented.
            System.out.println("SQL Submission .... ");
          } // End of actionPerformed() method.
        }); // End of fileButton action listener.

    // Send button.
    rSendButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            // Print message until implemented.
            System.out.println("Remote Sending .... ");
          } // End of actionPerformed() method.
        }); // End of rSendButton action listener.

    // Receive button.
    rReceiveButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            // Print message until implemented.
            System.out.println("Remote Receiving .... ");
          } // End of actionPerformed() method.
        }); // End of rReceiveButton action listener.
  } // End of buildButtonActionListeners() method.
Ejemplo n.º 11
0
    ModiPanel(MemberPane mp, BusinessPane bp) {
      this.member_pane = mp;
      this.busi_pane = bp;
      setLayout(null);
      add(member_title);
      member_title.setBounds(20, 10, 80, 20);
      add(member_id);
      member_id.setBounds(20, 35, 80, 20);
      add(member_name);
      member_name.setBounds(20, 60, 80, 20);
      add(member_tele);
      member_tele.setBounds(20, 85, 80, 20);
      add(member_level);
      member_level.setBounds(20, 110, 80, 20);
      add(member_bal);
      member_bal.setBounds(20, 135, 80, 20);
      add(text_id);
      text_id.setBounds(100, 35, 180, 20);
      add(text_name);
      text_name.setBounds(100, 60, 180, 20);
      add(text_tele);
      text_tele.setBounds(100, 85, 180, 20);
      /*add(text_level);
      text_level.setBounds(100,90,180,20);*/
      add(text_bal);
      text_bal.setBounds(100, 135, 180, 20);
      add(spinner_level);
      spinner_level.setBounds(100, 110, 180, 20);

      add(trans_title);
      trans_title.setBounds(20, 220, 80, 20);
      add(trans_member);
      trans_member.setBounds(20, 245, 80, 20);
      add(trans_money);
      trans_money.setBounds(20, 270, 80, 20);
      add(text_member);
      text_member.setBounds(100, 245, 180, 20);
      add(text_money);
      text_money.setBounds(100, 270, 180, 20);

      add(button_add);
      button_add.setBounds(100, 165, 100, 25);
      button_add.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              try {
                System.out.println("add");
                mm.addMember(
                    text_id.getText(),
                    text_name.getText(),
                    text_tele.getText(),
                    spinner_level.getValue().toString(),
                    text_bal.getText());
                member_pane.update_table();
              } catch (Exception ex) {
                JOptionPane.showMessageDialog(
                    mainFrame, "Adding Failure!", "ERROR", JOptionPane.ERROR_MESSAGE);
              }

              // dialog_send.setVisible(false);
            }
          });

      add(button_add_trans);
      button_add_trans.setBounds(100, 305, 100, 25);
      button_add_trans.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              try {
                System.out.println("add transaction");
                Business busi =
                    new Business(
                        text_member.getText(), Float.valueOf(text_money.getText()).floatValue());
                busi.addBusi();
                busi_pane.update_table();
              } catch (Exception ex) {
                JOptionPane.showMessageDialog(
                    mainFrame, "Adding Failure!", "ERROR", JOptionPane.ERROR_MESSAGE);
              }

              // dialog_send.setVisible(false);
            }
          });

      // set font;
      member_title.setFont(font_title);
      member_id.setFont(font);
      member_name.setFont(font);
      member_tele.setFont(font);
      member_level.setFont(font);
      member_bal.setFont(font);
      button_add.setFont(font);
      trans_title.setFont(font_title);
      trans_member.setFont(font);
      trans_money.setFont(font);
      button_add_trans.setFont(font);
    }
Ejemplo n.º 12
0
    MemberPane() {
      setLayout(null);
      /*add(B_add);
      B_add.setMargin(new java.awt.Insets(1, 1, 1, 1));
      B_add.setBounds(230,440,90,25);
      B_add.addActionListener(new ActionListener()
            {
                public void actionPerformed(ActionEvent event){
                	String[] data={T_title.getText(),T_director.getText(),T_actor.getText(),T_actress.getText()};
                	DBcore.addData("movie_info",data);
                	DBcore.showDB("movie_info", movie_column,info_data,info_table);
                }
            });*/
      add(B_delete);
      B_delete.setMargin(new java.awt.Insets(1, 1, 1, 1));
      B_delete.setBounds(330, 440, 90, 25);
      B_delete.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent event) {
              if (id != null) {
                int confirm =
                    JOptionPane.showConfirmDialog(
                        mainFrame, "是否删除该用户?", "删除提示", JOptionPane.OK_CANCEL_OPTION);
                if (confirm == JOptionPane.OK_OPTION) {
                  Database.deleteData("member", "id", id);
                }
                T_title.setText("");
                T_director.setText("");
                T_actor.setText("");
                T_actress.setText("");
              }
              update_table();
            }
          });
      /*add(B_edit);
      B_edit.setMargin(new java.awt.Insets(1, 1, 1, 1));
      B_edit.setBounds(430,440,90,25);
      B_edit.addActionListener(new ActionListener()
            {
                public void actionPerformed(ActionEvent event){
                	String[] data={T_title.getText(),T_director.getText(),T_actor.getText(),T_actress.getText()};
                	if(id!=null){
                	DBcore.updateData("movie_info", "no", id, detail_column, data);
                	}
                	DBcore.showDB("movie_info", movie_column,info_data,info_table);
                }
            });*/

      add(B_refresh);
      B_refresh.setMargin(new java.awt.Insets(1, 1, 1, 1));
      B_refresh.setBounds(530, 440, 90, 25);
      B_refresh.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent event) {
              update_table();
            }
          });

      add(info_label);
      info_label.setBounds(10, 10, 300, 20);
      info_label.setFont(new Font("TimesRoman", Font.BOLD, 12));
      add(info_scroll);
      info_scroll.setBounds(5, 35, 615, 400);
      info_name.add(columnName[0]);
      info_name.add(columnName[1]);
      info_name.add(columnName[2]);
      info_name.add(columnName[3]);
      info_name.add(columnName[4]);
      DefaultTableModel info_model = new DefaultTableModel(info_data, info_name);
      info_table.setModel(info_model);
      info_table.getColumnModel().getColumn(0).setWidth(25);
      info_table.addMouseListener(
          new MouseAdapter() {
            public void mouseClicked(MouseEvent e) {
              if (e.getClickCount() == 1) { // click to trigger the event
                show_selected();
                System.out.print(table_selected(0));
              }
            }
          });
      /*add(edit_panel);
      Border border=BorderFactory.createEtchedBorder(1);
      Border title1=BorderFactory.createTitledBorder(border,"Edit Area");
      edit_panel.setBorder(title1);
      edit_panel.setBounds(5,470,615,125);
      edit_panel.setLayout(null);
      edit_panel.add(L_title);
      edit_panel.add(L_director);
      edit_panel.add(L_actor);
      edit_panel.add(L_actress);
      edit_panel.add(T_title);
      edit_panel.add(T_director);
      edit_panel.add(T_actor);
      edit_panel.add(T_actress);
      L_title.setBounds(40,30,100,25);
      L_director.setBounds(325,30,100,25);
      L_actor.setBounds(40,75,100,25);
      L_actress.setBounds(325,75,100,25);
      T_title.setBounds(140,30,150,25);
      T_director.setBounds(425,30,150,25);
      T_actor.setBounds(140,75,150,25);
      T_actress.setBounds(425,75,150,25);*/
    }
Ejemplo n.º 13
0
  /** Initializes the graphical components */
  public void init() {
    username = getParameter("username");
    if (username == null) {
      username =
          JOptionPane.showInputDialog(
              this, "Please enter a username", "Login", JOptionPane.QUESTION_MESSAGE);
    }
    try {
      PORT = Integer.valueOf(getParameter("port")).intValue();
    } catch (NumberFormatException e) {
      PORT = 42412;
    }

    URL url = getDocumentBase();
    site = url.getHost();
    locationURL = "http://" + site + ":" + url.getPort() + "/" + url.getPath();

    setSize(615, 362);
    c = getContentPane();

    c.setBackground(new Color(224, 224, 224));

    if (site == null || locationURL == null) {
      c.add(new JLabel("ERROR: did not recieve needed data from page"));
    }

    myAction = new MyAction();
    myKeyListener = new MyKeyListener();
    myMouseListener = new MyMouseListener();
    myHyperlinkListener = new MyHyperlinkListener();

    c.setLayout(null);

    cboChannels = new JComboBox();
    cboChannels.setBounds(5, 5, 150, 24);

    butChannel = new JButton("Join");
    butChannel.setToolTipText("Join channel");
    butChannel.addActionListener(myAction);
    butChannel.setBounds(160, 5, 60, 24);

    butCreate = new JButton("Create");
    butCreate.setToolTipText("Create new channel");
    butCreate.addActionListener(myAction);
    butCreate.setBounds(230, 5, 100, 24);
    butCreate.setEnabled(false);

    butInvite = new JButton("Invite");
    butInvite.setToolTipText("Invite Friend");
    butInvite.addActionListener(myAction);
    butInvite.setBounds(340, 5, 80, 24);

    mainChat = new ChatPane(this);
    textScroller =
        new JScrollPane(
            mainChat,
            JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
            JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    textScroller.setBounds(5, 34, 500, 270);

    userList = new JList();
    userList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    userList.setCellRenderer(new MyCellRenderer());
    userList.setBackground(new Color(249, 249, 250));
    JScrollPane userScroller = new JScrollPane(userList);
    userScroller.setBounds(510, 34, 100, 297);

    messageText = new JTextField();
    messageText.setBounds(5, 309, 500, 22);
    messageText.setColumns(10);
    messageText.setBackground(new Color(249, 249, 250));

    JMenuItem item;
    popup = new JPopupMenu("test");
    popup.add("whisper").addActionListener(myAction);
    popup.add("private message").addActionListener(myAction);
    popup.add("ignore").addActionListener(myAction);
    popup.add("clear ignore list").addActionListener(myAction);

    conNo = new ImageIcon(getURL("images/connect_no.gif"));
    conYes = new ImageIcon(getURL("images/connect_established.gif"));
    secNo = new ImageIcon(getURL("images/decrypted.gif"));
    secYes = new ImageIcon(getURL("images/encrypted.gif"));

    conIcon = new JLabel(conNo);
    conIcon.setBorder(new EtchedBorder());
    secIcon = new JLabel(secNo);
    secIcon.setBorder(new EtchedBorder());

    conIcon.setBounds(563, 334, 22, 22);
    secIcon.setBounds(588, 334, 22, 22);

    bottomText =
        new JLabel(
            "<html><body><font color=#445577><b>"
                + "LlamaChat "
                + VERSION
                + "</b></font> &nbsp;&copy; "
                + "<a href=\""
                + linkURL
                + "\">Joseph Monti</a> 2002-2003"
                + "</body></html>");
    bottomText.setBounds(5, 336, 500, 20);

    c.add(cboChannels);
    c.add(butChannel);
    c.add(butCreate);
    c.add(butInvite);
    c.add(textScroller);
    c.add(userScroller);
    c.add(messageText);
    c.add(conIcon);
    c.add(secIcon);
    c.add(bottomText);

    userList.addMouseListener(myMouseListener);
    messageText.addKeyListener(myKeyListener);
    bottomText.addMouseListener(myMouseListener);

    users = new ArrayList();
    ignores = new ArrayList(5);
    afks = new ArrayList(5);
    admins = new ArrayList(5);
    history = new CommandHistory(10);
    admin = false;
    channels = new Hashtable();
    privates = new PrivateMsg(this);
    showUserStatus = false;

    myColors[0] = new Color(200, 0, 0);
    myColors[1] = new Color(0, 150, 0);
    myColors[2] = new Color(0, 0, 200);

    rect = new Rectangle(0, 0, 1, 1);

    String opening =
        "<font color=#333333>"
            + "==================================<br>"
            + "Welcome to LlamaChat "
            + VERSION
            + "<br>"
            + "If you need assistance, type \\help<br>"
            + "Enjoy your stay!<br>"
            + "Maestria Aplicada en Redes<br>"
            + "==================================<br></font>";
    HTMLDocument doc = (HTMLDocument) mainChat.getDocument();
    HTMLEditorKit kit = (HTMLEditorKit) mainChat.getEditorKit();
    try {
      kit.insertHTML(doc, doc.getLength(), opening, 0, 0, HTML.Tag.FONT);
    } catch (Throwable t) {
      t.printStackTrace(System.out);
    }

    // validate the name
    if (!username.matches("[\\w_-]+?")) {
      error(
          "username contains invalid characters, changing to "
              + "'invalid' for now. "
              + "Type \\rename to chose a new name");
      username = "******";
    }
    if (username.length() > 10) {
      username = username.substring(0, 10);
      error("username too long, changed to " + username);
    }

    connect();
  }
  public Design() throws Exception {
    super.setBackground(Color.BLACK);
    this.setTitle("");
    con = getContentPane();
    con.setLayout(null);
    dim = tk.getDefaultToolkit().getScreenSize();
    this.setTitle("Customer Peer Login");

    l1 = new JLabel(new ImageIcon("plain.jpg"));
    l1.setBounds(0, 0, 400, 400);
    con.add(l1);
    l1.setBorder(BorderFactory.createEtchedBorder(5, Color.black, Color.black));

    title = new JLabel("CUSTOMER PEER LOGIN ");
    title.setFont(new Font("Bookman Old Style", Font.ROMAN_BASELINE, 20));
    title.setForeground(Color.red);
    title.setBounds(80, 30, 300, 30);
    l1.add(title);

    l4 = new JLabel("CMACHINE NAME");
    l4.setFont(new Font("Bookman Old Style", Font.BOLD, 16));
    l4.setForeground(Color.BLUE);
    l4.setBounds(70, 100, 160, 20);
    //	l4.setBorder(BorderFactory.createEtchedBorder(5,Color.green,Color.green));

    l1.add(l4);
    jtf2 = new JTextField();
    jtf2.setBounds(250, 100, 100, 20);
    jtf2.setBorder(BorderFactory.createEtchedBorder(5, Color.green, Color.green));

    l1.add(jtf2);

    l2 = new JLabel("CUSER LOGIN");
    l2.setFont(new Font("Bookman Old Style", Font.BOLD, 16));
    l2.setForeground(Color.blue);
    l2.setBounds(70, 150, 120, 20);
    l1.add(l2);

    jtf1 = new JTextField();
    jtf1.setBounds(250, 150, 100, 20);
    jtf1.setBorder(BorderFactory.createEtchedBorder(5, Color.green, Color.green));

    l1.add(jtf1);

    l3 = new JLabel("CPASSWORD");
    l3.setFont(new Font("Bookman Old Style", Font.BOLD, 16));
    l3.setForeground(Color.blue);
    l3.setBounds(70, 200, 120, 20);
    l1.add(l3);

    jptf1 = new JPasswordField();
    jptf1.setBounds(250, 200, 100, 20);
    jptf1.setBorder(BorderFactory.createEtchedBorder(5, Color.green, Color.green));

    l1.add(jptf1);

    JLabel l4 = new JLabel("DAgent");
    l4.setFont(new Font("Bookman Old Style", Font.BOLD, 16));
    l4.setForeground(Color.blue);
    l4.setBounds(70, 250, 120, 20);
    l1.add(l4);

    box = new JComboBox();
    box.setBounds(250, 250, 100, 20);
    box.setBorder(BorderFactory.createEtchedBorder(5, Color.green, Color.green));
    l1.add(box);

    b2 = new JButton("Register");
    b2.setBounds(50, 300, 100, 20);
    l1.add(b2);
    b2.setBorder(BorderFactory.createEtchedBorder(10, Color.BLUE, Color.BLUE));

    b3 = new JButton("Login");
    b3.setBounds(150, 300, 100, 20);
    b3.setBorder(BorderFactory.createEtchedBorder(10, Color.BLUE, Color.BLUE));
    l1.add(b3);

    b1 = new JButton("Cancel");
    b1.setBounds(250, 300, 100, 20);
    b1.setBorder(BorderFactory.createEtchedBorder(10, Color.BLUE, Color.BLUE));

    l1.add(b1);

    b1.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent we) {

            dispose();
          }
        });

    try {

      Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
      conn = DriverManager.getConnection("jdbc:odbc:agent");

    } catch (Exception exp) {

    }

    try {
      Statement satem = conn.createStatement();
      ResultSet rsatem = satem.executeQuery("select * from Dagent");
      while (rsatem.next()) {
        String namem = rsatem.getString("uname");
        box.addItem(namem);
      }

    } catch (Exception expo1) {

    }

    b2.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent we) {

            String username = jtf1.getText().trim();
            String password = jptf1.getText().trim();
            String mechine = jtf2.getText().trim();
            String dname = box.getSelectedItem().toString();
            int porte = 0;

            try {
              Statement sate = conn.createStatement();
              ResultSet rsate =
                  sate.executeQuery("select * from Dagent where uname='" + dname + "'");
              if (rsate.next()) {
                servermachine = rsate.getString("umechine");
                porte = rsate.getInt("ulistport");
                System.out.println(servermachine);
              }
              System.out.println(servermachine);

            } catch (Exception exp) {
              exp.printStackTrace();
            }

            try {
              packet p = new packet();
              p.setaction("Creg");
              p.setCuser(username);
              p.setCpass(password);
              p.setCmname(mechine);
              p.setCDpeer(dname);
              Socket soc = new Socket(servermachine, porte);
              ObjectOutputStream out = new ObjectOutputStream(soc.getOutputStream());
              out.writeObject(p);
              ObjectInputStream in = new ObjectInputStream(soc.getInputStream());
              packet rpac = (packet) in.readObject();
              if (rpac.getaction().equals("ok")) {

                JOptionPane.showMessageDialog(null, "Sucessfully Registered");

                jtf2.setText("");
                jtf1.setText("");
                jptf1.setText("");

              } else {

                JOptionPane.showMessageDialog(null, "Already Registered");
                jtf2.setText("");
                jtf1.setText("");
                jptf1.setText("");
              }

            } catch (Exception exp) {
            }
          }
        });

    b3.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent we) {

            String username = jtf1.getText().trim();
            String password = jptf1.getText().trim();
            String mechine = jtf2.getText().trim();
            String Dname = box.getSelectedItem().toString();

            int porte = 0;

            try {
              Statement sate = conn.createStatement();
              ResultSet rsate =
                  sate.executeQuery("select * from Dagent where uname='" + Dname + "'");
              if (rsate.next()) {
                servermachine = rsate.getString("umechine");
                porte = rsate.getInt("ulistport");
                System.out.println(servermachine);
              }
              System.out.println(servermachine);

            } catch (Exception exp) {

            }

            try {

              packet p1 = new packet();
              p1.setaction("clogin");
              p1.setCuser(username);
              p1.setCpass(password);
              p1.setCmname(mechine);
              p1.setCDpeer(Dname);
              Socket soc1 = new Socket(servermachine, porte);
              ObjectOutputStream out1 = new ObjectOutputStream(soc1.getOutputStream());
              out1.writeObject(p1);
              ObjectInputStream in1 = new ObjectInputStream(soc1.getInputStream());
              packet rpac1 = (packet) in1.readObject();
              if (rpac1.getaction().equals("ok")) {
                int port1 = 0;
                try {

                  int portm = rpac1.getCport();
                  System.out.println("XXXXXXX" + portm);
                  //	JOptionPane.showMessageDialog(null,"Sucessfully Started");

                  new Listen(portm);
                  new process(username, portm);
                  dispose();
                } catch (Exception exp) {
                }
              } else {
                JOptionPane.showMessageDialog(
                    null, "Enter valid username and password", "Server reply", 2);
                jtf1.setText("");
                jtf2.setText("");
                jptf1.setText("");
              }

            } catch (Exception exp) {
            }
          }
        });

    setSize(400, 400);
    show();
    setLocation(150, 100);
    setResizable(false);
  }
Ejemplo n.º 15
0
  /**
   * Sets up the airplane seating GUI. Adds in all the buttons, keeping a space for the aisle.
   *
   * @precondition the button is still clickable
   */
  public void run() {

    Airplane.aLock.lock();

    JFrame manualreservation = new JFrame();
    manualreservation.setTitle("Airplane Reservation System");
    manualreservation.setPreferredSize(new Dimension(500, 500));
    JPanel panel = new JPanel(new GridLayout(50, 5));
    JPanel container = new JPanel();

    for (int rows = 0; rows < 50; rows++) {
      for (int columns = 0; columns < 5; columns++) {
        if (columns == 2) {
          JButton empty = new JButton("");
          empty.setEnabled(false);
          panel.add(empty);

        } else {
          JButton button = new JButton();

          if (columns > 2) {
            button.setText((rows) + "," + (columns - 1));
            Airplane.buttons.add(button);
          } else {
            button.setText((rows) + "," + (columns));
            Airplane.buttons.add(button);
          }

          /**
           * Attached an Action Listener to every button. Sets the clicked button to un-clickable
           * and updates the button ArrayList and seating array.
           */
          button.addActionListener(
              new ActionListener() {

                public void actionPerformed(ActionEvent seatselected) {

                  JButton buttonclicked = (JButton) seatselected.getSource();
                  String[] temp = buttonclicked.getText().split(",");
                  int[] location = new int[temp.length];
                  for (int i = 0; i < temp.length; i++) {
                    location[i] = Integer.parseInt(temp[i]);
                  }
                  int loc = location[0] * 4 + location[1];

                  airplane.setSeat(location[0], location[1], 3);
                  buttonclicked.setText("3");
                  buttonclicked.setEnabled(false);
                  Airplane.buttons.add(buttonclicked);
                  Airplane.buttons.get(loc).setEnabled(false);
                  Airplane.buttons.get(loc).setText("3");
                }
              });
          panel.add(button);
        }
      }
    }

    container.add(panel);
    JScrollPane jsp = new JScrollPane(container);

    manualreservation.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    manualreservation.add(jsp);
    manualreservation.pack();
    manualreservation.setVisible(true);

    Airplane.aLock.unlock();
  }