Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Crazy RRRussian
Mar 5, 2010

by Fistgrrl

Aleksei Vasiliev posted:


How are IRC strings formatted? If the name of sender of message is always in front then you can just compare the beginning of inputLine with whatever poster name?

Also contains() should work fine for this. inputLine.contains("AlekseiV");

Adbot
ADBOT LOVES YOU

Jonnty
Aug 2, 2007

The enemy has become a flaming star!

Aleksei Vasiliev posted:

I'm writing a really simple IRC bot just to learn poo poo and I'm trying to do something. I don't know what it's called. This is frustrating me. (i am bad at java/programming)

Strings have methods like contains and substring and poo poo, so I can do:
code:
BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
	String inputLine;
	while ((inputLine = br.readLine()) != null) {
		if (inputLine.contains("End of /MOTD")) {
			break;
		}
	}
but if I want to do poo poo like
code:
if (inputLine.isFrom("AlekseiV")) {
	//A message from the bot owner!
	doShit();
	}
how do I create the method isFrom() for strings? help :saddowns:
A tutorial or way of doing something similar or even just Google search terms would be great since I have no idea wtf this is called

You'll have to study the IRC RFCs first to work out how it lets you know where a message is from, then use split or the regex Pattern and Matcher classes to filter that out. This isn't something that's in the standard string library, it's specfic to IRC.

I'd also strongly recommend using the codes defined in the RFCs rather than the messages, which can change from server to server. If you haven't already, you should also probably telnet in to your favourite IRC server and pretend to be an IRC client yourself - there's a good guide here - as this really helps you understand how everything works a lot more. Also I hope you realise nicks are not a good way to authenticate people if you're doing anything important. Writing an IRC bot from scratch is harder than it looks!

Jonnty
Aug 2, 2007

The enemy has become a flaming star!

LockeNess Monster posted:

How are IRC strings formatted? If the name of sender of message is always in front then you can just compare the beginning of inputLine with whatever poster name?

Also contains() should work fine for this. inputLine.contains("AlekseiV");

Wow, so if I just put the owner's name in my message I can run the bot? Nice!

Malloc Voidstar
May 7, 2007

Fuck the cowboys. Unf. Fuck em hard.

LockeNess Monster posted:

How are IRC strings formatted? If the name of sender of message is always in front then you can just compare the beginning of inputLine with whatever poster name?

Also contains() should work fine for this. inputLine.contains("AlekseiV");

quote:

:javamob!javamobi@hostname.com PRIVMSG #chatt :sup
That's the bot with a nick of javamob saying "sup" in channel #chatt.

Just doing a contains will get false positives of anybody saying the bot owner's name.

edit: gently caress; beaten.

I've been using a bit of the RFC but also mostly just looking at the packets in Wireshark. My bot is poo poo and unreliable right now but I've only spent 30+ minutes on it so far.

I don't think I'll have that much problem getting the IRC stuff, but does anybody have an idea of how to do something like the isFrom() thing I'm thinking of?

Malloc Voidstar fucked around with this message at 20:46 on May 16, 2010

Jonnty
Aug 2, 2007

The enemy has become a flaming star!

Aleksei Vasiliev posted:

That's the bot with a nick of javamob saying "sup" in channel #chatt.

Just doing a contains will get false positives of anybody saying the bot owner's name.

edit: gently caress; beaten.

I've been using a bit of the RFC but also mostly just looking at the packets in Wireshark. My bot is poo poo and unreliable right now but I've only spent 30+ minutes on it so far.

I don't think I'll have that much problem getting the IRC stuff, but does anybody have an idea of how to do something like the isFrom() thing I'm thinking of?
(this is completely untested but should work)
code:
public String getSender(String line) {
  Pattern p = new Pattern.compile("^:([\w])+!");
  Matcher m = p.matcher(line);
  if (m.matches()) {
    return m.group(1);
  else {
    return null; 
  }
}
Get the idea? Also you should probably alter that regexp to include more valid nickname characters.

e: looking at the packets in wireshark seems like a pretty clunky way of doing it but whatever works for you. I prefer telnet because you get the plain text which you're dealing with and nothing else. You can also try sending strings too, which is either difficult or impossible with wireshark. Using wireshark lets you see the 'best practices' the clients use though, I guess.

Jonnty fucked around with this message at 21:07 on May 16, 2010

Malloc Voidstar
May 7, 2007

Fuck the cowboys. Unf. Fuck em hard.

Jonnty posted:

e: looking at the packets in wireshark seems like a pretty clunky way of doing it but whatever works for you. I prefer telnet because you get the plain text which you're dealing with and nothing else. You can also try sending strings too, which is either difficult or impossible with wireshark. Using wireshark lets you see the 'best practices' the clients use though, I guess.

quote:

:server.com NOTICE AUTH :*** Looking up your hostname...
:server.com NOTICE AUTH :*** Found your hostname
NICK javamob
:server.com 451 :You have not registered
As far as I can tell you need to send the NICK command (which is the first client command) before it does any of that, which seems to be impossible using a telnet client.

Jonnty
Aug 2, 2007

The enemy has become a flaming star!

Aleksei Vasiliev posted:

As far as I can tell you need to send the NICK command (which is the first client command) before it does any of that, which seems to be impossible using a telnet client.

It ought to be possible using a telnet client since it's functionally equivalent to a computer (apart from being slightly slower but that shouldn't matter). The error you're getting is defined here and shows you haven't registered with the USER command yet, like that link I posted told you to.

e: Although it looks like you have, so post the whole exchange you've had with the server so we can see what's happening.

Malloc Voidstar
May 7, 2007

Fuck the cowboys. Unf. Fuck em hard.
Turns out when using PuTTY you need to set "Telnet negotiation mode" to Passive to be able to telnet into an IRC server. Otherwise the server'll throw errors at you.

epswing
Nov 4, 2003

Soiled Meat
You could download and take a look at how pircbot does things.

epswing fucked around with this message at 05:35 on May 17, 2010

lamentable dustman
Apr 13, 2007

🏆🏆🏆

epswing posted:

You could doesn't and take a look at how pircbot does things.

Was going to suggest that, I've played around with it before. Very easy to use, runs its own irc client in main.

Partyworm
Jul 8, 2004

Tired of partying
Could anyone help me to understand the logical difference between these two similar methods for reading individual lines from a stream (which for some reason are producing wildly different results).

I started off using this method which i thought would be fairly logically sound:

code:
public String readThis() {
            try {
             if (buff.readLine() == null) {
		read.resetStream("johnny.txt");
                lineOut = buff.readLine();
            }
             else
		lineOut = buff.readLine();
		} catch (IOException io) {
			//do something
		} 
        return lineOut; 
        }
However this was giving me some bizarre behavior where it would skip the first line, output normally until about the tenth or so line, and then output a null value as a string (where there are no null values present in the file) and then cycle through the same 7-8 lines of a 20 or so lined text file, despite the stream being ostensibly called to reset before reading again.

I tried playing around with the logic a little and came up with this instead, which works flawlessly:

code:
   public String readThis() {
            try {
		lineOut = buff.readLine();
		if (lineOut == null) {
		read.resetStream("johnny.txt");
		lineOut = buff.readLine();
	    } } catch (IOException io) {
			//do something
		}
        return lineOut; 
        }
Could anyone shed some light on what logical flaw in the first method might explain the weird behavior?

lewi
Sep 3, 2006
King

Partyworm posted:

code:
public String readThis() {
            try {
             if (buff.readLine() == null) {
		read.resetStream("johnny.txt");
                lineOut = buff.readLine();
            }
             else
		lineOut = buff.readLine();
		} catch (IOException io) {
			//do something
		} 
        return lineOut; 
        }
Could anyone shed some light on what logical flaw in the first method might explain the weird behavior?

I assume that readLine() returns a line and then next time it is called it will return the next line? That would at least explain why the first line is not output as readLine() is called in the if statement, it is found not to be null, so else is executed which calls readLine() again. lineOut is then the second time that readLine() is called.

Step through your program line by line, writing down what happens (not what you think should happen, but what *actually* happens). That ought to help you fix your logical mistakes. You'll find out that your first method and your second method are not the same at all.

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."
Partyworm: Are 'read' and 'buff' a FileReader and a BufferedReader, respectively, or what? I'm not aware of any classes with a resetStream(String) method.

Also, that is some crazy tabbing. I don't want to start a holy war, but however you choose to format your code it is imperative that you're consistent. For comparison:

code:
public String readThis() {
	try {
		if (buff.readLine() == null) {
			read.resetStream("johnny.txt");
			lineOut = buff.readLine();
		}
		else {
			lineOut = buff.readLine();
		}
	}
	catch (IOException io) {
		//do something
	}
        return lineOut;
}
code:
public String readThis() {
	try {
		lineOut = buff.readLine();
		if (lineOut == null) {
			read.resetStream("johnny.txt");
			lineOut = buff.readLine();
		}
	}
	catch (IOException io) {
		//do something
	}
	return lineOut;
}

Partyworm
Jul 8, 2004

Tired of partying

lewi posted:

I assume that readLine() returns a line and then next time it is called it will return the next line? That would at least explain why the first line is not output as readLine() is called in the if statement, it is found not to be null, so else is executed which calls readLine() again. lineOut is then the second time that readLine() is called.

Step through your program line by line, writing down what happens (not what you think should happen, but what *actually* happens). That ought to help you fix your logical mistakes. You'll find out that your first method and your second method are not the same at all.

Thanks, you're right. How could i overlook something that obvious :( I woke up this morning after sleeping on it and before even looking at this thread i suddenly realized "holy poo poo, i'm reading two lines within the same method", and felt really dumb.

Internet Janitor: 'read' is an instance of a 'Reader' class i wrote that simply initializes a FileReader and BufferedReader together with the file name as the only argument. It's largely superflous and unecessary (your earlier fix worked just fine) but i like to play around as i learn and get a feel for what works and what doesn't. resetStream() is basically a method within that Reader class that closes the stream and then re-initializes it. I'm sure there's probably a simpler built in way of doing that, but at this stage i like to get my chops into writing methods wherever i can as its all good practice in the end.

And yeah, apologies for the horrible formatting - I tinkered with that method so much that all concern for 'form' pretty much went out the window.

Partyworm fucked around with this message at 09:47 on May 18, 2010

TheUnforgiven
Mar 28, 2006
lanky fuck
Hey guys. I'm struggling through a java class in school due to my teacher. He's a horrible teacher and I've had several friends who have tried taking the class with me drop out along with me. Next semester is the 2nd time I'm trying to take his class. I'm studying over the summer and I'm wondering what would be some good books to pick-up to help me through this class.

epswing
Nov 4, 2003

Soiled Meat
This set of video tutorials is linked in the OP, check them out: http://sourceforge.net/projects/eclipsetutorial/files/





Edit: vvv No worries, let us know if they're any good.

epswing fucked around with this message at 20:41 on May 18, 2010

TheUnforgiven
Mar 28, 2006
lanky fuck

epswing posted:

This set of video tutorials is linked in the OP, check them out: http://sourceforge.net/projects/eclipsetutorial/files/


Woops, I completely looked over it. I looked for a section on books/tutorials and didnt see anything.

Malfeasible
Sep 10, 2005

The sworn enemy of Florin
I have encountered a problem I cannot begin to figure out.

I have a static method that works perfectly when I test it in the main method of that same class. Here is the header:
code:
 public static Map<String, Object> getDataMap(int zipcode)
But when I try to call it from a different package the compiler tells me that it's a non-static method and cannot be referenced from a static context. I have googled this looking for anyone with the same problem but it's always people who haven't actually declared the method as static, which I clearly have. Why on earth would the compiler think that a static method is non-static? Here is the line of code where I attempt to call the method:
code:
java.util.Map<String, Object> zipData = ZipcodeJDBC.getDataMap(Integer.parseInt(zipcode));
I have been scouring my computer deleting old class files or old jar files that the compiler might be seeing instead of seeing the current version I have quoted here. I do not think it is a case of javac looking at an old class file from before I declared the method as static.

Also, I get a warning that I have an unchecked conversion, as if the method were only returning a Map and not a Map<String, Object>. Is this because generics are stripped out at compile time and do not actually exist in the class file, or is it related to the other problem?

edit: ARG! I didn't scour hard enough. I found an old version of the file that is definitely the culprit. The unchecked conversion issue seams to have cleared up as well.

Malfeasible fucked around with this message at 23:28 on May 18, 2010

WalletBeef
Jun 11, 2005

I am working on some code which needs to determine if a point on the earth is within a polygon. Are there java libraries which would allow me to do this?

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."
WalltBeef: It's probably not the fastest solution, but if all you care about is 2d there's always the AWT Polygon class. Check out the contains() methods.

lamentable dustman
Apr 13, 2007

🏆🏆🏆

Internet Janitor posted:

WalltBeef: It's probably not the fastest solution, but if all you care about is 2d there's always the AWT Polygon class. Check out the contains() methods.

When working on some GIS stuff I tried that at first, got annoyed and ended up just making my own stuff.

RitualConfuser
Apr 22, 2008

WalletBeef posted:

I am working on some code which needs to determine if a point on the earth is within a polygon. Are there java libraries which would allow me to do this?

Look into GeoTools. The Polygon class from AWT wouldn't deal with various edge cases.

E: Actually, going straight to JTS might be a bit simpler depending on what you're trying to do.

RitualConfuser fucked around with this message at 03:38 on May 20, 2010

Canine Blues Arooo
Jan 7, 2008

when you think about it...i'm the first girl you ever spent the night with

Grimey Drawer
I've been contemplating how to build save files for an app I've been working on. The data is mostly numeric and there are about 30-50 fields per save. I was originally going to just stick the data in a plain text file and read and write straight from there, however, I figure it may be easier to try to do it in a different way.

One of the ways I thought that'd be cool to try was to store said data in an Xlsx file and read out of there. The advantage is that the data is much more organized and readable. The disadvantages include having to deal with excel every time I want to view the file among other things, but I figure it would be an opportunity to learn how to use a package in Java so I justify doing it by writing it up as a learning experience.

Looking through some solutions, I found This which looks to provide very promising functionality for this little project.

My question is this: Is this a good idea? Am I digging myself a whole that's going to be very difficult to dig my way out of? Are there better solutions for this?

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.
I would use something like XStream or JSON serialization libraries before I would make it an Excel file. Seems like massive overkill for just persisting things to disk, unless you have a specific requirement to have an excel file. POI has a lot of options that might be a little daunting for a newbie, as well.

Links:
http://xstream.codehaus.org/

http://www.json.org/java/

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."

Canine Blues Arooo posted:

One of the ways I thought that'd be cool to try was to store said data in an Xlsx file and read out of there. The advantage is that the data is much more organized and readable. The disadvantages include having to deal with excel every time I want to view the file among other things, but I figure it would be an opportunity to learn how to use a package in Java so I justify doing it by writing it up as a learning experience.

At work I'm developing an API for manipulating XLSX files, so I know a thing or two about the format. If all you're interested in is reading and writing some numbers in a sheet, it's not too bad, but many of the corners of the OOXML standard are absolute nightmares.

If you're interested in learning how everything fits together, I recommend downloading a copy of the OOXML SDK 2.0- even if you don't use .NET, the package comes with a searchable cross-referenced documentation viewer called the "OOXML Classes Explorer" that's packed with Excel-2007-specific gotchas and details.

TRex is probably right, though- XLSX is most likely massive overkill for whatever project you have in mind.

_areaman
Oct 28, 2009

When a client quits my server by properly exiting, the server acknowledges them, deletes them from the system, and notifies all other clients.

But when a client quits unexpectedly, like their computer crashes, terminating the process, losing internet, etc. I can't make the server recognize they are no longer active.

Going through the socket class, I have the server periodically check on sockets of clients. I've tried isClosed, isConnected, isInputShutdown, and isOutputShutdown, but none of them acknowledge when I have a client terminate unexpectedly.

How can I make the server realize when a client has quit? It must be some type of check on the socket. I know I could ping each client, and any client that doesn't respond is disconnected, but isn't there an easier way?

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe

_areaman posted:

How can I make the server realize when a client has quit? It must be some type of check on the socket. I know I could ping each client, and any client that doesn't respond is disconnected, but isn't there an easier way?

What are you expecting, some sort of "help I just caught on fire" packet? By definition, a client that goes down cannot tell you about it, because it's down. The only reasonable solution is to require periodic transmissions to keep the connection alive.

That said, you can get the TCP layer to do this for you; just set SO_KEEPALIVE on the socket (i.e. socket.setKeepAlive(true)).

Fitret
Mar 25, 2003

We are rolling for the King of All Cosmos!
I posted this in the Android thread, but that thread is sort of dead and this isn't really related to Android development, but general Java development. Anyway...


I'm trying to make a Wizards of the Coast's DDI Compenium viewer app for Android and I'm running into problems with authentication. Wizards of course has no documentation for their authentication method, and looking at all the threads on this issue, it appears that no one has really figured it out, or at least bothered to figure it out and post about it. However, I know there's an iPhone app that lets you browse the compendium, and it logs in for you, so it must be possible.

Their login page has a fairly basic HTML form:
code:
<form name="form1" method="post" action="login.aspx" id="form1"> 
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKLTMxMzExNzE1NGRkPb/13oDMUJchqfP74F0S6Ir26k4=" /> 
<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWBAK744fKAgKyzcaDDQLyveCRDwK4+vrXBeDExHjW9/520ziutTg1ie5Br1aJ" /> 
<input name="email" type="text" id="email" /> 
<input name="password" type="password" id="password" /> 
<input type="submit" name="InsiderSignin" value="Sign In" id="InsiderSignin" /> 
</form>
There are some session related variables, so first I parse the site to get those (that works fine). From there, it seemed like the easiest solution was to use an HttpResponse object to make a POST call on login.aspx. Then, I attempt to get the authenticated web page.
However, it's not working:

code:
public void onCreate(Bundle savedInstanceState) {
	    super.onCreate(savedInstanceState);
	    setContentView(R.layout.entry_view);
	    
	    Intent i = getIntent();

	    webView_entry = (WebView) findViewById(R.id.webView_entry);
	    webView_entry.getSettings().setJavaScriptEnabled(true);
	    
	    try {
	    	URL myURL = new URL("http://www.wizards.com/dndinsider/compendium/login.aspx"); 
	    	URLConnection ucon;
			ucon = myURL.openConnection();
			lex = new Lexer(ucon);
			Node n = lex.nextNode();
			String viewState = null, eventValidation = null;
			while (n != null && (viewState == null || eventValidation == null)) {
				String tag = n.toHtml();
				
				if (tag.contains("__VIEWSTATE")) {	
					tag = tag.substring(tag.indexOf("value=") + 7);
					tag = tag.substring(0, tag.indexOf("\""));
					viewState = tag;
				}
				
				if (tag.contains("__EVENTVALIDATION")) {	
					tag = tag.substring(tag.indexOf("value=") + 7);
					tag = tag.substring(0, tag.indexOf("\""));
					eventValidation = tag;
				}
				
				n = lex.nextNode();
			}
			
			if ( viewState != null && eventValidation != null ) {
				BasicResponseHandler brh = new BasicResponseHandler();
			    DefaultHttpClient client = new DefaultHttpClient();
			    HashMap<String,String> hm = new HashMap<String,String>();
				
			    hm.put("email", username);
			    hm.put("password", password);
			    hm.put("__EVENTVALIDATION", eventValidation);
			    hm.put("__VIEWSTATE",viewState);
			    hm.put("InsiderSignin","Sign In");
				
			    HttpResponse response = doPost("http://www.wizards.com/dndinsider/compendium/login.aspx",hm,client);
			    try {
					brh.handleResponse(response);
				} catch (Exception e) {
					Log.e(TAG, e.getMessage());
				}
			    
			    if ( response != null ) {
			    	webView_entry.loadUrl(i.getStringExtra("com.package.compendiumviewer.Url"));
			    } else {
			    	showDialog(BAD_PASS);
			    }
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 	    
	}
    
    public static HttpResponse doPost(String mUrl, HashMap<String, String> hm, DefaultHttpClient httpClient) {
		HttpResponse response = null;
	
		HttpPost postMethod = new HttpPost(mUrl);
	
		if (hm == null) return null;
	
		try {
			List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
			Iterator<String> it = hm.keySet().iterator();
			String k, v;
	
			while (it.hasNext()) {
				k = it.next();
				v = hm.get(k);
				nameValuePairs.add(new BasicNameValuePair(k, v));
			}
	
			postMethod.setEntity(new UrlEncodedFormEntity(nameValuePairs));
			response = httpClient.execute(postMethod);
			Log.i(TAG, "STATUS CODE: " + String.valueOf(response.getStatusLine().getStatusCode()));
		} catch (Exception e) {
			Log.e(TAG, e.getMessage());
		}
	
		return response;
	}
Any thoughts? The HTTP Post response returns a 200, so I have no clue how to even begin debugging this.

Malfeasible
Sep 10, 2005

The sworn enemy of Florin

Fitret posted:

...
it's not working:
...
I don't know Android programming, I only know some Servlet/JSP stuff but...

What is it doing exactly? Can you show the full response that you got back? Since you got the 200 status code I assume the server didn't choke on your request, but what did it send back to you?

Malloc Voidstar
May 7, 2007

Fuck the cowboys. Unf. Fuck em hard.
Yeah, either save every line of what your client is POSTing and what is returned, or somehow run a packet logger.

Oh, and try replacing the "/"s in __VIEWSTATE with "%2F" instead. Maybe for __EVENTVALIDATION too.

_areaman
Oct 28, 2009

rjmccall posted:

What are you expecting, some sort of "help I just caught on fire" packet? By definition, a client that goes down cannot tell you about it, because it's down. The only reasonable solution is to require periodic transmissions to keep the connection alive.

That said, you can get the TCP layer to do this for you; just set SO_KEEPALIVE on the socket (i.e. socket.setKeepAlive(true)).

Calm down calm down, I thought there might be some way to detect the socket is inactive, like maybe "isConnected" sends something to the other end of the socket and returns false if it fails, which seems completely rational to me. Thanks for the input though.

ynef
Jun 12, 2002

Aleksei Vasiliev posted:

Yeah, either save every line of what your client is POSTing and what is returned, or somehow run a packet logger.

Oh, and try replacing the "/"s in __VIEWSTATE with "%2F" instead. Maybe for __EVENTVALIDATION too.

tcpmon is quite good for this. You start it up, tell it to act as a proxy, it prints out both request and response. Simple and just what is most likely needed here.

Canine Blues Arooo
Jan 7, 2008

when you think about it...i'm the first girl you ever spent the night with

Grimey Drawer
New Question: I'm looking into trying to implement a recommended text-esq feature into a couple text fields. I'm not sure what this feature is called exactly which is making it difficult to search for but it works kinda like so:

Lets say I have a list of colors in an array of strings. Some of the colors in the array include red, green, grey, and white. What I want to happen in this text box is for an auto-complete recommendation to fill out below it based on an array I feed it. That is, if I type a "g" in the field, I want a box to come down that shows "green" and "grey". If you've ever used the homework software Aplia for Accounting, it works exactly like that.

Assuming one can gather what I want out of this based on what I've written, how could I implement this? I'd imagine something has been written to make this much easier, but without knowing what to call it, It's made finding information on it difficult.

tef
May 30, 2004

-> some l-system crap ->
It is called an autocomplete widget, or an autosuggest widget.

Malfeasible
Sep 10, 2005

The sworn enemy of Florin

ynef posted:

tcpmon is quite good for this. You start it up, tell it to act as a proxy, it prints out both request and response. Simple and just what is most likely needed here.
This is awesome! This is something I've been looking for to trouble shoot web-services, but the only ones I could find were for windows.

scanlonman
Feb 7, 2008

by R. Guyovich
Hi, does anyone know any good Java tutorials? I skimmed the first few pages and full out read the OP and didn't see any mention of it. I ended up settling with Netbeans as my IDE of choice.

Thanks!

[edit]


vvvvvv

gently caress, I feel dumb. Sorry about that.. :( Thanks!

scanlonman fucked around with this message at 02:51 on May 28, 2010

epswing
Nov 4, 2003

Soiled Meat

The OP posted:

Also Bubblegum Wishes recommends this series of videos teaching Java from the ground up using Eclipse.

korofrog
Dec 15, 2006
smell my face!!!
Hello all, I'm learning a bit of java and I'm trying to work on a personal project involving measurement conversion and I need some help with the logic and see if there's a way to simplify how I think it should be done.

Basically, I want to do some simple conversion of feet, meters, inches, and yards. What I'd like is to have four separate text fields and a single button and if I put a number into one field, it will calculate the other three fields after clicking the button.

My original thought is to check and see if x field != "", then it would call a conversion method and then populate the remaining fields. So I'm thinking at minimum there will be four if statements. Anyone have any better ideas or a link to a tutorial on what I'm trying to accomplish?

Jonnty
Aug 2, 2007

The enemy has become a flaming star!

korofrog posted:

Hello all, I'm learning a bit of java and I'm trying to work on a personal project involving measurement conversion and I need some help with the logic and see if there's a way to simplify how I think it should be done.

Basically, I want to do some simple conversion of feet, meters, inches, and yards. What I'd like is to have four separate text fields and a single button and if I put a number into one field, it will calculate the other three fields after clicking the button.

My original thought is to check and see if x field != "", then it would call a conversion method and then populate the remaining fields. So I'm thinking at minimum there will be four if statements. Anyone have any better ideas or a link to a tutorial on what I'm trying to accomplish?

That's pretty much it. You'll have to make an executive decision regarding what to do if they've filled in 2+ boxes - probably just take the first filled one and ignore the rest - but the way of checking would be just a bunch of if statements, yeah. Don't forget sanity checking when you're working with numbers in strings!

Adbot
ADBOT LOVES YOU

yatagan
Aug 31, 2009

by Ozma

Jonnty posted:

probably just take the first filled one and ignore the rest

Here's a better way, remember which was last filled in by the user.

code:
KeyListener keyListener = new KeyListener() {
	public void keyPressed(KeyEvent e) {}
	public void keyReleased(KeyEvent e) {}
	public void keyTyped(KeyEvent e) {
		if (e.getSource() instanceof JTextField) {
		        //lastFilledIn is an instance variable of the enclosing class
			lastFilledIn = (JTextField)e.getSource();
		}
	}
};

JTextField myField1 = new JTextField();
myField1.addKeyListener(keyListener);
JTextField myField2 = new JTextField();
myField2.addKeyListener(keyListener);

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply