コード例 #1
0
  @Override
  public void actionPerformed(ActionEvent e) {
    String prefix = "";
    String userName = settingsPane.returnSetting("IRC_nick");
    String input = "<b><font color=blue>[" + userName + "]:</font></b> " + chatInput.getText();

    if (e.getSource() == g_start) {

      substarterBegin(prefix, userName, input);
    }

    if (e.getSource() == g_end) {
      substarterEnd(prefix, userName, input);
    }

    if (e.getSource() == sendButton) {

      if (!chatInput.getText().equals("")) {

        // toChatScreen(input);

        // chatScreen.append(input + "\n");
        if (chatInput.getText().startsWith("/")) {
          if (chatInput.getText().equals("/substart")) {
            substarterBegin(prefix, userName, input);
          }
          if (chatInput.getText().equals("/substartend")) {
            substarterEnd(prefix, userName, input);
          }
        } else {
          sock.outputToChannel(chatInput.getText(), channelName);

          try {
            // chatter.printScreen();

            toChatScreen(prefix + input, false);
          } catch (IOException | BadLocationException ex) {
            Logger.getLogger(IRCBOT.class.getName()).log(Level.SEVERE, null, ex);
          }
        }
        chatInput.setText("");
        // chatter.addTo(input);

      } else {
        chatInput.setText("");
      }
      chatInput.requestFocus();
    }

    if (e.getSource() == settings) {
      // makeNewWindow("Window " + frameCounter, JFrame.DISPOSE_ON_CLOSE, 800, 500, 2);
      settingsPane.showPane();
    }
  }
コード例 #2
0
  @Override
  public void keyReleased(KeyEvent e) {

    if (e.getKeyCode() == KeyEvent.VK_ENTER) {
      String prefix = "";
      if (!chatInput.getText().equals("")) {
        String userName = settingsPane.returnSetting("IRC_nick");
        String input = "<b><font color=blue>[" + userName + "]:</font></b> " + chatInput.getText();

        // toChatScreen(input);

        // chatScreen.append(input + "\n");
        if (chatInput.getText().startsWith("/")) {
          if (chatInput.getText().equals("/substart")) {
            substarterBegin(prefix, userName, input);
          }
          if (chatInput.getText().equals("/substartend")) {
            substarterEnd(prefix, userName, input);
          }
        } else {

          try {
            // chatter.printScreen();

            toChatScreen(prefix + input, false);
          } catch (IOException | BadLocationException ex) {
            Logger.getLogger(IRCBOT.class.getName()).log(Level.SEVERE, null, ex);
          }
          sock.outputToChannel(chatInput.getText(), channelName);
        }
        chatInput.setText("");
        // chatter.addTo(input);

      } else {
        chatInput.setText("");
      }
      chatInput.requestFocus();
    }
  }
コード例 #3
0
 public static void showResult(JTextArea txt, String result) {
   try {
     if (txt.getText().length() == 0) {
       txt.setText(result);
       txt.setSelectionStart(txt.getText().length());
       txt.setSelectionEnd(txt.getText().length() - 1);
     } else {
       if (txt.getText().length() > MAX_LOG_SIZE)
         txt.getDocument().remove(0, txt.getText().length() - MAX_LOG_SIZE);
       txt.setSelectionStart(txt.getText().length());
       txt.getDocument().insertString(txt.getText().length(), result, null);
       txt.setSelectionEnd(txt.getText().length());
     }
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
コード例 #4
0
  public IRCBOT(boolean uList, String channel, int chatNum) {

    // chatter = new ChatDisplay("<html><body bgcolor='black'><table border=0pt width=100%>");
    winNum = chatNum;
    URL iconURL = getClass().getResource("P_300x300.png");
    ImageIcon icon = new ImageIcon(iconURL);
    setIconImage(icon.getImage());

    Action doNothing =
        new AbstractAction() {

          @Override
          public void actionPerformed(ActionEvent e) {}
        };

    channelName = channel;
    standardWindow = uList;

    chatInput = new JTextArea(4, 55);
    chatInput.setWrapStyleWord(true);
    chatInput.setLineWrap(true);
    chatInput.getInputMap().put(KeyStroke.getKeyStroke("ENTER"), "doNothing");
    chatScreen = new JTextPane();
    chatScreen.setContentType("text/html");
    chatScreen.setEditorKit(kit);
    chatScreen.setDocument(doc);
    userList = new JTextPane();
    registeredUserList = new JTextPane();
    sendButton = new JButton("SEND");
    g_start = new JButton("START");
    g_end = new JButton("END");
    g_reroll = new JButton("secret");

    JLabel l_giveaway = new JLabel("Giveaway", JLabel.CENTER);
    JLabel l_chat = new JLabel("Chat", JLabel.CENTER);
    JLabel l_uList = new JLabel("User List", JLabel.CENTER);

    sendButton.addActionListener(this);
    g_start.addActionListener(this);
    g_end.addActionListener(this);
    g_reroll.addActionListener(this);

    g_start.setEnabled(false); // disabled for basic irc client
    g_end.setEnabled(false);
    g_reroll.setEnabled(false);

    // String start = "<html><body>";

    Dimension min = new Dimension(100, 1);
    Dimension pref = new Dimension(150, 1);
    Dimension max = new Dimension(600, 600);
    // chatScreen.setMinimumSize(min);
    // userList.setMinimumSize(min);
    // chatInput.addKeyListener(KeyBoardListener);

    JPanel mainPanel = new JPanel(new BorderLayout(5, 5));
    JPanel left = new JPanel(new BorderLayout(5, 5));
    JPanel mid = new JPanel(new BorderLayout(5, 5));
    JPanel right = new JPanel(new BorderLayout(5, 5));
    JPanel giveaway_buttons = new JPanel(new BorderLayout(5, 5));

    JPanel sendBar = new JPanel();
    scrollChat = new JScrollPane(chatScreen);
    JScrollPane scrollChatInput = new JScrollPane(chatInput);
    userListScroll = new JScrollPane(userList);
    JScrollPane regUserListScroll = new JScrollPane(registeredUserList);

    userListScroll.setMinimumSize(min);
    // userListScroll.setPreferredSize(pref);
    // userListScroll.setMaximumSize(new Dimension(800,600));
    // userListScroll.setPreferredSize(new Dimension(100,100));
    // scrollChat.setPreferredSize(pref);
    scrollChat.setMinimumSize(min);
    // scrollChat.setMaximumSize(new Dimension(500,500));
    regUserListScroll.setPreferredSize(pref);

    mid.add(l_chat, BorderLayout.NORTH);
    mid.add(scrollChat, BorderLayout.CENTER);

    right.add(l_uList, BorderLayout.NORTH);
    right.add(userListScroll, BorderLayout.CENTER);

    giveaway_buttons.add(g_start, BorderLayout.WEST);
    giveaway_buttons.add(g_end, BorderLayout.CENTER);
    giveaway_buttons.add(g_reroll, BorderLayout.PAGE_END);

    left.add(giveaway_buttons, BorderLayout.PAGE_END);

    JSplitPane chat_userList = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, mid, right);
    chat_userList.setOneTouchExpandable(true);
    chat_userList.setDividerLocation(500);
    chat_userList.setResizeWeight(0.5);
    chat_userList.setContinuousLayout(true);
    // chat_userList.setPreferredSize(new Dimension(100,100));
    chat_userList.setMinimumSize(min);
    // chat_userList.setMaximumSize(max);

    userListScroll.setHorizontalScrollBarPolicy(HORIZONTAL_SCROLLBAR_NEVER);
    // scroll.add(chatScreen);

    sendBar.add(scrollChatInput);
    sendBar.add(sendButton);

    if (standardWindow) {

      mainPanel.add(chat_userList, BorderLayout.CENTER);
      mainPanel.add(sendBar, BorderLayout.PAGE_END);

      JMenuBar menuBar = new JMenuBar();
      JMenu fileMenu = new JMenu("File");
      settings = new JMenuItem("Settings");

      settings.addActionListener(this);

      fileMenu.add(settings);
      menuBar.add(fileMenu);

      left.add(l_giveaway, BorderLayout.NORTH);
      left.add(regUserListScroll, BorderLayout.CENTER);
      // left.setBorder(new EmptyBorder(0,5,0,0));
      // chat_userList.setBorder(new EtchedBorder(0,0,0,5));
      mainPanel.add(left, BorderLayout.WEST);
      mainPanel.add(menuBar, BorderLayout.PAGE_START);
      // mainPanel.setBorder(new EmptyBorder(0,10,10,10));
    } else {
      mainPanel.add(scrollChat, BorderLayout.CENTER);
    }
    registeredUserList.setEditable(false);
    userList.setEditable(false);
    chatScreen.setEditable(false);

    registeredUserList.setFont(new Font("Courier New", Font.PLAIN, 12));
    chatScreen.setFont(new Font("Courier New", Font.PLAIN, 12));
    chatInput.setFont(new Font("Courier New", Font.PLAIN, 12));

    getContentPane().add(mainPanel);
    setSize(800, 500);
    setVisible(true);
    setResizable(true);
    setLocationRelativeTo(null);
    setTitle("IRC Chatter");
    setMinimumSize(new Dimension(500, 200));

    addWindowListener(
        new WindowAdapter() {
          @Override
          public void windowClosing(WindowEvent e) {
            // System.out.println("\n\n\n\n\n\\n\nCLOSEDWINDOW\n\n\n\n\n\n\n\n");
            if (sock.isSafe() == true) sock.outputText("PART " + channelName + "\r\n");
            // System.out.println("\n\n\n\n\n\\n\nCLOSEDWINDOW\n\n\n\n\n\n\n\n");
          }
        });
    chatInput.addKeyListener(this);
    chatInput.requestFocus();
  }