JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I don't understand
Are you disagreeing with my choice of java.util.timer, or my use of repaint?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The Timer method for running an update every 30 mSec (33 fps) looks like

scheduleAtFixedRate(this::updateSimulation, 0, 30, MILLISECONDS) // NB Java 8

where updateSimulation is a method that updates the model, like

   public void updateSimulation() {
        // reliably called by Timer every 30 milliseconds
        xPos += xSpeed; // update position of object
        yPos += ySpeed;
        repaint(); // notify that screen refresh is now needed
        // (that's for Swing, need the GDX equivalent)
    }

your render then just renders things at their latest position - it NEVER updates anything.

ps: This is different from the normal GDX way of doing things because it gives more control, especially when the hardware is struggling to maintain the frame rate.
If you find this confusing then you will probably be better off ignoring it and staying with the ordinary GDX Animation class.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Normal practice for Java animation is to use a java.util.Timer scheduleAtFixedRate to update the state of the model, then invalidate the GUI state to force a re-draw. That way the animation proceeds at a constant speed and the screen gets updated as often as possible.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Maybe you could render all your graphics at some fixed resolution (eg HDTV) and use a scale(double sx, double sy) to scale all the contants to whatever the actual screen resolution is?

As for speed... what Timer are you using?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Some of the cases do have breaks, but that's not the real problem.

(sorry Ant695 but you're going to kick yourself when you read this...)
You should be switching on the chosen planet, not the person's weight!
J

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Because bytes are integer values. Doubles are 8 byte floating point values. When you assign a float value to a byte it's rounded down to the nearest integer value.
You also have a problem if the value is >127, becuase that's the largest value a byte can hold.

Either way, the answer is to use more than 1 byte to send the value.
You can use an nio ByteBuffer to convert doubles etc to byte arrays abd back again.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

This sounds like the "premature optimisation" anti-pattern!

I would concentrate on getting it working properly with a simple implementation (eg re-draw everything each tick). If you try to optimise too early then
1) You may well be wasting time fixing a non-problem
2) Your optimisation may well clash with things you have to do later to complete the functionality

I'm not saying ignore efficiency totally. You should try to start with simple clean sensible data structures and algorithms, but do not complicate things until/unless you know you have a performance issue and you have understood all the constarints of the full functionality.
If you have a strong suspicion that a particular area will be a perfomance bottleneck then define it as an interface and provide a basic implementation. That way if later it is confirmed to be a problem you can swap in different implementations.

Finally, remember you have a machine that processes thousands of instructions in a microsecond, and most of those instructions are OS and JRE, not your code.

Doogledude123 commented: Awesome recommendation, always the best answers from you. +3
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

What are the Tile objects - are they RGB Images, or something that needs more elaborate "rendering"?

Passing the position is not an issue. The only thing to worry about is if rendering a Tile is expensive AND you are doing that rendering more times than is necesary.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The only thing that matters is that you load the tile once to create a Tile object that persists for the whole game. Provided you do that, static or final won't make any difference. Regardless of how you track those objects (in an array or a List etc) they still give you the address of the Tile object so the renderer can access it. Remember that arrays etc do not actually contain Objects, they just contain references (pointers) to the objects.

There's much out-of-date info on the web regarding efficient graphics in Java. In particular you used to have to handle your own double-buffering, but now that's done automatically by default.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

They are two different Objects that happen to have the same values in them. They occupy different places in the JVM's heap, and have different hashes. The == operator will return false. You can change one of them, and the other will not be changed.
All Java objects have an equals method that is normally used to test for two objects having the same values (state). When you create a new class you have to define what "equals" means for your class, otherwize you just inherit the default equals method which is just the same as == (ie tests for being exactly the same object in memory)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Rubbish. Text pad will not convert a .class file to Java source. Never has.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Nice!
I think this one is done now?
cheers
J

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

All I meant was
If there are many letters, then there are many many possible sequences, and a random sequence has a good chance of being a solution. So trying random sequences is a sensible strategy.
If there are fewer letters, there are fewer possible sequences, and there is less chance of a random sequence being a solution, in which case a deterministic complete solution is more favourable.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The statistical approach (see pdf above) is based on the monumentally unlikely assumption that all the 2^16 chars are equally likely, so given any sensible file size there are very many short sequences not present.
A much more interesting (and realistic) version would just use the ASCII character set, so all the characters are likely to be present, and most short strings will be present in even a fairly small file.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Two points:
1. It still involves guessing random strings until one is found,so not deterministic and in bad cases may run idefinitely long
2. The REGEX hides the fact that mutiple matches are being tried at every character - don't expect fast!

Here's a suggestion that is deterministic and must be damned close to optimum, provided you have enough memory to hold three times the size of the string:
Note: If the string length N is < 2^16 there is a single char solution
1. try the single letter solution first. If that fails:
Note: if N < 2^32/2 there is a 2-character solution
2. make an array of all the 2 consecutive letter sequences (N-1 elements of 4 bytes each)
3. sort the array
4. search the array sequentially until you find a gap in the sequence. Any value in that gap is a solution.
Note: if N > 2^32/2 and cunningly constructed to include every possible 2-char sequence you will have to go to 3 chars (and you will also win the lottery 3 times in succession)
5. make an array of 3 char sequences as above (construct array of N-2 elements of 6 bytes each), sort, and search for gaps
6. etc

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes, there are UniCode symbols that need more than 2 bytes, but frankly they are a mystery to me.
For substrings >= 2 chars I can't think of anything that wouldn't require many searches of the entire String, which is horrible. (So maybe it's always worth trying the single letter case first because that's so very quick and would surely work in 100% of all real-life situations.)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I don't know Python, but can't you just create an array of 2^16 booleans, corresponding to the 2^16 basic UniCode characters, do one pass of the string and set the corresponding boolean as you encounter each character.

Gribouillis commented: good suggestion +14
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

How short is "short"? If the string/file is less than 2^16 characters long then there will be at least one UniCode character that's not in the string, and which will therefore meet your requirement. ;)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK. I was talking about the user updating the database, so it's propbably not relevant here.
If the database is updated every second then maybe you have to use a timer to update the display every second, unless you can hook into the update code somehow to pass the new info directly to the display code

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The OP said "display", which may imply that its not an updatable view - in which case its a lot lot simpler to do!
To handle updates, rather than a timer, you can listen for update events in the JTable and save the changes as they happen. Alternatively, you may prefer the kind of user interface where the user edits the table, then presses OK to commit the update, in which case you just listen for the OK button.

amogh.max commented: These data are coming from a sensor,so the database is updated every second;how would i implement listen for update in that case. +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You can do this by using JDBC to read the data and a JTable to display it. It's a fairly common thing to do, so you'll find many examples and tutorials on the web - just Google JDBC and JTable together

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You are using + to concatenate stuff for printing, OK, but you have left some out. You need a + between every expression..
"there are " + weeks + " in " + (etc)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes, that code looks like a good answer to the question. (Except: Spelling mistake on line 1, and I have not tested it on a computer).

ps: Most people here advise that you do NOT use Eclipse if you are a complete beginner. Its a very complicated tool for experts, and will not help you when you are trying the learn the fundamentals of Java

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You must try to answer this question. Show us your answer and we will help you to get it right.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

How many times have we said this in the Java forum...
Never NEVER NEVER do this when writing new code:

} catch (Exception e) {
}

If/when there is an error you just told Java that you didn't want to know anything about it, and please discard the detailed error message that Java just created for you.
ALWAYS put an e.printStackTrace(); in your catch blocks until/unless you have a good reason to do something else.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I don't know, but you could try printing the contents of firstLine to see what's happening. Maybe it's something that's not displayed, like "<html>" ???

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

The check is obviously done in your isInteger method, so you need to change that.

Edit:
djjeavons makes a good point. My advice above is bad. Don't change isInteger - maybe create a new isAlphanumeric method to parallel isInteger but with the tests you need.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Sorry, I don't have any other info - that's one reason why we ended up developing our own algorithm.

Briefly:
We send the screen image as a series of 32 bit words that encode the content as a string of pixels top-left to bottom-right.
If (as is usually true) there are pixels unchanged from the last image we just send the number of consecutive unchanged pixels.
When there are changed pixels we send the new RGB values for those pixels. Because there are often runs of identical pixels we further compress the changed pixels by sending the count of the consecutive identical pixels (run-length encoding, or RLE).

Ie there are two kinds of 32 bit word sent:
pixels unchanged from previous image:
first byte = 0, bytes 1-3 = number of unchanged pixels
or
changed pixels:
first byte = number of consecutive identical pixels
bytes 1-3 = RGB values for those pixels

Unless you want lossy compression (not good for small text om screens!), this algorithm gives you a lossless compression for typical screens that is near optimum while being easy to code and very fast to run. Eg: if the screen hasn't changed since the previous send it's just a single word (0 + number of pixels on screen). If there is just a letter or two that has changed then only the changed letters are encoded, and the RLE encoding does that very efficiently.

I found it gave a …

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Sending mouse and keyboard events depends on the language you use, but the real problem is how to send and update the real-time screen image across a limited bandwith. It all comes down to how you compress the screen images.
We had a long thread on this in the Java forum a while back. If you skip straight to the end you'll find the algorithm that worked best for us. (The code is Java, but you will be able to translate the compression code to VB very easily.) https://www.daniweb.com/software-development/java/threads/254810/find-the-differences-between-two-images-and-the-locations-of-the-differences/

OMER AHMED commented: helpfull but need more clearification +1
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

This web page has an excellent discussion of how to do it (and how not to do it)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
boolean isAnExample;
...
do {  // Loop until user enters a valid password
   isAnExample = true; // re-sets boolean at start of each pass of the loop
   ...
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You obviously need to re-initialise your booleans each time the user enters a new password (ie around lines 19 to 31)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK. That explains it.

For some bizarre reason you have to ask the compiler to check your code properly by adding the -Xlint option. IMHO that should have been the default, with an option to turn it off if you need to (like -nowarn).
Anyway, I cannot understand why anyone would NOT automatically always use -Xlint when developing a program - it's on a par with catch(...) {} in terms of ignoring the diagnostics that Java works so hard to provide.

The moral (for anyone else reading this) - always compile with -Xlint unless you have a good reason not to!

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Mine was Java 8 on Yosemite
did you use -Xlint?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Hi
Compiling from the command prompt gives you a "warning: [static] static method should be qualified by type name, A, instead of by an expression" (provided you are using -Xlint, which, frankly, you would be mad not to).

// demo code
class A {
  static void x() {}
  {new A().x();}
}
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

yes, really.
NetBeans and Eclipse both give a compile-time warning for accessing a static method via an instance ref. It is, as you say, valid but confusing.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The definitive Oracle tutorials are kept up to date, and include MySQL...
http://docs.oracle.com/javase/tutorial/jdbc/index.html
AFAIK there were no significant SQL-related changes in JDK 8.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Just think of the number in in its binary representation.
What question will tell you the value of the first bit?
Knowing that, what question will tell you the value of the next bit?
How many questions will you need to know the values of all the bits?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

It means the method is a class method as opposed to an instance method. You do not need an instance of the class to use that method, and the method has no access to any instance variables or instance methods )unless someone else supplies the instance).

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

An array of chars is one thing, a String is a differemt thing.
Arrays of chars are not very often used - all you can do is iterate through the array to process the chars one at a time
Strings are used all the time - they have dozens of valuable methods, and wil also allow you to get the individual chars that make up the String.

new String(anArrayOfChars) takes a not-very-useful array of chars and creates a new String that you can use with all the methods of the String class (and many other methods that that use Strings as parameters)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Line 60: shouldn't you be adding the costs, not the sizes?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

It's not something that I've ever done, so I can't really help. Sorry. J

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Did someone speak my Name?
Yes, except a JTable in the middle, not a hand made grid.
I don't know if you can do that with the print methods in JTable. I suspect you will have to use the normal printer support and draw your header &footer as part of the page. There is header and footer support that does text with page numbers etc, but I don't know if that includes in ages. (Maybe it does via HTML?)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
while (!signalFromThreadB) {
    pthread_yield();
}

Isn't that a flat-out polling loop that's going to burn 100% of the spare CPU time? Safe, maybe, but not good practice?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

When someone runs your program from the command prompt (or batch file etc) they can add parameters to their command. You get a copy of those parameters in the String array.

java.lang.* is imported by default in all Java programs

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK - that makes it a lot clearer. You should have said that right at the start to save time.

My guess is that when the cell is rendered it adds the row, which causes the table to be re-drawn - which renders the cell again - ... loop

The cell renderer isn't a good place to do this. It's just part of the painting, and could get called any time. I would try adding a listener to the combo box(es) and using that to add the row etc when the user selection changes in the combo box.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

We can't help you if you don't help us by answering our questions.

"is not working" tells us nothing. Do you mean nothing happens at all? Or something happens but its wrong (in which case exactly what does it do that's wrong) = give DETAILS.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Before reading all that code...
How much of the requirement is working already? How much is implemented, but not working properly (detail incorrect behaviour vs correct). How much isn't implemented at all?