JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

is.read(bytes) reads some number of bytes into the array, then returns an int with the number of bytes actually read. That value is assigned to the variable read. Depending on the type of stream that may be a complete array-full of bytes, or some smaller number, or even, in theory, zero.

When the read() is at end of file it (obviously) doesn't read any bytes into the array, and returns a value of -1 to indicate eof. Thw while test tests for a -1 being returned, and stops looping when that happens.

eg Suppose yo have 300 bytes in a file, and a buffer size of 255
First read reads 255 bytes, returns 255, loop continues
Second read reads remaining 45 brtes, returns 45, loop continues
Third read is now at eof, reads no bytes, returns -1. Loop exits

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

It's certainly legal Java to append strings like that, but horribly inefficient - every + or += creates a new String object.
When you want to build up a String like that you should use a StringBuilder, which is a mutable class with methods like append(...) that are very efficient. When the StringBuilder finally contains the whole thing, call its toString() method to get a single immutable String with the same contents, eg

        StringBuilder sb = new StringBuilder();

        sb.append("The following ");
        sb.append(myArray[0]);
        for (int i = 1; i < myArray.length; i++) {
            sb.append(",");
            sb.append(myArray[i]);
        }
        sb.append(" are students\n");

        String result = sb.toString();
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

DaniWeb Member Rules (which you agreed to when you signed up) include:
"Do provide evidence of having done some work yourself if posting questions from school or work assignments"
http://www.daniweb.com/community/rules

Post what you have done so far and someone will help you from there.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

In that case you can use the ProcessBuilder class - it lets you start an external process, set its working directory etc.
See the usual API doc, or Google for tutorials

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

stultuiske's comments are correct, but his solution doesn't quite apply to your case. His advice is correct for printing an instance of a class you define, but not for printing ordinary arrays.

The Arrays class has a static toString method to convert ordinary arrays to sensible Strings for printing, like this:

System.out.println(Arrays.toString(myArray));

there's also a deepToString method that works for multi-dimensional arrays, eg

System.out.println(Arrays.deepToString(myNDimensionalArray));

ps Just for your info - the toString() method that everying inherits from Object tells you the type of the object and its unique hash code (normally same as its memory address). thus: [[I@1747b17 breaks down as
[[ - two dimensional array...
I - of integers...
@1747b17 - at that hex address in the JVM's heap.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Hi Xabush. Welcome to Daniweb.
I'm not going to join in any sematic debate about "intermediate", but I will refer you to the top sticky in this forum, which is a compendium of useful resources for learners. Doing actual projects is the best way to learn, so the second sticky may be helpful too.
Once you have the basics, "where next?" depends on where your interests lie and how you see yourself using Java in the future - custom desktop user interfaces, scientific computing, major corporate IT systems etc etc? If you start a discussion along those lines people will be able to comment with greater relevance.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

One that's declared in the class, but not inside the definition of any method or constructor, and isn't static.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That's just a restriction on inner class binding to local variables (just ask if you want he full explanation). Simply make your timer variable an ordinary instance variable and the inner class will be abse to use it.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Line 10 - the method name is spelled differently

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You really haven't posted enough code to show where the problem lies, but from those two lines here's a guess...
are you sure you are updating the mainPanel variable when opening the second main JFrame?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That all looks like good progress to me. There may still be mistakes (I didn't study every line) but what you are doing with the constrcutor and passing the values looks right. Have you tried it yet? Never be afraid to try to compile and run your code.

In your run method you could print the name (the thread ID won't tell you anything useful), and don't forget to have a loop that does the print numCheers times.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Here are some simplified answers to start with - you may want some follow-up questions.

A class is a data type - think of it as a struct plus some related methods. Eg a Person class has individual variables for for name etc, date of birth etc and methods to update or use those variables. Eg a Button object has all the data needed to define a GUI button, and methods to display the button, perform a callback when the button is clicked, etc.

An object is a instance of a class - eg {"John Doe", 12/12/1994} coiuld be a Person object - an instance of the class Person.

A method is like a function - you pass it some values as parameters, it processes them and (optionally) returns a value. In Java-speak a "function" is a method that doen't have any state info - ie the returned value depends only on the passed parameters.

Not everything in Java is an object. For reasons of efficiency there are also "primitive types" like int, boolean, char, float that are like their C equivalents.

Ordinary Java variables come in two types: primitive types just hold an int, float etc, and "reference" types hold a pointer to an object. It's a convention that primitive types have names that begin with a lower case letter, and classes have names that begin with an upper case.

Finally wrapper classes take a primitive vaue (int, char etc) and "wrap" it in a class because that attaches …

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

This is my 10,000th post in the DaniWeb Java forum. so I hope I won't get an infraction for being off-topic.

I just thought this would be the perfect opportunity to thank all the people who have helped to make this such a valuable and rewarding experience for me. I can't name them all now, but particular thanks go to peter_budo and Ezzaral who, 5 years ago, set me on the right path for "how to respond to a DaniWeb post", ~s.o.s~ who has forgotten more about programming than I ever will know (despite his being completely wrong about happiness) and mKorbel whose knowledge of Swing is even more amazing that his interesting use of the English language. Others deserving a special mention include masijade, stultuke, bestJewSinceJC, jwenting and the much-missed NormR1. Everyone else: you know who you are...

I'm really looking forward to continuing working with, debating with, and learning from all you guys.

10,000 thanks
James

mKorbel commented: +++ +10
~s.o.s~ commented: Congratulations! :) +15
Dani commented: Congrats!! :) +15
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Annoying? Absolutely not! Sensible questions, and good use made of the answers. Ideal.
Mark solved?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

A bit late (3 years) don't you think?

Did you try your solution? Do you have a complete minimal executable demo of it in action?

naresh1845 commented: yes +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You just copy/pasted your assignment without even a moment taken to explain what help you need. That's highly disrepestectful to the many people who give their time to help others here.

There are lots of people here who will freely give their time to help you become the best Java programmer you can be. There's nobody here who is interested in helping you cheat or doing your homework for you.

DaniWeb Member Rules (which you agreed to when you signed up) include:
"Do provide evidence of having done some work yourself if posting questions from school or work assignments"
http://www.daniweb.com/community/rules

Post what you have done so far and someone will help you from there.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Overridding paint rather that paintComponent is almost always a mistake. In this case you call super.paint - which paints the Panel and all its children, then draw the background image over the top of all that.

You may also need to set one or more of size/preferredSize/minimumSize for your JPanel because Swing doesn't know about your image, so it has no way to know how big the JPanel should be.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

This problem breaks down into two distinct stages:
1. Collect all the info from the user (10 names, 10 counts) and store those in two arrays...
then...
2. Using that info stored in the arrays, use a loop (see above) create and start 10 threads

You can't mix the user input and starting the threads because the user will take so long to type that any previous threads wil have finished long before you start the next one.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

What is your major subject for your degree? Plagiarism?

Seriously: If you need to "make an app" then just copying someone else's code is not going to qualify.

If you want help to design and develop a pothole detection app then please free free to ask any specific questions here.

rubberman commented: Indeed! +12
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes, but of course components calulate their preferred size using the metrics of their current font etc, so they scale properly with different environments.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Most components calculate a preferred size based on their contents, eg the text in a JLabel or the overall size of the children of a JPanel. Most layout managers use getPreferredSize rather than getSize. The layout manager will then often override that to make the components fit according to its own rules (eg all the components in a Grid are the same size). On average you are more likely to influence the layout manager by setting a minimum size.
If mKorbel is around he's a real expert on this stuff...

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

It's pixels

If you are using a layout manager like you should, then setSize is pretty much useless. With a null layout manager it sets the component size in pixels, and you look really silly when someone runs it on a retina display.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That's all wrong! import just affects the way that names are resolved at compile time. It has absolutely zero effect on what classes get jarred, or on the run time.
importing everything is a lot easier than importing just the classes you need, especially if you are not using an IDE that adds imports for you. It's possible that it may slow compilation slightly,but no so much thatyou would notice.
The danger in doing it is that some names are used in multiple packages, eg there'a List in java.util and another List in java.awt, and you may get incredibly confusing error messages, eg try...

import java.awt.*;
import java.util.ArrayList;
...
List<String> x = new Arraylist<>();
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Tables are split into two main parts - the visible GUI stuff, and the data for the table. This allows you to chose how to store the data any way you like, without affecting the way the GUI display works (and vice-versa). The part that holds the data is called the TableModel.
For simple cases, where there's nothing special about the data storage, you use a DefaultTableModel that does it for you, so you don't have to write any extra code. Similarly, the GUI part of the table has methods to access the data in the TableModel for you, so you don't need to bother with that either unless you have a special requirement.

Oracle's tutorials are an excellent source of info. Maybe not the easiest because they are so comprehensive, but an ideal place to go when a simpler tutorial hasn't answered all your questions, eg
http://docs.oracle.com/javase/tutorial/uiswing/components/table.html

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

If you are using Serialization (ie write/readObject) then bean standards are irrelevant, but you must declare every class involved as "implements Serializable" as a way of asserting that your classes don't contain anything the can't be serialized - eg references to live operating system handles.
If you are using javabeans XML serialization then you must conform to java beans standards, and the Serialization marker interface is irrelevant.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I'm not sure how it will interpret that classpath. Try specifying a complete explicit path to the jar file.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes, i n that case the jar should contain a folder A with the class file in that, and the classpath should include the jar file.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The package A has to be in a place that's in your classpath. If you have C:\Z\A\B\A\Print.class then A.Print is in C:\Z\A\B, so that's what has to be in the classpath.

Ps: Having two directories called A, one inside the other is perfectly legal, but pretty much guaranteed to cause confusion and mistakes.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

If someone gives me a hand with doing standard to vertex, I should be able to do vertex to standard.

This engaged my curiosity, and I found that vertx to standard is easy, so here's an attempt at that.
More important, this is an opportunity to show how "pointless" methods and classes(!) can make spaghetti code so very understandable.
First, let's have a couple of trivial classes for the two kinds of equation. Here the standard form:

class StandardQ {

    final int a, b, c;

    public StandardQ(int a, int b, int c) {
        this.a = a;
        this.b = b;
        this.c = c;
    }

    @Override
    public String toString() {
        return "Standard form: " + a + "x^2 + " + b + "x + " + c;
    }

}

The vertex form is the same, but I've implemented a little conversion method in there:

class VertexQ {

    final int a, h, k;

    public VertexQ(int a, int h, int k) {
        this.a = a;
        this.h = h;
        this.k = k;
    }


    public StandardQ toStandardQ() {
        // expand to  ax^2 + 2ahx + ah^2 + k
        return new StandardQ(a, a*h*2 ,a*h*h+k);
    }

    @Override
    public String toString() {
        return "Vertex form: " + a + "(x +  " + h + ")^2 + " + k;
    }
}

Still easy, yes?

Now a little test case:

    VertexQ vq = new VertexQ(2,-1,3);
    System.out.println(vq);
    System.out.println(vq.toStandardQ());

Which is also trivial to read and understand, and gives …

Doogledude123 commented: Much appreciated for the help. +2
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes, I think it should be a semicolon as well

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

stultuske: downvotes without a comment are, by design, anonymous, so beware of assuming you know who voted.
However, stressedout overstepped the mark by re-posting the same question, then posting two entries containing personal abuse, so I have banned him. This thread is therefore dead.
JC

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

When parsing the infix you can parse for parens, operators and numbers like you do now, but also parse for alphabetic tokens ie variable names (looks like you can assume single letter names?). Treat them just like numbers when converting to postfix.
In the evaluator, when you get an variable replace it with its numeric value and evaluate as usual. If the variable names/values are fixed you can hard code that; in general you could use a Map with the name as key and the current value.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Oh, did you say before this android? My answers were valid for Windows/Mac/Linux, I don't use android at all, but the same code should work as long as it compiles!

Edit: Your exception is documented as "The exception that is thrown when an application attempts to perform a networking operation on its main thread."
It seems there's a problem with where you have put the code in your application. There's no such exception for "normal" Java, so that's all I know, but this may help:
http://www.androiddesignpatterns.com/2012/06/app-force-close-honeycomb-ics.html

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

(Ignore previous version of this post - it doesn't work)

Sites may or may not respond to pings, so the only reliable way is to check a public service that definitely works. Eg try to make an connection to google.com on port 80 (google's search web site). eg

   InetAddress a = InetAddress.getByName("google.com");
   SocketAddress sockaddr = new InetSocketAddress(a, 80);
   socket = new Socket();
   socket.connect(sockaddr, 2000);

If the internet connection is unavailable for any reason the connect nethod will throw an IOException

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

5: which requirements did he fail?
6. did he fail both?

One way would be to have a couple of booleans,one for each condition, showing whether that condition was met or not. You already have if tests for those conditions, so you have all the code you need to set the booleans.
You can then use them to control some print statements: eg (pseudo code)

if (metCondition1) print "you passed criterion 1"
else  print "you failed criterion 1"
   or 
if (didn't meet both) print "you must repeat"
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That's the output I would expect from line 13/14.
Did you enter 3 values for examscore, assessment, fees? Followed by a carriage return?

It's clearer for everybody if you prompt for one value at a time, eg (pseudo code)

print "what is the exam score" // NB print, not println
examscore = ...nextInt...
print "what is the assessment?
assessment = ...nextInt...
print "what are the fees> ?
fees = ...nextInt...
etc
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You just copy/pasted your assignment without even a moment taken to explain what help you need. That's highly disrepestectful to the many people who give their time to help others here.

There are lots of people here who will freely give their time to help you become the best Java programmer you can be. There's nobody here who is interested in helping you cheat or doing your homework for you.

DaniWeb Member Rules (which you agreed to when you signed up) include:
"Do provide evidence of having done some work yourself if posting questions from school or work assignments"
http://www.daniweb.com/community/rules

Post what you have done so far and someone will help you from there.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

IMHO those GUI libraries are way too advanced for this requirement. There's nothing there that requires anything more that just an ordinary Swing GUI.
The Oracle tutorials are unbeatable for accuracy, currency, and completness, but you may want to Google for some simpler tutorials if the Oracke ones are too much
http://docs.oracle.com/javase/tutorial/uiswing/index.html

অসীম commented: I tried to play with swing before by writing codes.Now I tried again from your link and it seems easier than before. I think I can start now, I'll mark this thread solved and thanks to both of you +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Hello Wilfred, welcome to DaniWeb.

We don't do people's homework for them.
If you have a specific problem with some aspect of Java then we're glad to help, but simply copy/pasting your assignment and waiting for an answer is just insulting.

DaniWeb Member Rules (which you agreed to when you signed up) include:
"Do provide evidence of having done some work yourself if posting questions from school or work assignments"
http://www.daniweb.com/community/rules

Post what you have done so far and someone will help you from there.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You have a break; as the last statement in your loop, so it will always exit the loop at the end of its first pass. Maybe you intended that to be inside the else block?
Also: the if test on line 28 is redundant.

stultuske commented: I missed that one ... +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That's the solution I proposed earlier, except that he misses a key point - which is that ArrayLists can also be encoded/decoded (the ArryaList class has been retrofitted with extra methods to support XML encoding). He messes about writing the arraylist elements one at a time, then reading them back in and addig them to a new list. All you need is to encode the ArrayList itself (one call) and decode it (one call)

CoilFyzx commented: :D Thank you. +2
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Could it be that the action command is "Save" (defaults to the same as the button text), but you are testing for equals("save") ?

stultuske commented: equalsIgnoreCase to the rescue :) +13
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Use java.beans.XMLEncoder and pass it the ArrayList. It will encode the entire ArrayList and it's constituent classes and their ArrayLists of other classes and primitives all the way down.
Your custom classes just need to comply with JavaBeans standards (get/set/add methods, a no-args constructor).
It encodes to a Stream so you can do multiple encodes and subsequent decodes on the same stream/file.

I have a little demo using an ArrayList of instances of a class that contains another ArrayList among its instance variables, should you need convincing...

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

aren't editors column specific instead of cell specific?

It comes down to JTable's getCellEditor(int row, int column). Subclass JTable, override that method, and you have cell-specific editors

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

If you want to count the letters in a word there's no need for the alphabet array and the nested loops. Java chars are an integer type, and the letters a-z are consecutive in UniCode, so all you need is

for (char c : word.toCharArray())  count[c - 'a']++;
iamthwee commented: nice point +14
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The range of keys that will be included in the subMap view are from "b" to "g". That includes all possible keys that sort after "b" but before "g". You can add any keys within that range, but not ouside it. "b" being the second letter in the alphabet has no significance whatsoever.

ps: Technically speaking the range is from "b" inclusive to "g" exclusive

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

TreeMaps are always sorted by their keys.
subMap returns a view of a contiguous range of keys of the TreeMap, including only those keys within the specified range.
Because it's a view, updates to it just update the origional (backing) TreeMap.
Similarly updates to the origional TreeMap arre immediate visible in the view (provided they are inside the range specified when the subMap as created).
Because the view is only a specified range of keys, any attempt to add a key to it must be within that range. Anything outside that is an error.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes, I agree with all that. He certainly should not be removing/adding listeners dynamically to fix this.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Thanks for the link - hopefully OP will identify the exact source of the NPE to determine whether this is a Swing problem or something related to the underlying code.
I have had similar problems in the past - ie replace the contents of a list box -> fires the list box listener multiple times, first time with no contents. Seemed to me at the time that testing for, and ignoring, the irrelevant calls was the easiest solution.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Your analysis of the problem seems reasonable. Why not just check the selection in JList ListSelectionListener and ignore the event if the selection is null?