TextField and Submit JavaFx for Hangman game [closed] - java

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
How to make TextField that inputs letter than compares it with string? It's Hangman game.

The field itself would not do any of the comparing, it will act only as an input access point. That would mean that the only thing it will do is gather whatever you type in it.
So how do you actually make the comparison? Well you will have to call an underlying method, every time there is something written in the field.
for that method you could use some of Java's build in String functionalities for example you could use:
string.indexOf('a').
If the a is present in string, it returns the index(>=0). If not, it returns -1. So, a non-negative return value means that a is present in the string.

You can use Java Swing to create the UI.
There is a TextBox (JTextField). But mostly the Textbox itself will not write anything in it. A user has to do the writing.
You would like to make it only possible to add one char at a time or you have to check if the text the user entered is at most one char.
After that you can check if the char exists in the word you are looking for.

Related

Run combination of methods based on user input? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
Assuming I have 4 methods
methodA()
methodB()
methodC()
methodD()
Now I want the user to be able to input a number to run a combination of the methods.
So the user can choose if they want to run:
methodA() and methodB()
or:
methodB(), methodC() and methodD()
or just one of the methods or all of them.
Is there any other possibility than specifying any possible combination in if-statements?
You could use a bitmask. In that way one number could represent multiple flags that indicate which methods get called. A quick google search returned the following:
http://drumcoder.co.uk/blog/2010/jan/06/bitmasks-java/ Explains some solutions for this problem, which is what I think you're facing.
If you need to store multiple boolean flags for something, you can do
it using bits and storing that inside a single integer.

How can i search for a specific word(Value) in database? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I am making an android app , which scans a text and detects if a certain word is abusive. So i want my abusive words to be stored in database (SQLite).
My question is can i check if my text contains a word which is "forbidden". Should i use loop to check if each word of the text is contained in my database ? I need this to be fast.
Any help will be much appriciated.
Thanks in advance!
EDIT
I want the forbidden word to be displayed or stored in Arraylist.
I would suggest you save your scanned word in database, now use Like query to verify any forbidden word exists. If yes then keep that word otherwise delete it straightaway.
SELECT column_word FROM table WHERE id = "your_word_id" AND (column_word LIKE '%word1%'
OR column_word LIKE '%word2%' OR column_word LIKE '%word3%')
If result cursor have more than zero data then it must have forbidden word.

How to Create Strings Programatically in Java [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
So I am creating a program that need to create as many strings and integers as the user says. The amount is stored in wordlength, and I need to create these strings programmatically based on the input. Can somebody help me?
First, ask the user to input how many strings to store. This can be done through a Scanner.
Then, make an array of type String with length equal to the user input number.
Then, fill in the array through a Scanner with a for loop.
I hope next time you search about you problem before you write a question about it.

Search by name and number both within in single search bar [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I want to implement a functionality in java where I can search by both by username or by employee number within a single search bar.
I am looking for a simple solution either at client side or at java side
Thanks in advance
Just perform the first search, if it gives a result use it. If not then do the second search.
If usernames must contain alphabetic characters and employee numbers cannot contain them then you could look at the contents of the string and decide which search to run based on that.

Implementing jsp:include at Java [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I want to start from a given file(i.e. a.html) and if I see a pattern as like that:
<!--$include file="b.html"-->
I will go that file(b.html) and take whatever it has and all files will be written as into a final file(i.e. output.html)
If I see an include at b.html I should follow that include too and take whatever it has and I should repeat it recursively at Java?
Any ideas?
PS: It is similar to what jsp:include does but I want to implement it myself. I will implement it as a Maven plugin and I constructed a maven plugin for my need however using recursion or not and using a regex pattern or any other efficient way is what I am looking for.
You need to create a function to get files list, e.g. getFileList(htmlFile:File): File[];
Create a readline function and create a function to parse line which pattern is like "^.*<!\\-\\-\\$include file\\=\"(.+)\\.(html|htm)\" \\-\\->.*$", this is a regular expression, it can match what your searched regex. let's defined the function's name as checkRule(line:String):boolean
If checkRule return true, and get file name, then recursively invoke getFileList by passing just found file name.
Be careful about infinite loop. For example, a.html includes b.html, and b.html includes a.html, it would become infinite loop. So you need to check file list to ignore the file.
Good luck!!!

Categories