Created
July 19, 2020 14:27
-
-
Save olegrewko/5f9d3bb8e34f17bedecd78364f9321a4 to your computer and use it in GitHub Desktop.
SimpleChatBot_01
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.awt.*; | |
import java.awt.event.*; | |
import javax.swing.*; | |
public class SimpleChatBot extends JFrame implements ActionListener { | |
final String TITLE_OF_PROGRAM = "Chatter: simple chatbot"; | |
final int START_LOCATION = 200; | |
final int WINDOW_WIDTH = 450; | |
final int WINDOW_HEIGHT = 150; | |
JTextArea dialogue; | |
JCheckBox ai; | |
JTextField message; | |
// SimpleBot sbot; | |
public static void main(String[] args) { | |
new SimpleChatBot(); | |
} | |
SimpleChatBot() { | |
setTitle(TITLE_OF_PROGRAM); | |
setDefaultCloseOperation(EXIT_ON_CLOSE); | |
setBounds(START_LOCATION, START_LOCATION, WINDOW_WIDTH, WINDOW_HEIGHT); | |
dialogue = new JTextArea(); | |
dialogue.setLineWrap(true); | |
JScrollPane scrollBar = new JScrollPane(dialogue); | |
JPanel bp = new JPanel(); | |
bp.setLayout(new BoxLayout(bp, BoxLayout.X_AXIS)); | |
ai = new JCheckBox("AI"); | |
message = new JTextField(); | |
message.addActionListener(this); | |
JButton enter = new JButton("Enter"); | |
enter.addActionListener(this); | |
bp.add(ai); | |
bp.add(message); | |
bp.add(enter); | |
add(BorderLayout.CENTER, scrollBar); | |
add(BorderLayout.SOUTH, bp); | |
setVisible(true); | |
} | |
@Override | |
public void actionPerformed(ActionEvent event) { | |
if (message.getText().trim().length() > 0) { | |
} | |
message.setText(""); | |
message.requestFocusInWindow(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment