JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Add print statements after each line to print out the values that were set/changed on that line. Then you'll be able to understand how it works.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

To be honest - some variant on that read/testEOF combo is in most programs that read from a file. I would really have to classify it as a common standard pattern. It's only "rare" in applets. But don't worry, some of us have been using Java since last century but still keep coming across things we didn't know about it.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I can't make any sense of your undocumented code, but in general:
There is no restriction in Java anything like "only first function can access the variables."
Methods can share variables that are defined at class level, but not any variables that are declared within a method. If you declare a variable within a method that has the same name as a class variable then there is no compiler error, but it's very confusing.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

It looks like tmp is a 50MByte array which you copy at least once, so you're probably just exceeding the default memory allocation for the JVM. This link is a decent summary of what you need to know...
http://javarevisited.blogspot.com/2011/05/java-heap-space-memory-size-jvm.html

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Although that approach can work, at least for a fixed size list of values, it's a pretty heavy way to overcome the OP's problem which was how to print an array of Strings.
A better answer would be to use the Arrays.toString method, as in

System.out.println("Values of tree map: " + Arrays.toString(tMap.values()));
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Maybe your problem is that you get and update the Graphics in mouseMoved, but Swing doesn't know that you have done this. Swing is by default double-buffered, so the screen isn't getting updated with your new line until something else happens to cause a refresh of the screen.
If you want to do it that way you should call repaint() after drawing to the Graphics. However, in general, updating the component's Graphics outside paintComponent(..) isn't a great idea - it's hard to coordinate your drawing with Swing's event handing, eg on a window re-size.. It's normally better to update some data that describes the line in your mouse listener (or draw the line to your own off-screen graphics buffer), then call repaint(). Draw the latest version in paintComponent when that gets called by Swing.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

chars are numeric values that are used to represent characters. You must always distinguish between the two, ie
char c = 0;
is not the same as
char c = '0';
in the second case c has the value 48.

From the API doc of Integer.toBinaryString
... The characters '0' ('\u0030') and '1' ('\u0031') are used as binary digits.
So your chars are '0' and '1', ASCII numeric values 48 and 49 respectively. The logical operators work with the numeric values, not the character representations, so you may need to rethink your code a bit.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Every public class must be in its own .java file with the same name as the class. You can't have 2 public classes in 1 file.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

If you have one listener for multiple text fields then you can get the source of the event from the CaretEvent that's passed as a parameter to your caretUpdate method, eg

public void caretUpdate(CaretEvent e) {
   if (e.getSource() == myFirstTextField) { ...
   else if ((e.getSource() == mySecondTextField) { ...
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The "import java.io is never used" message means what it says - you don't need that import and can simply delete it.
I'm not a Linux buff, so I don;t understand the second half of that output.

But this should definitely run:

public class HelloWorld {
  public static void main(String[] args) {
    System.out.println("Hello, World");
  }
}
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

If I understand your question, then yes. eg
ArrayList<String> = ...
ArrayList<Vector<String>> = ...
etc

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You don't need to. Use an Employer class with an ArrayList of Employees, eg

class Employer {
   private ArrayList<Employee> employees = new ArrayList<Employee>();
   public void createEmployee() {
      String name = (prompt user to enter a name)
      employees.add(new Employee(name));
   }
   public List getEmployees() { // eg to display in a list box or menu
      return employees;
   }
}
...

If you display the employees in a listbox you can use the selected employee to call addJob or whatever.
Or maybe you will use a getEmployeeByName(String name) method to get a particular Employee (in which case maybe better to use a Map<String, Employee> rather than an ArrayList<Employee> to hold the Employees?)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
static String name;
static double perDayCharge;
static double maximumCharge;

static means that there is only one value for this variable, and all instances of the class share that same single value. I bet that's not what you intended!

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

All you need is an Employee class, whose members include a collection (eg ArrayList) of Jobs, and a Job class whose members include an Employee (or collection of Employees if a Jab may involve multiple Employees). You can also have an Employer class whose members include a complete list of Employees and Jobs. The Employer class is also where you will have methods for adding Employees, creating new Jobs, and assigning Jobs to Employees.
None of this involves hard coding any data at all.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That's because you go ahead and compute the average, even if there are no numbers. The average calculation is sum/count so if count is zero you get a divide by zero error.
After the user has entered his numbers, but before you calculate the average, you can test for count == 0 and stop there (eg return; from your method).

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That's an awful lot of drawing to repeat every 20 mSec, especially since nothing changes except an x position offset.
Why not create an Image and draw the car into that just once, then you can draw that Image to the panel's Graphics with a single call, which will be just one place to specify the x position of the whole car?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Of course we will help you through it. Make a start, and if you get stuck post the complete details of whatever it is that's stopping you progressing.

What? You didn't expect anyone to do it for you, did you? That would be cheating.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

At line 50 you have retrieved an array containing the file names.
JList has a setListData method that takes an array as a parameter and displays the contents of the array.
So you just need to create a JList somewhere in your window and call its setListData method passing the array of file names.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Hi stultuske and stevanity
I just picked up on this thread, and there's one post I wanted to clarify...

public String classlist(){
    return classlist();
  }

will indeed give you errors. remove the brackets, after all, you're not trying to return the method, but the values

the reason for the syntax error is you have added a "()" after "return classList" statement. remove the brackets.

This perfectly valid source code does not generate a syntax error, nor does it try to return a method. It's a simple recursive call that returns the value returned from calling classlist(). Mind you. although the syntax is valid, the runtime effect is simply an infinite recursive loop that will very quickly throw a stack overflow, so it's totally useless in practice.
Sorry if this sounds pedantic, but with most readers being newbies I think it's important to be precise about these things. I'll go away now and leave you all in peace...

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

.. and a few notes on the GUI specifically:

You don't need all those this. qualifications on your variables and methods.

Your menus are perfectly sensible for this size of app, but as things grow you will start to get more & more complex - eg if you duplicate any menu items by adding a toolbar, or some right-click context menus. If you are considering going that way it's better to use Actions ( http://download.oracle.com/javase/tutorial/uiswing/misc/action.html ). Even if you don't but you do add more menus, the use of a single listener (this) with a load of if (source is A) else if (source is B) else if ... gets really untidy and hard to read. Things scale better with one listener per menu item, using an inner class. Personally I prefer the anonymous inner class version.

You have a number of methods that throw Exception rather than catching it. In general this isn't a good idea. When you get an E you want to display the stack trace, plus as many relevant variables as may help diagnose the problem. If you throw the E up to the calling method you lose much of the context in which the E was originally thrown, which makes it hard to understand. More seriously you lose the ability to have a finally clause that tidies up after the error.
If you want to signal a problem to a calling method you should still catch it where it …

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I just had a really quick look and my immediate impression is of good quality code. Variable & method names, plus relevant comments make it easy to see what's what. Lots of runtime tracing to confirm good behaviour (maybe an idea to use a simple Logging class rather than System.out so you turn them all on/off easily?).
My only area of question is re the lock (should be Lock!) class where you seem to have home-brewed a pile of functionality that's already available in a fully-designed fully-debugged bullet-proof form in the existing Java SE API? I'm not the best person to take that any further but maybe someone who's more of a Locks & Threading guru could comment?
But, in summary, there's nothing in this that screams "inexperienced" to me.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That's great! Please now help everybody else here by explaining how you solved it. Thank you.

mKorbel commented: hehehe +9
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Line 118 is in this context:

big.addActionListener(new ActionListener() {
  public void actionPerformed(ActionEvent event) {
   String Selection = event.getActionCommand();

This code is only triggered by the big button, so there's no point testing

if(Selection.equals("Big")){

... even if you do code the if test correctly (see my earlier post)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I understood it to be numbers like 321 or 987, but not 123 or 999. I think there are 120 3-digit numbers that meet the definition and 880 that don't.
I would use 3 nested for loops - one for each of the three digits, although it's possible with while loop(s) as well, if you prefer.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You can compare aobj with the possible JComponents that it could be, eg

if (aobj == myJTextField1) ...
else (aobj == myJTextField2) ...

When you know what the source is, you can cast aobj to the appropriate class, eg

if (aobj == myJTextField1) JTextField tf = (JTextField) aobj

or maybe all the possible sources are JTextFields anyway so you can start with

JTextField source = (JTextField) caretEvent.getSource();

Finally, depending on how many components share this listener, and how similar or dissimilar their processing is, it may be best to have a different listener for each component so you don't need to check what the source was.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

So you have multiple "datastrings" each of which has info1;info2;info3 values associated with it. Is that correct?
If so, definitely start with a small class that encapsulates a datastring and its associated infos. You can then put those objects into a static map with the datastring as key. That will get you off to a decent start.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
  1. Post your code in CODE tags so we can read it.
  2. frame.getContentPane().add(pane); the getContentPane() hasn't been required since Java 1.5
  3. Never override paint(), override paintComponent instead.
  4. Because your custom JPanel has no components in it Swing doesn't know how big it is, and probably has its size as 0,0 So the scroll pane won't do much. You may do better by setting your panel's size to a suitable value
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That's the idea! Now maybe the next array will have numbers between 1000 and 2000 in it, so ideally you should start with a much bigger number, say 1000000.
Best of all, there's a constant in Java called Integer.MAX_VALUE which is the largest value an int can possibly have, so that's the very best starting value for min.

Average is sum/count, and you don't have a final value for sum until the loop has finished looping, so it makes no sense to calculate it inside the loop.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The List interface shows the remove methods as optional, and adds the following for all the remove methods:

Throws:
UnsupportedOperationException - if the remove operation is not supported by this list

Arrays.asList has the following documentation

public static <T> List<T> asList(T... a)

Returns a fixed-size list backed by the specified array. (Changes to the returned list "write through" to the array.) This method acts as bridge between array-based and collection-based APIs, in combination with Collection.toArray(). The returned list is serializable and implements RandomAccess.

This method also provides a convenient way to create a fixed-size list initialized to contain several elements:

So it looks pretty clear that the List returned from asList will not support List's optional remove methods

ps If you want to continue using the asList approach then you need to do something like

ArrayList<String> list = new ArrayList<String>(Arrays.asList(arr));
peter_budo commented: You beat me to the answer +16
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

setUndecorated(true);
(do this before making visible etc)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The EDT is an ordinary thread. It's started somewhere in Swing's startup code. The only thing special about it is that there are lots of classes and methods within Swing that use it.

javax.swing.SwingUtilites is a perfectly ordinary class, like javax.swing.JLabel or java.lang.String. It has variables and methods like any other class, and one of those methods happens to be invokeLater. There's absolutely no magic here, none of these things is any different from classes and methods that you write yourself or threads that you start.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

1. Anonymous inner class is slightly shorter code, and keeps it all in one place, but you can have an ordinary named class that extends Runnable if you prefer.

2. The EDT is a Thread, which is managed by Swing. Swing maintains a queue of "things to do" (screen repaints, events to post etc) and runs them one at a time on the EDT. The "things" on that queue are Runnables. invokeLater is an ordinary method in the javax.swing.SwingUtilities class that simply places a reference to your Runnable on the queue. When your runnable gets to the front of the queue Swing calls your run method on the EDT thread.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You have

do {
   ...
while(Registrant == 0);

ie keep doing the loop as long as Registrant is 0
Can you see why that's wrong?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Do you know how to execute a method when a button is pressed? If not, start with the tutorials.
Your button handler just needs to inform, the controller that the button has been pressed so a new customer must be created and added to a queue. You already have Model methods to do those things, so the controller just has to call them.
Beginners often make the mistake of doing the GUI first then don't know how to perform the actual functions. You are in a much better place because you have a Model with all the functionality easily available via public method calls. All you have to do is call the appropriate methods when a button is clicked. It really couldn't be much easier! I think if you just get stuck in and give it a go you'll find that there really isn't a problem.

ps: the grid layout is a bit of a distraction here - the whole listener/controller stuff is the same regardless of the GUI layout.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

It's just a perfectly normal method in the java.io.PrintStream class, just like print and println. It's just a bit newer, that's all. If you create a PrintStream explicitly you'll need to import it, but it's normally used via System.out

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

There is no 'printf()' in Java.

Sorry, but yes there is. It was added in Java 1.5 This is from the API doc for PrintStream:

public PrintStream printf(String format, Object... args)

A convenience method to write a formatted string to this output stream using the specified format string and arguments.

JeffGrigg commented: Useful information. +7
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I won't around for the full 8 hours, but if you get started I'll try to support you with information and problem solving as far as I can (and so will others on DaniWeb, I'm sure), but you'll still have to do the real work.. Good luck!

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

If it crashed then you were doing something wrong - the whole of Swing relies on mouse listening, and its really solid code. Try again?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

RequestDispature red = request.getRequestDispature("xyz");

What happens here is that the getRequestDispature method is called on the object request. Somewhere in that method it obtains an instance of some class that implements RequestDispature. Nothing in that line of code tells you what class is or how it gets it, all you know is that it implements RequestDispature. Because you are assigning that result to a variable of type RequestDispature everything is OK.
If you want to know more you can look at the documentation for getRequestDispature, and see how it declares its return type. Maybe that's just RequestDispature, or maybe it names an actual class that implements RequestDispature. Also at runtime you could print red.getClass() which will tell you exactly what kind of object was returned from request.getRequestDispature

This is a common thing in Java - for example you may have a method
public List getSomeStuff()
List is an interface, so you can use all its methods on the returned List. But inside getSomeStuff you will find an instance of ArrayList, or LinkedList, etc. It may even return a different class depending on some internal criteria.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Your new Runnable is an example of an anonymous inner class.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes, OK, but what are lines 32 and 33 doing there - the input is in the text field, not in System.in. Just delete those 2 lines and see what happens.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes, setIcon(icon);, or super(icon); as the first line of your constructor, gives the JLabel code access to your icon. Excellent!
I'm sorry if I made you work too hard for that, but I do believe you learn so much more when think right through to the solution yourself, and not just copy/paste something.
For the setBounds - you don't say what layout manager you are using, but you may need to call pack() on the parent to get the layout manager to use your new bounds.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The continue statement skips the current iteration of a for, while , or do-while loop. Since yu don't have any of those, it's not a valid use of continue.
Look at the second part of this tutorial
http://download.oracle.com/javase/tutorial/java/nutsandbolts/branch.html

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Whenever you update the vote data, call repaint(); on your PollDisplayPanel. This will result in Swing calling your paintComponent, where you will re-draw the pie chart using the latest values.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

At the four places where you construct the question you can also calculate the correct answer, and save it in a variable so you can check the user's answer against that value when they press "submit".

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Leave it like that if you want. It doesn't work, and crashes with an error message, but maybe that's OK?

Of course you can fix it. Look at the last line of my previous post. It tells you what you need to know, you just have to read it carefully and think about what to do with that information.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Quick answer: call textfield2.requestFocusInWindow();
Proper answer: read this tutorial to understand how Swing manages moving the focus, and how you can control it:
http://download.oracle.com/javase/tutorial/uiswing/misc/focus.html

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Excellent! Please mark this solved so others will know.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK, this is fun! The Map is the way to go.
Have a Map that maps a String name to double array. HashMap is the one to use here:

Map<String, double[]> names = new HashMap<String, double[]>();

when you need a new array just add it the map

names.put("Matthew", new double[15]); // new array with name Matthew

then you can just retrieve the one you need

double[] temp = names.get("Matthew");

or use them directly

names.get("Matthew")[0] = 12.3;
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes, you need to create new Objects, one for each array element, not just references (pointers) to objects.
The only way memory allocation is going to fail is if you run out of memory in the Java VM. In that case you will get a OutOfMemoryError exception thrown, but frankly there's not a lot you can do practically at that point except let the program crash and increase the VM memory settings for the next run.