package com.gaurav.bole;
import java.awt.Color;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.Scrollable;
public class ChatBoot extends JFrame implements KeyListener {
JPanel p=new JPanel();
JTextArea dilog=new JTextArea(20,50);
JTextArea input= new JTextArea(1,50);
JScrollPane scroll= new JScrollPane(dilog,
JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED
);
String[][] chatBot={
//standerds greeting
{"hi","hell","him"},
{"hi","hello","hey"},
//question
{"how r u","how are you","how are u","how r you"},
{"good","doing well","ya i am ok"},
//..........
{"sut up","you're bad","noob","stop talking",
"(shivani is not unavailabal, due to LOL)"},
};
public static void main(String arrgs[])
{
new ChatBoot();
}
public ChatBoot() {
// TODO Auto-generated constructor stub
super("Shiwani is hear");
setSize(6000,4000);
setResizable(false);
setDefaultCloseOperation(EXIT_ON_CLOSE);
dilog.setEditable(false);
input.addKeyListener(this);
p.add(scroll);
p.add(input);
p.setBackground(new Color(225, 200, 0));
add(p);
setVisible(true);
}
@Override
public void keyPressed(KeyEvent e) {
// TODO Auto-generated method stub
if(e.getKeyCode()==KeyEvent.VK_ENTER)
{
input.setEditable(false);
//code grab
String quote=input.getText();
input.setText("");
addText("-->You:\t"+quote);
quote.trim();
while(
quote.charAt(quote.length()-1)=='!' ||
quote.charAt(quote.length()-1)=='.' ||
quote.charAt(quote.length()-1)=='?'
){
quote=quote.substring(0,quote.length()-1);
}
quote.trim();
byte response=0;
int j=0;
while(response==0)
{
if(inArray(quote.toLowerCase(),chatBot[j*2]))
{
response=2;
int r=(int) Math.floor(Math.random()*chatBot[(j*2)+1].length);
addText("\n-->Shivani:\t"+chatBot[(j*2)+1][r]);
}
j++;
if(j*2==chatBot.length-1 && response==0){
response=1;
}
}
if(response==1){
int r=(int) Math.floor(Math.random()*chatBot[chatBot.length-1].length);
addText("\n-->Shivani:\t"+chatBot[chatBot.length-1][r]);
}
addText("\n");
}
}
private boolean inArray(String in, String[] str) {
// TODO Auto-generated method stub
boolean match=false;
for(int i=0;i<str.length;i++)
{
if(str[i].equals(in)){
match=true;
}
}
return match;
}
private void addText(String str) {
// TODO Auto-generated method stub
dilog.setText(dilog.getText()+str);
}
@Override
public void keyReleased(KeyEvent e) {
// TODO Auto-generated method stub
if(e.getKeyCode()==KeyEvent.VK_ENTER)
{
input.setEditable(true);
}
}
@Override
public void keyTyped(KeyEvent e) {
// TODO Auto-generated method stub
}
}
(* forget about shivani LOL)
import java.awt.Color;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.Scrollable;
public class ChatBoot extends JFrame implements KeyListener {
JPanel p=new JPanel();
JTextArea dilog=new JTextArea(20,50);
JTextArea input= new JTextArea(1,50);
JScrollPane scroll= new JScrollPane(dilog,
JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED
);
String[][] chatBot={
//standerds greeting
{"hi","hell","him"},
{"hi","hello","hey"},
//question
{"how r u","how are you","how are u","how r you"},
{"good","doing well","ya i am ok"},
//..........
{"sut up","you're bad","noob","stop talking",
"(shivani is not unavailabal, due to LOL)"},
};
public static void main(String arrgs[])
{
new ChatBoot();
}
public ChatBoot() {
// TODO Auto-generated constructor stub
super("Shiwani is hear");
setSize(6000,4000);
setResizable(false);
setDefaultCloseOperation(EXIT_ON_CLOSE);
dilog.setEditable(false);
input.addKeyListener(this);
p.add(scroll);
p.add(input);
p.setBackground(new Color(225, 200, 0));
add(p);
setVisible(true);
}
@Override
public void keyPressed(KeyEvent e) {
// TODO Auto-generated method stub
if(e.getKeyCode()==KeyEvent.VK_ENTER)
{
input.setEditable(false);
//code grab
String quote=input.getText();
input.setText("");
addText("-->You:\t"+quote);
quote.trim();
while(
quote.charAt(quote.length()-1)=='!' ||
quote.charAt(quote.length()-1)=='.' ||
quote.charAt(quote.length()-1)=='?'
){
quote=quote.substring(0,quote.length()-1);
}
quote.trim();
byte response=0;
int j=0;
while(response==0)
{
if(inArray(quote.toLowerCase(),chatBot[j*2]))
{
response=2;
int r=(int) Math.floor(Math.random()*chatBot[(j*2)+1].length);
addText("\n-->Shivani:\t"+chatBot[(j*2)+1][r]);
}
j++;
if(j*2==chatBot.length-1 && response==0){
response=1;
}
}
if(response==1){
int r=(int) Math.floor(Math.random()*chatBot[chatBot.length-1].length);
addText("\n-->Shivani:\t"+chatBot[chatBot.length-1][r]);
}
addText("\n");
}
}
private boolean inArray(String in, String[] str) {
// TODO Auto-generated method stub
boolean match=false;
for(int i=0;i<str.length;i++)
{
if(str[i].equals(in)){
match=true;
}
}
return match;
}
private void addText(String str) {
// TODO Auto-generated method stub
dilog.setText(dilog.getText()+str);
}
@Override
public void keyReleased(KeyEvent e) {
// TODO Auto-generated method stub
if(e.getKeyCode()==KeyEvent.VK_ENTER)
{
input.setEditable(true);
}
}
@Override
public void keyTyped(KeyEvent e) {
// TODO Auto-generated method stub
}
}
(* forget about shivani LOL)
Comments
Post a Comment