Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Two suggestions:
1) Read the forum rules on using proper English - not text-speak - here: http://www.daniweb.com/forums/faq.php?faq=daniweb_policies#faq_keep_it_clean
This isn't a chat room.

2) Use the search function. There are probably a thousand "Need a project topic" posts for you to peruse.

Nick Evan commented: yup, that works for me +8
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Homework or self-study, it comes down to the same thing - if someone can't show that they have put any effort in solving the problem then they shouldn't expect someone here to just hand them a solution.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Well, actually those directions aren't quite correct on the tutorial page. The file they reference has a package declaration

package start;

but they do not mention that and the command to run that file won't work as they have it written. Remove that package declaration and re-compile it and it should work fine.

If you leave in the package statement, you would need to have that class file in a directory called 'start' and from it's parent directory you would execute it as follows

java start.HelloWorldSwing
peter_budo commented: Thanx for the tip :) +9
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

And that stack trace tells you exactly which line it occurs on, so where is it? Have you walked through the execution to see why that variable would still be null when you try to access it?

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

This is the Java forum - not Javascript, which has it's own forum in the Web Development section.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I really didn't think something like this would be this hard. It's going to take awhile, and a lot of study and practice, but I am going to eventually figure it out.

You never "finish" learning good design skills. Each project is different in some way (if it wasn't, you would just keep using the first one right?) and there are many possible ways to design it. Finding the one that best suits the particulars of the problem at hand is the "art" portion of programming and comes only through experience - it's also the challenging part that keeps it interesting.

While good design skills only come with experience, there are several good books available with valuable and thought-provoking advice. If you're interested, I would recommend:

Design Patterns: Elements of Reusable Object-Oriented Software - the canonical book on software design patterns. You will surely here criticism regarding the overuse of patterns and some can certainly be "overkill" for a lot of simple design tasks, but reading and knowing about them will give you a perspective on design and object interaction that you won't get from simple coursework or tutorials.

Refactoring: Improving the Design of Existing Code covers just what the title says: Improving the design of code you already have written and working.

Code Complete, Second Edition has all kinds of useful information and advice on many aspects of programming, design, and software project management. While geared more towards working …

Alex Edwards commented: I will have to purchase those books sometime soon =) +2
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You will need to override the toString() method or provide some other method like toFileString() that returns the line of data that you need to record.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Then it seems you are incapable of performing that job and another should be hired to do it instead.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You can use a simple comma-separated value format for that then. Record the type of the object first, then the values that you need to re-create.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Yes, I received a PM asking for a project topic. In the same awful text-speak, as well.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You can serialize the entire object to file in it's current state by implementing the serializable interface. Here is a technical doc on that: http://java.sun.com/developer/technicalArticles/Programming/serialization/

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Also, do not send PMs to plead for project topics.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Well, you are off to a good start by choosing to hijack an old thread in the Java forum to ask someone to walk you through it.

Post your question in the C++ or C# forum and don't be surprised if you get very general answers to such a general question.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Are most companies like this? I guess it'd be excusable for small companies, but there is like 100 people in this department, about 20 are developers.
Honestly, cannot wait to leave this place. I mean, there were times when i was literally depressed for weeks at this place.

Most? Who knows? But it's certainly not uncommon - and it's got nothing to do with the size of the company. The one thing you can be sure of is that it isn't likely to change anytime soon, so just bail if you can't accept it as just part of the job. Software development gets horribly mismanaged all of the time. You learn to live with some level of it and promote better practices wherever you can, or you polish the resume and hit the bricks.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I believe that you can call isDisplayable() on the frame to determine if it has been disposed.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I see the same behavior occasionally with Firefox on threads with absolutely huge code posts.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

And... ? Did you have a question?

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Well, you certainly have nothing to lose by starting to look. Worst case you cannot find anything. Best case you find an excellent job with a stable company. In fact, if you are really concerned about layoffs, looking around now rather than getting caught flat-footed with no job and a family to support seems like a prudent thing to do in my mind. At the very least you will have a better idea of what to expect from the job market if you decide to stay with your current company for the time being.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

jasimps suggestion of using a List is generally the best way to handle a collection like that where the number of elements in unknown.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

The Swing Timer is great for a lot of things. It just depends on your expectations of precision. The piece to keep in mind with them is this part from the api doc

Although all Timers perform their waiting using a single, shared thread (created by the first Timer object that executes), the action event handlers for Timers execute on another thread -- the event-dispatching thread. This means that the action handlers for Timers can safely perform operations on Swing components. However, it also means that the handlers must execute quickly to keep the GUI responsive.

If a handful of milliseconds or even a half-second perhaps don't have much impact on the operation you are performing, say like updating a GUI text field or repainting a graph or some such, the thread timing is of no real consequence. If more accurate timing is needed, or in your case constant accumulation of a time value over many firings of the timer, then the uncertainty in execution time can become a concern.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I really wouldn't recommend trying to keep accurate time information by incrementing your own variables, since you have little control over things like processor time-slicing and garbage collection. This portion here presents an additional unknown

ActionListener al = new ActionListener(){
		public void actionPerformed(ActionEvent e){
			finishTime++;
		}
	};

That listener code will execute on the AWT event dispatching thread, in a single-threaded queue with all of the other AWT events. You have no way of knowing exactly when actionPerformed() will get executed.

If you need accurate timing use System.nanoTime() in conjuction with variables to capture the time at crucial points and make timing decisions based on a calculated elapsed time against the current value of System.nanoTime().

Alex Edwards commented: Thank you for the clarification on how Timer really works. I wasn't aware of its unpredictable execution. +1
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Why are you so concerned that it's not explicitly null? dispose() is sufficient for all practical purposes that I can think of

Releases all of the native screen resources used by this Window, its subcomponents, and all of its owned children. That is, the resources for these Components will be destroyed, any memory they consume will be returned to the OS, and they will be marked as undisplayable.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Actually the language spec makes no guarantee as to when or what order finalizers will be called or which thread will call them.

The Java programming language does not specify how soon a finalizer will be invoked, except to say that it will happen before the storage for the object is reused. Also, the language does not specify which thread will invoke the finalizer for any given object. It is guaranteed, however, that the thread that invokes the finalizer will not be holding any user-visible synchronization locks when the finalizer is invoked. If an uncaught exception is thrown during the finalization, the exception is ignored and finalization of that object terminates.

The whole section on finalization is here: http://java.sun.com/docs/books/jls/third_edition/html/execution.html#12.6
Also, System.gc() and System.runFinalization() are documented as only "suggesting" that the JVM perform these operations.
Anyway, the people here in C++ world probably don't care much about the details of Java garbage collection, so I won't drag along the discussion :)

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Have you bothered to look them up?
Java EE and http://en.wikipedia.org/wiki/J2EE
JavaScript

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Well, re-reading the problem description

Long int number of seconds into minutes, hours and days and centuries and what have you.

has nothing to do with converting a single long into a string and inserting a comma between sets of three digits. It's a matter of applying the appropriate division operations to determine the desired unit of measure intervals and building a result string with that info. i.e.

System.out.println(centuries + ", " + days + ", " + hours + ", " + minutes + ", "+seconds);

or using the formatted printf() function to format the result string.

Not knowing what you have covered in class, it's hard to say what the instructor is expecting.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Pointer arithmetic is one thing. Such as traversing an array by incrementing the pointer. That is not possible with references.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

It's much easier to use a GeneralPath for drawing arbitrary shapes such as a graph. It is basically just a series of connected points. Here is the tutorial link for it: http://java.sun.com/docs/books/tutorial/2d/geometry/index.html

It accomplishes the same thing as many drawLine() calls between all of the points.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

How To Use Tables in the Swing tutorial.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Since you are using Runtime.exec() to execute it, the standard output is already redirected to the parent process, which is probably why nothing is getting written. Take a look at the Process API for info on handling that output. You should be able to just get the output as a stream(the method is actually called getInputStream() because it's an input stream to your program from the output stream of the process - a little bit confusing in name) and write that to a file with a BufferedWriter.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You can use String.valueOf(long) to get a long into a string.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Pointers allow you to alter the memory address itself, not just the contents of that memory address. The C++ gurus here can probably give you a lot better answer, but this FAQ might help a bit: http://www.parashift.com/c++-faq-lite/references.html

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You might want to consider translating your origin to a point in the middle of the selected component of your drawing before you render it and positioning the viewport over that new origin. You would also need to ensure that the JPanel gets sized such that all of the drawing would be visible.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

The books "Head First Java" and "Core Java: Volume 1" are both good places to start if you want to go the book route. They'll provide more detailed step-by-step explanation of things than most individual tutorials you'll find on the web.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Really? Like what (genuine curiosity)?

Well, if you take a glance at the API docs for Java SE (Standard Edition, not EE which denotes the Enterprise Edition APIs) you'll quickly see that a majority of the content is unrelated to or not specific to networking or web concerns. It encompasses things like basic i/o, collections, math, graphics, printing, GUI components, event handling, multi-threading, database access, regular expressions, xml, cryptography, security, and a lot more. Some of those can certainly apply to network operations, but they are by no means specific to them.

Just wondering - I've begun to write some games, and I find that I'm heavily reliant on linked lists to keep track of any set of objects that change during runtime (like bullets). How do you handle stuff like that in Java?

Just like you would in C++. Java's references function just like pointers with the exception that you can't alter the memory address itself. A basic linked list just needs a reference to the head element and the next element. Linked lists, doubly-linked lists, circular linked lists, stacks, queues, and any other generic data structure for handling collections of things are easily implemented in Java. The standard API even offers many implementations of them for you in the Collections Framework

That's not what I'm trying to say. My current perspective of the two was that C++ is more, I want to say "basic", but that seems like the wrong word. To …

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

In Windows, ">" is used to redirect output. The command below will send the standard output (stdout) of "SomeProgram" to a file named "out.txt"

java SomeProgram > out.txt

You can find more information on Windows command redirection here: http://www.microsoft.com/technet/archive/winntas/deploy/prodspecs/shellscr.mspx#EIIAE

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Well, you could pipe the command line output directly to a file with just the OS syntax, but if you want your program to do the file writing just add use a second arg as the the output file path and use a BufferedWriter to write the output similar to this

if (args.length<2){
    System.out.println("Usage: <YourParserClass> inputFile outputFile");
    System.exit(1);
}
File inFile = new File(args[0]);
File outFile = new File(args[1]);

// ... your operations here (including args validation)
// then write it out with BufferedWriter
try {
    BufferedWriter out = new BufferedWriter(new FileWriter(outFile));
    while ( stuffToWrite ){
        out.write( stuff );
        out.newLine(); // If you need to...
    }
    out.close();
} catch (IOException e) {
    e.printStackTrace();
}
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Well, unless you post specific questions that you would like answers to, no one can really help you out. The context you have given of a "book report" isn't clearly related to this site and thus it's pretty difficult to tell you much that would help.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Well, it seems about as relevant doing your report on kittens playing in a box, but that's between you and your instructor I suppose :P

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Exactly. You are just supporting the same point that I was trying to make: each has it's own strengths and weaknesses that need to be taken into consideration when deciding which to use for a specific purpose.

Alex Edwards commented: Ezzaral, you rock dude! +1
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Um, you realize this site isn't a book, right? There's little to tell about the site that should be in a book report - since those usually report on, well, books...

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

No, there isn't a specialized operation like that. It's a generic image manipulation API - not Photoshop.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

C++ is powerful.

And Java is powerful and so is Assembly.

As was mentioned, the JVM was written in C++.

It couldn't be written in Java, now could it? This is irrelevant.

If you can't do something in another language, do it in C++.

Or some other language. Take your pick, there are a ton to choose from.

As is evident by the fact that the JVM is written in C++, you can create languages with C++.

You can create languages from most any language. They are just mechanisms to convert text instructions to machine code.

Almost all of the software you use relies in some way on C++.

No, it all relies on machine instructions, as does C++ itself.

Certain things in C++ just seem like they're more correct than in other languages.

Seem more correct to whom? You? Computer scientists? Your third grade teacher? Jesus? "Seem more correct" is hardly an objective basis for any comparison.

I'm just beginning to learn Java, but Java seems to be a very web-oritented lanaguage

It was originally designed with network computing needs in mind, yes, but there is plenty in Java that has nothing whatsoever to do with networks or the web.

(I read somewhere that its web oritentation iS why it doens't have pointers - since one of the qualities of being web-friendly is security, getting rid of pointers ensured that Java programs can't access memory outside of the JVM).

Not allowing direct …

VernonDozier commented: Great post. +5
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

There is a Java interface to ImageMagik that you could use if you want a third-party solution. Other than that, you would need to perform the image analysis yourself to isolate the sub-region and create the new image from it. The Advanced Imaging API would be useful for that.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Sure, it's stickied right at the top of this forum. labeled "Read Me: Starting Java": http://www.daniweb.com/forums/thread99132.html

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Perhaps you should be more concerned with attending to your studies than whether your phone is "trendy and expensive looking" or "out of fashion".

Salem commented: Damn straight! +18
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Try

String userName = System.getProperty("user.name");
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Does your book not have any examples at all? No code, just descriptive text?

public void oneParamMethod(int firstParam){
...
public void threeParamMethod(int firstParam, double secondParam, String thirdParam){
...
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Stick with the first suggestion - use DecimalFormat.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

If I get some time later in the day, I may be able to fiddle around with this a bit, but in the mean time, here is a very extensive FAQ on generics and type erasure that might help:
http://www.angelikalanger.com/GenericsFAQ/JavaGenericsFAQ.html

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Why not find out for yourself? Run those lines (well, check your syntax before you do, because it's incorrect and "end;" isn't a valid statement) with System.out.println() calls after the operations and see what you get.

Your own computer will give you answers to questions like this much quicker and more accurately than anyone on the net.