JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes, just convert the int to a String.
Shortest way is string concatenation because that converts automatically, eg ""+count
... but some people dislike that because it's a bit obscure, in which case the "official" ways are
Integer.toString(count) or String.valueOf(count)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Excellent!
A while ago I did a test/demo program using the simple architecture above. It has hundreds of balls bouncing around and bouncing off each other, with full spherical bounce calculations and gravity, plus animated gifs moving across the screen at the same time and assorted bricks and balloons crashing/floating around. Runs smoothly at 30 fps on a five year old ordinary PC.
Back in the days of Java 1.4 that was the first version where animated games became possible, but only if you spent a lot of time doing your own buffering etc.. Unfortunately there are still many tutorials on the web that date back to those days. Java 1.5 gave us double buffering and a whole load of internal optimisations, and life has been a lot simpler ever since.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

It looks like you are fighting the Java graphics system rather than working with it.
Before getting into buffer strategies, just try the recommended (flicker free) mechanism...
Override paintComponent for a JPanel and do all your drawing there or called from there
Update the game state in a non-Swing thread
Call repaint() at the required intervals
Let Swing's double buffering handle the flicker

The link I gave you earlier has some other hints to optimise performance.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Swing components are double buffered by default, unlike the old AWT components that make you do it. If you place a canvas with some more complex buffering strategy inside a double buffered Swing parent it's far from clear what your custom buffering will achieve anyway.

If you are updating the painting of a JPanel you do not need to call revalidate, a simple call to repaint will do, so that's no different from canvas.
Have a look at Oracle's write up on AWT vs Swing. http://www.oracle.com/technetwork/java/painting-140037.html

So unless you are doing something very special in a difficult hardware environment it's safe to say that using obsolete AWT components instead of their superior Swing replacements is always a mistake, and mixing them is a bigger mistake.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Useful in what ways?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Why? Canvas is an old AWT component that you would use in an old AWT Frame. Forget it, and use a JPanel.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That's a good question. All the definitions of mediant that I found in a quick google had no use or meaning for such a parameter.
Are you sure that method signature is right? Is there any supporting documentation?

Vinolia commented: the method signature is really correct +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I'm not c++ buff, but it looks to me like you have set the precision for printing numbers, but that has no effect on the numbers themselves.

fx could still be 0.000001, you are just printing it to 4 decimal places

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Looking at the print method, where the error is generated, I see 2*i+1 etc in a loop where I goes up to the list size, so the out of bounds is inevitable

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

"There is only one skill needed: code"

... if you just want to be a coder, blindly programming whatever someone else tells you to code, doing the most hours of work for the smallest salary...
But if you want more than that from your job, you absolutely need the other skills mentioned in previous posts

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

1: You get an exception (null pointer, zero divide etc)
or
the program behaves in a way didnlt expect (wrong output etc)

2: Trace the execution one step at a time, using a debugger or lots of print statements until you find where its going wrong

3: Design top-down - classes / method signatures etc before getting into details, so any logic errors will be localised
and
keep methods small, doing just one thing
and
be very careful with naming methods/variables etc so the name exactly describes the usage, and so any mis-use is obvious

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

If you get that information from the user then you have to store that in a configuration file (or equivalent) somewhere so you can find it next time the program is run.
So your startup code can look something like:

p s v main(etc) {
   get config file
   if file exists start running normally
   else run the one-time installation code
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Most bad web sites are not bad because of some technical failure, they are bad because they don't do what the user wants or expects.
Learning PHP or whatever is not hard - just takes a bit of time and effort.
IMHO the key skill is being able to see your web site from the viewpoint of a non-technical real user. You can practice that by letting your non-techy family members or friends try to use your site... do NOT give them any help or advice, just sit back and watch them get confused or frustrated. Then afterwards, ask them what they found confusing or hard.

broj1 commented: I like this one ;.) +11
gentlemedia commented: Yes, usability testing can be done relatively cheap. Okay... it takes time, but if the reward is happy users. +5
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You have written the array of data to a text file, so loading it is a question of
Reading each line from the text file (see any tutorial for reading lines from a text file)
Splitting that line into fields using the tabs as separators (see String's split method)
Storing the fields into your data array

Doing something every 5 seconds (if that is really waht you want) can be done with a java.util.Timer (see the API doc) which will call your save method every 5,000 miliiSecs

shayan_doust commented: Brilliant, thanks! I will try it tomorrow (It's 10 PM local) and I will keep you updated. +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK

You can use a Scanner to read the data from the user, then store it into an array or arrays.
You can use loops to go through all the data in the array(s) to perform the calculations, the print the results to System.out

samuelmathews commented: thankyou sooo much, +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

No, sorry, can't see any problems their either. This is baffling!

ps: I see you are defining local constrants to save typing KeyEvent. All the time
Do you know about import static?

import static java.awt.event.KeyEvent.*;

Then you can just use the public static members from that class without needing to qualify them. eg case VK_UP;

It's not just the save of time/space. You shoiuld assume that somene treading yur code knows the relevant Java, so VK_SPACE will be recognised but CLEAR could be anything.

Doogledude123 commented: Nice tip with the static, I do know it so I'm not sure why I didn't bother using it. +3
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Although algorithms in general are used outside programming (eg in maths), in this context an algorithm is a way of solving a programming problem. If you don't have some knowledge of programming then the algorithms will make little or no sense to you.

I'm 100% voting for learning at least some programming first.

Ghost0s commented: THanks +1
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That fragment of code opens a socket connection, sends some text, and disconnects. What did you expect?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That is ok for a simple case. If you have multiple windows that may be called in various sequences, and complex data to be shared, then the standard approach is to create a new class that holds all the data and make that class available to all windows.

ddanbe commented: True indeed. +15
Santanu.Das commented: Right solution +6
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

mayank
read the previous two posts

mayank7296 commented: thanks +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

VisualVM will let you see what objects the VM has stored in its (heap) memory.
https://visualvm.java.net/gettingstarted.html

But it doesn't give you any access to actual memory locations. It just lists objects according to their class or size or whatever.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes, that code creates a new String object with the value "hello" and it also creates a new variable called hello that contains a reference to the String. The String will be created in the JVM's heap(s) somewhere. The variable may be in the heap (if it is a static or instance variable) or on the stack if it is local.

The language definition refers to references, not to addresses. Yes, the simplest sort of reference is just the address of the object being referred to. But that's not necessarily so and there are good reasons why you might do it differently (eg use an offset into a table of object addresses, which then allows you easily to move objects to optimise memory usage). The design of the Java language is very careful never to say anything about actual memory addresses.

Bottom line: in some implementations you may be able to interpret the default hash as an object address, but this is not required or guaranteed. In general there is no way to get an object's actual memory address.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Here's Oracles brief operating instructions for jconsole
https://docs.oracle.com/javase/tutorial/jmx/overview/javavm.html

... but what do you really want/need to know? I can't imagine that a memory address is going to be useful to you.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The result could be as long as the longer input aray, or 1 digit longer than that (if you end up witha carry), so maybe the easiest way is to set up 3 arrays of length (longest input +1), read the inputs into two of them and calc the result into the third. With all the arrays the same length you will have no problems with indexes or loops.

ps: a boolean expression evaluates to true or false, so some of your code is highly redundant, eg consider
if(isValid(temp) == true)
isValid(temp) returns true or false, so the == true does exactly nothing. All you need is
if (isValid(temp))

Similarly, consider

        if(val == 0 || val == 1)
            return true;
        else
            return false;

now val == 0 || val == 1 evaluates to true or false, so all you need is

return  val == 0 || val == 1;
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

We don't know where you're wrong either. What have you done so far?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

So, you have published you teacher's original (copyrighted?) assignment here.
And what did you expect to achieve by that?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
  1. Decide which platform you are going to major in. It's not hard to learn a new language; algorithms and techniques are mostly portable; but to be good at games you need to understand the actual API/graphics tools in all their horrible detail with all their horrible quirks and work-arounds.
  2. Write lots of code. Then write some more. Get someone who knows to critque it, then re-write it. Do not ever leave out bits that look hard or tedious (eg error handling and recovery) - these are the bits where expertise matters.
  3. After that you could try to join an open-source project to get experience of a real team developing a real program.

I agree with rubberman - expect this to take several years.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The "unknown source" is just referring to the internals of the Java API classes (for which the source code is not on your computer).
The first lines of the message tell you what you need to know...

ArrayIndexOutOfBoundsException: 0 at myGUI.Summary.actionPerformed(Summary.java:67)

that looks like line 111 in the code as you posted it (?), if so it looks like all or part of the data[][] array is uninitialised - ie does not have a member [0]

looking at lines 72-74 it seems you have initialised data to size [0][3], so there's your problem

ddanbe commented: Instructive & helpful +15
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

static = one value, shared for all instances of the class
non-static = every instance has its own values

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

hazelkahn
So we don't delete all your posts as junk, can you please explain what you are trying to do. Do you want solutions to these exercises? Are you proposing them as good exercises for learners to try? Something else?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Same problem as in your previous post: "sum" is not a Java type, nor a class.
Line 8 also has invalid syntax for calling a method

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

lines 3,4 you have two {

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

It's obviously designed with the assumption that it will only encode/decode A-Z, so it's not surprising that it fails with a blank in the input.
Having said that...
args[0] is maybe just the first word of your input, the other words being in args[1] etc, depending on how you typed the command.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I already asked him that yesterday. He's not responding.
It's starting to look like he has spotted his error and has moved on without the basic courtesy of letting us know. He doesn't bother to mark his threads "solved" either. Unfortuately that kind of rudeness is all too common.
He has 30 "contributions" to DaniWeb, every one of which is about his problems. As far as I can see in 3 1/2 years he has never made a single contribution to anyone else's problems. Draw your own conclusions.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Method 1: (Object...params)
That's as unhelpful and error-prone method signature as I can imagine. You have no idea what the arguments should be, and the compiler can do nothing to help you.
Method 2: (Class<T> entityClass,String name, String idName,String value,String id)
Now at least I know what the arguments are supposed to be, and the compiler can check that the first is a class<T>, the second a String etc

For me it's 100% the second version. No contest.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

apply() just sets a listener. How can it possibly return a value for radius?
You don't have a value for radius until after the onClick is executed, and the onClick can't be called until after apply() has executed..

Without the whole context it's hard to give a relevant example, and the wrong example will just cause more confusion.

Here's what real programmers do when faced with a challengle like this: they sit down and pretend to be the JVM stepping through the application code, keeping track of the variables etc. Once you have worked out what you would need if you were the virtual machine then you will know what Java needs.
(It's called the "mental model" - all competent programmers have a mental model of what the computer is doing with their code. Without a mental model all you can do is try stuff at random and hope for the best.)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

All that apply() does is to set a listener. For the radius method you need an actual numeric value, which apply() does not supply.
I'm curious about this mistake. What did you hope would happen if your code was able to execute the way you intended?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

In my opinion the Eclipse debugger has a very steep learning curve, and is far too difficult for someone who hasn't started learning about threads yet. For a beginner I think it's far better to stick to what they already know, and put in lots of System.out.println calls.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

fis.close(); etc, of course

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You really are not trying.
Google JList tutorial. Go to the official Oracle tutorial. Go to the section called "Adding Items to and Removing Items from a List"

peter_budo commented: My thought... +16
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

"Java" includes the API, and the standard API includes a class Void
It's no different from "class" vs "Class"

https://docs.oracle.com/javase/8/docs/api/java/lang/Void.html

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Read the DaniWeb rules

If you want help you must show effort
Post in full-sentence English

Now... start again

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

On which line did it throw the exception?
What was the file/path that you were processing at the time?

Munazza_1 commented: It throws exception on second one. The first one works for one text file, i want to iterate it over the same folder for all file. Same path +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Use your debugger (or lots of print statements) to trace the execution of both the server and the client so you can see what is happening.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That looks like a search. Using the algorithm I posted earlier you can call that recursively based on the previous position until you reach the target square. For simplicity you could try assuming that a move in the right direction is always best, and a move in the opposite direction is always worst, so you only need to search the up/down choice when moveRight is unavailable. (You can construct bizarre maps where that won't work well, but it should be pretty good for ordinary maps)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK, that makes it clear.
So, something like

if (wants to move right)
   if (can move right) move right       // ideal answer
   else if (can move up) move up        // equal second best
      else if (can move down) move down // equal second best
   else if (can move left) move left    // bad, but no other choice
   else cannot move in any direction!

(times 4 for up/down/left as well).
It's pretty clunky, and there must be ways to optimise that code, but getting it working is more important.
Ideally you could use some kind of look-ahead to see whether up or down would be better when right is unavailable.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

C and C++ are two languages. Java is another, completely different, language. You can't use a Java compiler for C or C++.

JDK 1.5 is many years old, no longer supported, and has unfixed security errors. If you want to code in Java you should download the latest version of JDK 1.8 from Oracle's web site.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

It would be helpful to know exactly what the error message says.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes, there's no ODBC in current Java. Fortunately there's an open source JDBC Access driver http://ucanaccess.sourceforge.net/site.html that seems to have a good reputation.

Ps: That call to Class.forName (line 21) (and the problems it can spawn) has been obsolete for many years now. Don't use it.
It just shows how out of date so many tutorials are! The only ones you can rely on are Oracle's own: https://docs.oracle.com/javase/tutorial/jdbc/basics/connecting.html