9 Replies - 1298 Views - Last Post: 18 November 2010 - 01:24 AM Rate Topic: -----

#1 peepsrct  Icon User is offline

  • D.I.C Head

Reputation: 11
  • View blog
  • Posts: 151
  • Joined: 29-March 09

Help: Parsing a JTextfield then spliting contents into different varia

Posted 04 November 2010 - 02:11 PM

Hello,
I was wondering is there a way that you can display a JTextField, then when the user enters informaton into(such as a older land deed ex:"S 15(degrees) 45(minutes) W 145(chains" and presses button it breaks this down into different ints/strings where needed? Been looking at .split(), but not sure if that's what I'm looking for.
Is This A Good Question/Topic? 0
  • +

Replies To: Help: Parsing a JTextfield then spliting contents into different varia

#2 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2831
  • View blog
  • Posts: 11,992
  • Joined: 20-September 08

Re: Help: Parsing a JTextfield then spliting contents into different varia

Posted 04 November 2010 - 04:23 PM

To reduce the possibility of errors i would use separate fields. The problem (and probably others) then disappears

This post has been edited by g00se: 04 November 2010 - 04:23 PM

Was This Post Helpful? 0
  • +
  • -

#3 peepsrct  Icon User is offline

  • D.I.C Head

Reputation: 11
  • View blog
  • Posts: 151
  • Joined: 29-March 09

Re: Help: Parsing a JTextfield then spliting contents into different varia

Posted 04 November 2010 - 04:45 PM

Yeah, That was the direction I ended up going using a JSpinner for the directions. I played with split() a little more, and it just seemed like more of a headache then was needed.
Was This Post Helpful? 0
  • +
  • -

#4 peepsrct  Icon User is offline

  • D.I.C Head

Reputation: 11
  • View blog
  • Posts: 151
  • Joined: 29-March 09

Re: Help: Parsing a JTextfield then spliting contents into different varia

Posted 10 November 2010 - 08:58 PM

I have a new question, concerning this same project I'm working on. I'm having trouble understanding how to write my own constructrs. Here is my attempt at a simple one.

public class DeedExample
{
	public String newDeed;
	Deed deed=new Deed();

	public static void main(String args[])
	{
		System.out.println(deed);
		System.out.println("Complete.");
	}
	public Deed myNewDeed()
	{
		newDeed="Deed!";
    }

}



and the error:

8: non-static variable deed cannot be referenced from a static context
		System.out.println(deed);
		                   ^


Thanks for any help, always appreciated.

This post has been edited by peepsrct: 10 November 2010 - 09:13 PM

Was This Post Helpful? 0
  • +
  • -

#5 NeoTifa  Icon User is offline

  • Whorediot
  • member icon





Reputation: 2793
  • View blog
  • Posts: 15,901
  • Joined: 24-September 08

Re: Help: Parsing a JTextfield then spliting contents into different varia

Posted 10 November 2010 - 09:02 PM

You could take the Strings and separate the tokens using the space delimiter. Then from there parse each token. :/ Hope that helped.
Was This Post Helpful? 0
  • +
  • -

#6 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10803
  • View blog
  • Posts: 40,273
  • Joined: 27-December 08

Re: Help: Parsing a JTextfield then spliting contents into different varia

Posted 10 November 2010 - 09:46 PM

The error is pretty specific- you cannot access non-static elements from other static elements. Really, the main() method is for unit testing only. It doesn't make sense to instantiate a Deed object as an instance variable of the Deed class, as you are asking for inifinite recursion. Simply instantiate the Deed object in the main() method, and test the class there. Your constructor is fine, though. :)
Was This Post Helpful? 0
  • +
  • -

#7 peepsrct  Icon User is offline

  • D.I.C Head

Reputation: 11
  • View blog
  • Posts: 151
  • Joined: 29-March 09

Re: Help: Parsing a JTextfield then spliting contents into different varia

Posted 10 November 2010 - 10:26 PM

View Postmacosxnerd101, on 10 November 2010 - 08:46 PM, said:

Simply instantiate the Deed object in the main() method, and test the class there.


Thanks for the help, but I don't quite grasp what you mean by this statement. As long as I can get pointed in the right direction, I should be good to go.
Was This Post Helpful? 0
  • +
  • -

#8 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10803
  • View blog
  • Posts: 40,273
  • Joined: 27-December 08

Re: Help: Parsing a JTextfield then spliting contents into different varia

Posted 11 November 2010 - 07:35 AM

Rather than saying Deed myDeed = new Deed(); as an instance variable, you should instantiate it in your main() method. What will happen if you keep this where it is, is that you will get a StackOverflowError. When the Deed object is instantiated, another Deed object will be instantiated, and this will continue until your program crashes.

The main() method is static, though, meaning it is associated with the class, not the Objects. So by using the main() method, you can test your Deed class.
public static void main(String[] args){
   Deed d = new Deed(); 
   //now use d to test its functionality
}


Was This Post Helpful? 0
  • +
  • -

#9 peepsrct  Icon User is offline

  • D.I.C Head

Reputation: 11
  • View blog
  • Posts: 151
  • Joined: 29-March 09

Re: Help: Parsing a JTextfield then spliting contents into different varia

Posted 11 November 2010 - 10:06 AM

Thanks, though I now get this error. And not sure exactly how to handle it. Error falls on bracket at end of constructor.
DeedExample.java:14: missing return statement
    }
    ^


Was This Post Helpful? 0
  • +
  • -

#10 peepsrct  Icon User is offline

  • D.I.C Head

Reputation: 11
  • View blog
  • Posts: 151
  • Joined: 29-March 09

Re: Help: Parsing a JTextfield then spliting contents into different varia

Posted 18 November 2010 - 01:24 AM

Tried editing, but still no luck solving my contructor problem. Anyone able to tell me where I'm going wrong.
public MyCall()
{
	x=0;
	y=0;
}

public MyCall(String angle2,int degrees2, int minutes2, String turn2, int distance , String comment)
{
	String ogDirection=angle2;
	int	orgDegrees=degrees2;
	int orgMinutes=minutes2;
	String secDir=turn2;
	int secDistance=distance;
	String comments=comment;
}




Error it gives is this, before it simply gave me a "you need a return" error, now it doesnt even do that.
.java:243: invalid method declaration; return type required
public myCall()
       ^
.java:249: invalid method declaration; return type required
public myCall(String angle2,int degrees2, int minutes2, String turn2, int distance , String comment)
       ^
2 errors

Tool completed with exit code 1



Was This Post Helpful? 0
  • +
  • -

Page 1 of 1