Home › Forums › General Chat › VuTales M.A.S.T.E.R.M.I.N.D.
- This topic has 5 replies, 3 voices, and was last updated 15 years, 8 months ago by
David.
-
AuthorPosts
-
16 June 2009 at 22:24 #2947
David
ParticipantA very simple program that receives a question input and spits out an answer.
Sad how such a simple program requires almost 50~ lines or so of code. 🙁
Obviously, with limited experience, it’s messy and not very useful, but I hope one day to develop a version that can be put online – kind of like Wolfram and Alpha, and talk about the legacy that is VuTales…
UPDATE:
Uses arrays instead of doing it manually for each question. Ftw.Code said: /*
** Written by David G.
** Program answers specified questions within strings. Uses a simple event structure.
** Uses FlowLayout for easier use.
** Strings may be modified easily and answers can be added just as quick.
*//*
Imports here
*/
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;public class VuTalesMastermind extends JFrame {
/*
Set up the GUI
*/
JLabel questionLabel = new JLabel(“Ask a question: “, JLabel.RIGHT);
JTextField questionAsked = new JTextField(“?”, 20);
JTextField answerPlz = new JTextField(“You haven’t asked a question.”, 50);
JButton askPlz = new JButton(“Ask Question!”);/*
All Questions
*/
String[] Questions = { “Is FunnyFroggy an idiot?”,
“Is Mipsacri an awesome moderator?”,
“Who owns VuTales?”
};
/*
All Responses
*/
String[] Responses = {
“Why yes, of course he’s an idiot.”,
“Of course she’s an awesome Moderator.”,
“David owns VuTa-WHACK- !OW! It’s Vu- vu- Vusys. :(”
};/*
These regulate defaults
*/
String blank = “”;
String blankQuestion = “The text field is blank. You have to ask something.”;
String responseToVoid = “I’m sorry, I do not recognize that question.”;
String notAQuestion = “You have to finish the question with a question mark – otherwise I won’t recognize it.”;/*
Creates the GUI and places then onto the screen.
*/
VuTalesMastermind() {
super(“VuTales M.A.S.T.E.R.M.I.N.D.”);
setSize(590,100);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
FlowLayout lulz = new FlowLayout();
setLayout(lulz);add(questionLabel);
add(questionAsked);
add(askPlz);
add(answerPlz);
answerPlz.setEnabled(false);
askPlz.addActionListener(new AnswerTheQuestion());
setVisible(true);
}/*
The Event Listener – waits for user the press the button.
*/
class AnswerTheQuestion implements ActionListener {
public void actionPerformed(ActionEvent ae) {
/*
Sets up variables used only in the Event
*/
String question = questionAsked.getText();
String thisQuestion = “”;
String thisResponse = “”;
char[] letters = question.toCharArray();
String AnswerR = “”;
int count = 0;
int ohnoes = 0;
int j;for (j = 0; j < Questions.length; j++) {
if (question.equals(Questions[j])) {
thisQuestion = Questions[j];
thisResponse = Responses[j];
}
}/*
Gets the last character of the question
*/
for (int i = 0; i < letters.length; i++) {
count++;
}if (letters[count – 1] != ‘?’) {
ohnoes++;
} else {
}/*
Gets first 3 characters of the question
*/
if (letters.length > 2) {
String WOW = String.valueOf(letters[2]);
String WoW = String.valueOf(letters[1]);
String wow = String.valueOf(letters[0]);
AnswerR = wow + WoW + WOW;
} else if (letters.length > 1) {
String WoW = String.valueOf(letters[1]);
String wow = String.valueOf(letters[0]);
AnswerR = wow + WoW;
} else if (letters.length > 0) {
String wow = String.valueOf(letters[0]);
AnswerR = wow;
} else {
}/*
Answers the question, if ohnoes = 1, then it is not a question. Default takes the first three characters supplied and puts … after it, with a error message.
*/
if (ohnoes == 1) {
answerPlz.setText(notAQuestion);
} else if (question.equals(thisQuestion)) {
answerPlz.setText(thisResponse);
} else if (question.equals(blank)) {
answerPlz.setText(blankQuestion);
} else {
answerPlz.setText(“I’ve received “” + AnswerR + “…” as an input. Is that correct? If so, it’s not in my database. I cannot help you.”);
}
}
}public static void main(String[] args) {
VuTalesMastermind pg = new VuTalesMastermind();
}
}16 June 2009 at 22:36 #12025Vusys
Participant…?
LOL Vista’s default theme without glass is so ugly.
16 June 2009 at 23:05 #12028David
ParticipantYes – well, I’m upgrading to Windows 7 when it does hit the public.
By the way, what happened to [code] tags? ._.
17 June 2009 at 09:14 #12050Vusys
ParticipantDavid said: Yes – well, I’m upgrading to Windows 7 when it does hit the public.By the way, what happened to [code] tags? ._.
I already have. It needs some work, but I’m finding it better than XP now.
17 June 2009 at 09:24 #12051Quang
ParticipantOoh how’s windows 7?
17 June 2009 at 11:19 #12053David
ParticipantFeedback has been pretty decent for it – although the price when it hits the public is still pretty lame. It’s Microsoft anyway. ._.
The new features are really good though, plus the pre-loaded wallpapers are awesome. 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.