Advertisement
Guest User

Untitled

a guest
Apr 26th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.14 KB | None | 0 0
  1. package gui;
  2.  
  3. import ai.api.examples.TextClientApplication;
  4.  
  5. import java.awt.BorderLayout;
  6. import java.awt.event.ActionEvent;
  7. import java.awt.event.ActionListener;
  8. import java.awt.event.MouseAdapter;
  9. import java.awt.event.MouseEvent;
  10.  
  11.  
  12. import javax.swing.*;
  13.  
  14. public class GuiStart extends JFrame {
  15.  
  16.     private JTextField userInput;
  17.     private JTextArea chatWindow;
  18.  
  19.     public static void main(String[] args) {
  20.         new GuiStart(args);
  21.     }
  22.  
  23.  
  24.     //constructor
  25.     private GuiStart(String args[]) {
  26.         super("AI CORE - Chatbot");
  27.         add(createUserInput(), BorderLayout.SOUTH);
  28.         add(createChatWindow());
  29.         add(new JScrollPane(chatWindow, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER));  //den som gjør at du kan scrolle
  30.         setSize(800, 600);
  31.         setVisible(true);
  32.         TextClientApplication.setGui(this, args);
  33.     }
  34.  
  35.  
  36.     /**
  37.      * lager den derre greia dere har Øverst
  38.      *
  39.      * @return selve objectet
  40.      */
  41.     private JTextArea createChatWindow() {
  42.         chatWindow = new JTextArea();
  43.         chatWindow.setEditable(false);
  44.         chatWindow.setText("welcome to ai bot");
  45.         return chatWindow;
  46.     }
  47.  
  48.  
  49.     /**
  50.      * lager den derre greia dere har nederst
  51.      *
  52.      * @return selve objectet
  53.      */
  54.     private JTextField createUserInput() {
  55.         userInput = new JTextField("Skriv meldingen her...");
  56.         userInput.setEditable(true /*false*/);
  57.         userInput.addMouseListener(new MouseAdapter() {
  58.             @Override
  59.             public void mouseClicked(MouseEvent e) {
  60.                 userInput.setText("");
  61.             }
  62.         });
  63.  
  64.  
  65.  
  66.  
  67.         userInput.addActionListener(
  68.                 new ActionListener() {
  69.                     public void actionPerformed(ActionEvent event) {
  70.                         TextClientApplication.sendRequest(event.getActionCommand());
  71.                         userInput.setText("");
  72.                     }
  73.                 }
  74.  
  75.         );
  76.         return userInput;
  77.  
  78.     }
  79.  
  80.  
  81.     public void addText(String newText) {
  82.         chatWindow.append("\n " + newText);
  83.     }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement