Write only one number in text field [closed] - java

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
How can i let user write only one number in text field? Other should be consume.
I have code for write number.
private boolean number(char zn){
if(zn>='0' && zn<='9')
return true;
return false;
}

You state that this is a Swing question, and so I assume that you are using a JTextField. If so, you have one of two possible solutions here:
Use a JFormattedTextField and use a MaskFormatter, something simple like "#" should probably work perfectly here.
Or get the JTextField's Document and set its DocumentFilter with one that restricts input to as you deserve it. I think that this would be unnecessarily complex for you, and I recommend the first option.
Check the tutorial on how to use JFormattedTextFields which you can find here: JFormattedTextField Tutorial. It will explain all of the above including how to use a mask formatter with JFormattedTextFields.
Also please check Jon Skeet's blog on Writing the Perfect Question. Writing questions on this and other sites is a learned skill which can get better with study and effort. The tips that this blog contains will help you so that you'll know what information to include in your question so that the volunteers helping you don't have to guess at things. They will appreciate it, and you'll likely get better and quicker answers.

Related

Usage of java.util.ArrayList in ColdFusion [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 3 years ago.
Improve this question
I am working on some old ColdFusion code. It probably dates from late '90s. It was programmed using
queryParams = createObject("java", "java.util.ArrayList");
...
arrayAppend( queryParams, {...});
...
It is looking like a normal array. I am wondering if someone just created a normal ColdFusion array the hard way.
To preface this... My comment was an educated guess. The only person who could give a truly objective answer for a question like this is the champion who originally wrote the code you're looking at.
But yes, it's entirely possible (probable?) that the way people handled Arrays in Coldfusion 20 years ago would seem alien to us in modernity. ArrayNew() simply did not exist.
Pro Tip to anyone who reads this in the future: Adobe's help documentation usually has a "history" section that shows when functions came to be, or when they stopped being supported.
https://helpx.adobe.com/coldfusion/cfml-reference/coldfusion-functions/functions-a-b/arraynew.html
ArrayNew
> History
Introduced in ColdFusion MX
EDIT
From the comments, I have been informed that Adobe's official page appears to be wrong. I see there are books that reference the ArrayNew function all the way back until at least ColdFusion 4 in 1999.
I suppose it's still possible that OP's code is old enough to pre-date that function since he didn't give us a version, but an interesting development nonetheless.

How easy is it to steal something left out for garbage collection? [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
Why getText() in JPasswordField was deprecated?
According to this answer for the above question, what I understood was that creating a String object containing the password is a security threat because it may remain in the memory for a while and it is immutable.
So I was wondering,
How easy is it to retrieve something which has been hanging around
in the memory, without a reference or left out for garbage collection?
And how do you do it?
EDIT
As the question has been closed, be kind to share your knowledge by adding a comment, and consider reopening the question if you believe it may get interesting answers in the future. :)
https://en.wikipedia.org/wiki/Heartbleed
This is a good real-world example of things hanging in memory being used for exploitation. There's different ways to do it, so it's good to just make sure things that are valuable aren't being left hanging. Usually these attacks are just guess-and-check. You just keep sending information and piecing together the bits of extra memory you get in return.

user defined functions vs built in function in java five relevant differences over time and space complexities [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Please explain me the differences over time and space complexities in java for user defined and predefined functions in java. examples like, linked list, list, stack class. please explain this with valid example.
thank you.
There is nothing special in predefined function over user defined. The only thing is predefined has been written by somebody else for you. It depends on algorithm.
Crap code/implementation runs in a crap way. Doesn't matter if its user created or system/API provided. example at a high level is EJBs vs Spring.
Good written code runs pretty and sleek. Again doesn't matter who the hell wrote it.

Should names be in good english? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
(This might be the wrong place to ask the question, please let me know).
Should I name my method isStaticallyImported or isStaticlyImported?
(They'd be pronounced pretty much the same way, I believe)
Of course they should be in good english. Even if the human brain will likely have no problems reading garbled up words, compilers do not enjoy the same luxury.
How many times have you miswritten a variable name, then later on used the correct spelling, only to find out that the program crashed at run/compile time?
This problem is only amplified when working on code that was not written by you, because we think of things as, well, things, and having to specially remember that the thing had to be spelled in a special way is just an unneeded break to your workflow.
Yes, your variables should be clear to the developer. You can name it whatever you want and it will work because the compiler doesn't care. When you name the variable in a human readable manner then developers after you will be able to read and understand your code much easier. You should name it "isStaticallyImported".
They should be in the most easily understandable language for those using and maintaining it in my opinion.
I'm also pretty sure the compiler doesn't care about the quality of spelling.

how to see what row is selected in a JTable [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I am trying to get the value of the row selected in a Jtable but am so confused on how to implement the ListSelectionListener so that I can see what has been selected. I have gone to the java tutorial but i find it confusing. can anyone give me an example on how to create a ListSelectionListener and handle an event where a user selects a row?
am so confused on how to implement the ListSelectionListener
See: How to Write a List Selection Listener for a working example.
I have gone to the java tutorial but i find it confusing.
We don't know what you find confusing about the working example from the above tutorial. So why do you think any code we post would be any different? Unless you can state the exact problem you have (along with your SSCCE) we can't offer any more help.
Have a look at the code at;
http://www.coderanch.com/t/339330/GUI/java/values-selected-row-JTable
I think, it'll help you.

Categories