JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

ii) They are absolutely essential
iii) not recently in a "project group"
iv) ?
v) yes, but in the early 1990's when they were a new idea, so more conceptual than specific.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

MVC, Listener/Observer - all the time. They're essential for Jave UI work.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That's just the first part of a program, full of redundant (experimental?) code, and with some obvious mistakes (overriding paint, loading a new ImageIcon every time the user presses a key, repeatedly starting the same Timer...
but most important, it doesn't show any code for adding or moving the enemy, nor do you explain what you mean by "why the screen gets mess up when I display the moster".
So please help us to help ypou by cleaning up the code, fixing the indentation and layout, posting the whole thing, and explaining exactly what goes wrong.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Java is case-sensitive. "While" is not the same as "while".

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

In practice it's limited by the available memory, but if each instance does not have big data members you can create tens of millions of instances

rubberman commented: The technical term in "gazillions"... :-) +12
<M/> commented: :) +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

16: String A1 = rowSet.getString("County_ID");

Maybe this should be String A1 = rowSet.getString("Town"); ?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You declared getRotatedModel as returning a object of class Model, but the method does not return anything

<M/> commented: :) +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

((javax.persistence.Query)null).getResultList();

starting inside the brackets you have a null reference. null
You then cast that to a javax.persistence.Query type, (javax.persistence.Query) null
but it's still null.
Then you use that to try to call getResultList(). Hey presto NPE.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Here's a good one involving recursion...
write a method to evaluate arbitrary arithmetic expressions according to the normal rules of arithmetic. Eg given "(2+4)*4" as input it should return 24 as the result.
It's about 100 lines of code. No special Java stuff needed, but the recursion will stretch your brain.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Now that you have seen that example, give it back to whoever you got it from and write your own version, following the instructions you were given.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

For someone who "had no idea how to do this" less than an hour ago, that's a pretty good effort!
When you compile and run that code does it give any error messages? Does it display the correct answers?

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.

Begginnerdev commented: Awesome answer! +8
<M/> commented: accurate.... +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The instructions are very clear and detailed. Just start with the first one "Create a class called Date", then carry on, doing one step at a time. When you get stuck, come back here, post what you have done so far, and explain exactly what's confusing you about the next step.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

im just a beginner here. self studying ofcourse. i just want the opinion of others. ofcourse it is running. but i want to know if i applied polymorphism,overriding or overloading. thats all.

OK, no problem. Your add and mult methods, which have the same names but different parameter lists are a good example of overloading. For the rest you will need a more complex setup that has more than one one class in some kind of class hierarchy.

I assume you are following some kind of on-line course or set of tutorials? If so they should introduce all those examples in some kind of sensible order. In any case, please feel free to come here for help and advice.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Try writing down the logic in simple english before trying to do it in Java. Imagine you are explaining to someone else how the allocation should be done if it was a manual/paper system.
This will help you get the logic clear in your own head, after which the Java will be easy.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

If you have a variable list of things to display then use a JList or JTable, both of which have a varibale number of rows. There's no need to create controls on the fly

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

"doesn't run" implies a run-time error or exception (array index out of bounds, maybe?). Next time please post the complete text of any error messages.
This one looks like the classis Scanner "gotcha" - nextInt followed by NextLine
nextLine leaves the scanner pointing just after the int, ie just before the following newline character, then nextLine takes eveything up to the newline, which is a zero-length String.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

depends on how you are doing it - do you override paintComponent or is it a JLabel with an ImageIcon?
If it's paintComponent then just draw the image at (panel width - image with)/2, (panel height - image height)/2. Your paintComponent will be called after any resize and will always center the image.
If it's a JLabel then it also depends on the layout manager...

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

more thoughts...

if the target starts at boot time then it will be running in its own VM with its own heap/stack. Any other Java program you start later will also have its own VM/heap/stack - you don't get to start your program in someone else's already-running VM unless the target program has some coding to support that.

do you have access to the target's source? If so maybe you could modify it to allow value changes from outside, and place your version of the class file ahead of the original in the classpath?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

This is the Java forum, but that's not Java code.
Please check what language you are using, and re-post in the appropriate forum.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I'm also just back from a trip, so good timing!

Unique object IDs for database use is a standard problem with many standard solutions - just Google.

Probably the easiest way to explain the proxy idea is with some (pseudo) code - but remember this hasn't been in any way optimised for your (unpublished) complete requirement...

    abstract class Chunk { 
       int ID;
       ...
       abstract public void doStuff();
       ...
    }

    class RealChunk extends Chunk {
       // this is a real chunk that is fully populated with data
       ArrayList<Chunk> chunksThisLinksTo = ... // could be real or just proxies
       ...
       public RealChunk(int ID) {
          // load chunk data from database
          // populate chunksThisLinksTo with new ChunkProxies
       )
       public void doStuff() { ...
       ...
    }

    class ChunkProxy extends Chunk {
       private RealChunk realChunk = null; // the chunk this is a proxy for

       public ChunkProxy(int ID) {
          this.ID = ID:
       }

       public void doStuff() { 
          if (realChunk == null) loadRealChunk();
          realChunk.doStuff();   // proxy the calls
       }
       ...

       void loadRealChunk() {
          // may need to free memory by unloading a real chunk...
          // ... just set its proxy realChuck variable to null and let GC do the rest
          // (implies you maintain a list of proxies whose realChunks are in memory)
          realChunk =  new RealChunk(ID);
          (list of proxies whose realChunks are in memory).add(this);
      }
   }

So now when you are loading Chunks from the database you create create ChunkProxies for all the chunksThisLinksTo values. They just sit there until the program …

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

For displaying you can also use the printf method instead of print or println. That allows you to format data while you are printing it.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

First, let's assume you know some basic graphics stuff - how to create and display a window (if not you need to study a tutorial on that first).

Then look through this tutorial on custom painting in Swing for the basic info you will need.
Using that you can draw your thermometer as a rectangle whose length is defined by the temperature. You can decorate that with colors, text and numbers etc as you wish.

However, you may be able to get something close enough by using a simple JProgressBar

somjit{} commented: +1 for the JProgressBar idea. +3
<M/> commented: :) +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That's OK, thanks for understanding. Some people will take the time to study the before/after versions, see what's changed, and work out why... but many others wll just copy/paste. see it works, breath a sigh of relief and move on, with no gain of understanding. You never know at first which type the OP is :)

ps Your second para would have been a perfect initial answer to the question like this...

"Dennis_1 , you have defined your methods but you have not called them , so just make a condition as per user input inside a nested If else and call each method accordingly."

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Just a quick answer beause I'm going to bed now.... but situations like this are often solved by having an abstract Chunk superclass, with all the getters/setters defined, and two concrete subclasses InMemoryChunk and OnDiskChunk. The in memory version just works as expected, but the on disk version's methods trigger a read from disk and creation of an in memory version.
The application code refers to Chunks via a ChunkProxy wrapper class that allows on disk Chunks to be replaced by in memory Chunks without the application knowing. This means that all your links/Terminals etc refer to ChunkProxies and never get involved with in memory/on disk issues at all.

ps (next norning) In any given case you may chose to merge two or more of those classes into one for a simpler solution - it depends on data volumes, complexity of interface, cost to read/write disk versions etc.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

http://docs.oracle.com/javase/tutorial/essential/concurrency/syncmeth.html

(basically there is a lock object corresponding to the current instance ("this") for synchronised methods, and when one method has the lock the other threads have to wait for it. Because it has the lock that method can call other synchronised methods for the same intsance, but other threads can't)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

It is not possible for two invocations of synchronized methods on the same object to interleave. When one thread is executing a synchronized method for an object, all other threads that invoke synchronized methods for the same object block (suspend execution) until the first thread is done with the object.

So the first instance starts its bow method, which calls the other instance's bowBack
Simultaneously, the other instance starts its bow method, which calls the first instance's bowBack.
So one thread is in the first instance's bow, and cannot run it's bowBack becuase they are synchronised.
At the same time, the other thread is in the second instance's bow, and cannot run it's bowBack because they are synchronised.
Neither bow can finish until its call to the other's bowBack has finished, but neither thread can start bowBack until its bow has finished. So nothing can happen. Everything sits in an infinite "stuck" wait. That's a deadlock.

Don't worry if this seems confusing, because it is confusing. In my opinion thread-related problems are the hardest thing to understand in the whole of programming. You just have to keep thinking it through until it clicks in your brain.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

my file only has day 0 in the second line. why ?

because the "morning lunch evening night average\n" is on the first line.

Just work slowly through a simple example like this:

str = "abc";
str = str + " def"  // str is now "abc def"
str = str + " ghi"  // str is now "abc def ghi"

...

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You only have one str variable. Each time you re-use it you lose the earlier value(s).

Initially it refers to "\t\tMorning\t\tLunch\t\tEvening\tNight\t\tAverage\n", but then after
str = str + "Day "+ row + " :\t\t";
it no longer refers to that value. It now refers to
"morning lunch evening night average Day 0 " (ignoring the tabs for clarity)
you no longer have any reference to the orginal "Morning Lunch Evening Night Average\n"

then you execute
str = str + traffic[row][col] + "\t\t";
after which str refers to
"morning lunch evening night average Day 0 5"

In other words, each time you execute
str = str + xxx;
you just add xxx onto the end of whatever str was before.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

All I can say is "keep going back to the JLS". It states explicitly that the value of the expression is the value before the new value is stored, so your line 5 contradicts the JLS.

ps: If you want to have a "Java is wrong" debate, how about: adding a "protected" keyword to something makes it less protected!

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

@bibiki: What I care is to learn how this actually works

Quite right. Here's how it is defined to work by the JLS:

Java Language Spec 15.14 (postfix Operators)

... the value 1 is added to the value of the variable and the sum is stored back into the variable ... The value of the postfix increment expression is the value of the variable before the new value is stored.

so yes, there is a "new block in memory", but it's used to hold the value of the expression, ie the evaluation of the postfix ++ is like this:
int valueOfExpression = num;
num = num + 1;

and 15.26 (Assignment operators)

the right-hand operand is evaluated ... the result of the conversion is stored into the variable.

so after the expression is evaluated (see above) the value of the expression is stored in the LHS, ie
`num = valueOfExpression;

stultuske commented: short 'n sweet +14
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The linked examples seem (a) pretty heavyweight amount of code and (b) don't meet the original requirement of formatting on field exit. Here's a simple example of what I was suggesting -(this one just changes the field to upper case when you exit and restores the user's exact input text when you re-enter. Changing the format rather than upper-casing is a trivial extension to this)

class UCField extends JTextField implements FocusListener {
   // displays input as upper case whenever it does not have the focus

   private String original = "";

   {addFocusListener(this);}

   @Override
   public void focusGained(FocusEvent e) {
      setText(original);
   }

   @Override
   public void focusLost(FocusEvent e) {
      original = getText();
      setText(original.toUpperCase());
   }

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

Get the field's text - now you have it in a String. Parse that as a number. Create a new String that's a formatted version of the number. Use that to set the field's text.
String's format method takes a String and a format spec, and returns a formatted version of the String. The format method is documented in the API doc for String,and the format specs are documented in the API doc for Formatter.
Key pressed events are useless to you if the user has a mouse - he can type some input then click the next field. That's why the lostFocus event is the one you need.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

AWT is still officially supported in every version of the JVM, and it will be "forever". Swing is built on top of many pieces of AWT, so if AWT stopped working, Swing would stop as well. All I was saying is that there may be some bugs in the Windows 8 environment that haven't been identified and/or fixed yet if they only affect AWT but not Swing.
It's not hard to move to Swing, and you will benefit from a vastly superior GUI toolset, so don't leave it too long!
Cheers
J

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You can create a new subclass of JButton, and just override its paintComponent method to paint it however you want. (Not nececssarily the best way to do that particular task, but since this is a follow-up to your earlier posts about painting in Swing, that's the most relevant general answer.)

Have a loot ak http://docs.oracle.com/javase/tutorial/uiswing/painting/

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

It's when you want to do something that standard Swing GUI controls don't do, eg animated graphics/games or special text effects.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

create an array to display it.

did you mean that?

stultuske commented: dumb typo's when doing too many things simultaneously :) +14
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I also avoid Scanner - I know it's intended as a simple system for beginners, but I've lost count of the number of posts we've had here where someone has tried nextInt() ... nextLine() and got baffled.

mrosario: You are doing exactly what I would do, ie reading whole lines then splitting/parsing them yourself so you have complete control. For that you don't need a Scanner at all, just a BufferedReader and its readLine() method

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

It works correctly in C++ but not in Java...

Hopeless, absolutely hopeless.

TokamakFusion commented: Not constructive +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

There is no ASCII code for any of those characters, which is why you get 63 ('?'). ASCII is a 7 bit code that just has the unaccented english characters and some punctuation.
http://en.wikipedia.org/wiki/ASCII

That's why Java uses UNICODE.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You just have one paintComponent() method (for your JPanel) and no paint() methods. That's all.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You are forcing a repaint of the whole applet every time, which may be the cause of your flickering.
In any case it's much better to put your animation in a JPanel, and override paintComponent for the JPanel to do your drawing. Add that JPanel to your applet and don't mess with the applet painting at all (at line 62 just call repaint() on yur JPanel).

ps Sorry, the .java was there and I was being stupid.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

But, including it at the front or end looks cleaner. ;-)

The irony of this whole thing is that I was convinced it was the ? that was the problem, and totally forgot the - is also a special character.

Because I'm obsessed with readablilty/understandability I actually settled on
replaceAll("[ _\\-\\?]", "*");
so that I (or anyone else) will never fail to notice the special character(s) in future.
J

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I know this is going to be really simple, and I'm going to look like a fool when someone answers it, but...
I'm tryingto replace any occurrenxe of any of these characters - ?_ with a * in a String
I start with replaceAll("[ _-]", "*"); and all is well except for a ?
But then i tried
replaceAll("[ _-?]", "*");
replaceAll("[ _-\?]", "*");
replaceAll("[ _-\\?]", "*");
and just get invalid regex's

Can some regex expert please put meout of my misery?
Thanks
J

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

A JPanel object is initialized to use a FlowLayout, unless you specify differently when creating the JPanel. So in the second case you are adding to a FlowLayout (using a BorderLayout parameter for an unspecified result)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

140: for(int i =1; i<rowCount;i++)

How many rows of data do you have? This will ignore the first row (row zero).

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

import static imports any static final variables from a class (eg Colors from the Color class).
Youu probably should be using just
import com.healthmarketscience.jackcess.Database.*;
to import the classes.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

All your methods (except main) are (correctly) instance methods. You need to create an instance of CashDispenser to use those methods. You create an instance with (eg)
CashDispenser cashDispenser = new CashDispenser();
That creates an instance, and sets your cashDispenser variable to refer to it. Now you can call your methods.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Deve - what exactly is your problem here? You have some code to do a calc and display it when a button is pressed - what exactly happens when you try to run it?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Sorry, no real time now, but briefly...
C is a low-level language that keeps you close to the hardware and is perfect for writing operating systems or real-time games etc. Not much used for applications now (too hard). It is not object-oriented.
C++ is a kind of object-oriented upgrade of C that (in my opinion) combines the worst features of both, and is a dead end (others may disagree).
C# and Java are very similar proper object-oriented languages.
c# is mainly used on Windows where it works with Microsoft's .net libraries.
Jave is used for cross-platform applications (runs on Windows/Linux etc) and uses it's own cross-platform libraries.
Either C# or Java wopuld be a good way to go if you want to be an application developer.