Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package gui;
- import ai.api.examples.TextClientApplication;
- import java.awt.BorderLayout;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.awt.event.MouseAdapter;
- import java.awt.event.MouseEvent;
- import javax.swing.*;
- public class GuiStart extends JFrame {
- private JTextField userInput;
- private JTextArea chatWindow;
- public static void main(String[] args) {
- new GuiStart(args);
- }
- //constructor
- private GuiStart(String args[]) {
- super("AI CORE - Chatbot");
- add(createUserInput(), BorderLayout.SOUTH);
- add(createChatWindow());
- add(new JScrollPane(chatWindow, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER)); //den som gjør at du kan scrolle
- setSize(800, 600);
- setVisible(true);
- TextClientApplication.setGui(this, args);
- }
- /**
- * lager den derre greia dere har Øverst
- *
- * @return selve objectet
- */
- private JTextArea createChatWindow() {
- chatWindow = new JTextArea();
- chatWindow.setEditable(false);
- chatWindow.setText("welcome to ai bot");
- return chatWindow;
- }
- /**
- * lager den derre greia dere har nederst
- *
- * @return selve objectet
- */
- private JTextField createUserInput() {
- userInput = new JTextField("Skriv meldingen her...");
- userInput.setEditable(true /*false*/);
- userInput.addMouseListener(new MouseAdapter() {
- @Override
- public void mouseClicked(MouseEvent e) {
- userInput.setText("");
- }
- });
- userInput.addActionListener(
- new ActionListener() {
- public void actionPerformed(ActionEvent event) {
- TextClientApplication.sendRequest(event.getActionCommand());
- userInput.setText("");
- }
- }
- );
- return userInput;
- }
- public void addText(String newText) {
- chatWindow.append("\n " + newText);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement