Results 1 to 4 of 4
- 07-27-2010, 02:51 PM #1
Senior Member
- Join Date
- Apr 2010
- Location
- Belgrade, Serbia
- Posts
- 278
- Rep Power
- 4
get values from JTextFields input
Hi.
I have written small program that works with coordinates.
I want to use JTextField for insertion coords like this: "(x,y)".
So my first problem is how to get values x and y from string "(x,y)".
My first idea is to get rid of brackets and then split string with .split(',').
Is it good approach, or there is some better way to do it?
My second problem is how to make my input more flexible.
For example somethimes I'll have input: "(x, y)" or " ( x, y ) ", and I still want to get values from it.
Is it good to work with regular expressions in this case?
- 07-27-2010, 03:00 PM #2
split is fine and using a regex to get the values is ok too.
Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
The Ubiquitous Newbie Tips
- 07-27-2010, 09:33 PM #3
Senior Member
- Join Date
- Apr 2010
- Location
- Belgrade, Serbia
- Posts
- 278
- Rep Power
- 4
PhHein thanks very much.
I solved the problem.
Here is my code:
Java Code:import java.util.regex.Pattern; public class GetCoordValues { public static void main(String[] args) { String coord = "(12 , 14 )"; String[] coords; coord = coord.substring(1, coord.length()-1); Pattern pattern = Pattern.compile("[,\\s]+"); coords = pattern.split(coord); for(String variable : coords) System.out.println(variable); } }
- 07-27-2010, 09:35 PM #4
Uhm, you're welcome, but you solved it yourself indeed.
Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
The Ubiquitous Newbie Tips
Similar Threads
-
Changing Webpage's Input Values
By Lawllerskates in forum New To JavaReplies: 0Last Post: 05-16-2010, 02:26 AM -
draw in jpanel using values input in textbox
By New to JAVA in forum AWT / SwingReplies: 6Last Post: 07-08-2009, 11:06 AM -
Please help me. Input Values sending from Jsp to Servlet
By Santoshbk in forum JavaServer Pages (JSP) and JSTLReplies: 1Last Post: 02-17-2009, 02:18 PM -
Problem with JTextFields not null
By romina in forum AWT / SwingReplies: 1Last Post: 08-07-2007, 05:17 AM -
JTextFields with username & password.
By Eric in forum AWT / SwingReplies: 2Last Post: 07-01-2007, 11:41 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks