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
such a nice boy
Mar 22, 2002

Contract Otter posted:

I've now gone through two courses of Java-programming in my university and while I feel I know the basics of the syntax and object orientated programming,

Don't say orientated.

Adbot
ADBOT LOVES YOU

such a nice boy
Mar 22, 2002

Since you know the format of the student ID, you can use that as a reference point. Look for 3 numbers, a dash, two numbers, a dash, four numbers (use a regex!). Everything before that is the name. After that, you'll have two fields separated by whitespace, so that's easy to parse.

such a nice boy
Mar 22, 2002

Phillyt posted:

What's a regex?

A "regular expression". It's a way of matching text. I googled a bit and this looked like a good page for beginners:

http://gnosis.cx/publish/programming/regular_expressions.html

and here's the Java Regex lesson:

http://java.sun.com/docs/books/tutorial/essential/regex/

Regexes are incredibly useful when trying to parse text. Every decent programming language has support for them. You need to know how to use them.

such a nice boy
Mar 22, 2002

Phillyt posted:

I can't really figure out where to put the tokens. I have a .txt file named hello which is basically made up of entries like above but I am really bad at using tokens to scan it. Right now all I'm trying to do is check for \t delimiters. Here's my code:
code:
...
            while ((l = inputStream.readLine()) != null) 
            {
                outputStream.println(l);
            }
...

OK, so this is the core of your program. All it's doing right now is reading a line from inputStream and writing it to outputStream. What do you want it to do?

Well, you want to write the output in a standardized way. You want to be able to use something like this:

code:
outputStream.println("\"" + name + "\", <" + emailaddress + ">");
There's probably a better way to do that using some string formatting stuff but I haven't worked in Java in a while. Anyway, that line presupposes that the variables "name" and "emailaddress" have the right information in them. Let's write the code to make that true...

code:
// we're going to use a regex to find the student ID:
Pattern idpattern = Pattern.compile("\d{3}-\d{2}-\d{4}");
// then we split the original string at the student ID:
String[] items = idpattern.split(l);
String beforeID = items[0];
String afterID = items[1];
// and then you write some code here that figures out the name and address because I can't do homework for you...
String name = ????
String emailaddress = ????
Hope that helps. Use that Java Regex guide to figure out what I did with "Pattern" up there. I can't guarantee that this code compiles or works because I haven't tried it but the idea is right.

such a nice boy
Mar 22, 2002

shodanjr_gr posted:

Yet another SWING question (i managed to hack around and get my previous one fixed :P).

Is it possible to somehow add the SAME component (meaning, the same instance of a component) to two separate containers?
No.

shodanjr_gr posted:

edit: Second question, why the heck does the JVM get "clogged up" (for lack of a better term), when it captures mouse events on a container?

I move my mouse, over my container, and some times fail to get an update on it's position. Then i wiggle it around a bit, and get about 10-15 updates together...This really kills my GUI (im changing stuff inside my container, depending on the mouse's position).
Threading stuff. It's complicated. Read this:
http://java.sun.com/products/jfc/tsc/articles/threads/threads1.html

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