JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

It looks like your problem is lines 26/27 where you try to get the text from the text fields.
The variables jtf3 and jtf4 are private to the ChuaWeiheng class, so they are not accessible in the Comments class.
The simplest fix is to make Comments an inner class of ChuaWeiheng so it has access to its variables. (That would also be better design becaise the Comments calss has no use except from ChuaWeiheng.)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Why the redundant tests?
Line 4: we know that i<60 because of the if test in line 2, so that part of the test is redundant.
Ditto the <45 on line 6

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

what help EXACTLY do you need?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I looked at IDLE, but I hated its fragmented windows.
I tried PyCharm Community Edition and immediately felt at home - same overall L&F as Netbeans or Eclipse, and a full feature set.
So now I'm having fun taking some demos from my Java tutorial/demo library and trying to implement them (from scratch, not by translating line-by-line!) in Pyton 3.8
No big gotchas yet, but I love the way it treats lists as a primary data type and ignores arrays.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Maybe this is where you are misunderstanding something... (?)
When you define a float constant you need an f, eg 123f, 3.14159fetc so the compiler knows you want a float and not a double.
But when you use a float variable you never add an f to its name - declaring it as float was enough for the compiler to know what to do.
so:
float x = 123f; System.out.println(x); NOT System.out.println(xf);

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

radiusF has to be a variable fro this program, but PI is probably the obvious constant from the java.util.Math class. You can only make an unqualified reference to it like that if you have imported it at the beginning of the source file.

may5457 commented: how do i make radiusf a variable? its suppose to be radius but the f is because its has to be a float +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Hi Guys.

I'm getting bored, and so I'm looking at Python for a new challenge. I hoped to be able to use my Java NetBeans IDE to avoid an IDE learning curve, but it seems that NetBeans support for Python died years ago.

So, all you Python gurus... what do you IDE do you recommend for an experienced Java/SmallTalk developer? Must run on MacOS, must be free.

Stay safe
James

dlblock commented: Have you looked at Atom? +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

What's the most efficient algorithm you have come up with so far? (Pseudo-code or plain English will do... you can't start coding until you know what the algorithm is.)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Not really listening because you have no intention of ever restoring the forums, you just want to win an argument. That's why you started by diverting the discussion to an area where you can win (functionality).
We did beat this to death at the time. I argued that a web page headed "This is the DaniWeb Java forum" s is very different from a web page headed "search results for tag 'java'". The messages they convey about DaniWeb's interest in Java are obvious. You responded with techy stuff about functionality. We didn't agree. It's your web site so the outcome was inevitable. I'm only angry because I care.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Hi. 11 years for me.
I used to be very active in the Java forum, but since Dani got rid if it there's been less and less for me to do. Very sad. ;(

extr3mex commented: 11 years! congrats!! +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

See Nick's answer in this thread.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Netbeans support for C++ was going to be released in version 11.3 but it didn't make it Maybe it will be ready for use in 11.4, maybe not.
Anyway, you need to select a different IDE for C++ right now.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Since when is this site helping scholars with their homework?

Since forever.
We have always been ready to help people learn by explaining where they have gone wrong, or providing guidance when they get lost.
BUT we insist that they first show some effort themselves.
We never do homework for people, and are highly intolerant of people who just post their assignment and expect us to post the code.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

By your definition Java, not producing machine code, and needing a run-time interpreter for its byte codes, is a scripting language.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That's not declaring an abstract method. Please read the whole thread before posting - it you had then you would know that you have defined an empty method (definition is complete, it can be called, but it does nothing). To declare an abstract method you have to either use the abstract keyword or declare the method as part of an interface definition, where methods are abstract by default.

Note also that his thread has beed dead for 9 years, so its unlikely that anyone is still waiting for the answer!

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Q: "I want to learn first aid" A: "I suggest you start with brain surgery"
C++ is a nightnare agglomeration of everything that is difficult from every other language. Definitely not for beginners, nor (IMHO) for anyone else.
Almost any modern language would be a decent place to start. Loops and if tests are pretty universal, as is some kind of OO now.

Remember that what you need to learn to program in real life is like 10% programming language and 90% API/toolset/libraries etc. Some langauges come with a matching API library (eg Java. Swift) but others like need you the chose APIs to learn as well.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You contact the provider to register the product for the new computer. Why is that so hard?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Use JOptionPane.showOptionDialog with options for True and False.
Eg:

        String[] options = {"False", "True"};

        int answer = JOptionPane.showOptionDialog(null,"Java is great?", "Question", 
                JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null,
                options, null);

        if (answer < 0 ) System.out.println("User cancelled/closed dialog");
        else System.out.println(options[answer]);
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Hi
Unlike certain other sites we welcome and encourage discussion and opinions. Anything goes, just keep it legal and don't insult other members.
What would you like to talk about?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

If you are thinking of setting up an outbound cold calling centre then i sincely wish a horrible death on everyone involved. 10 cold calls a day made my life so disrupted that in the end i had to give up my land line. Cold callers are the scum of hhe earth. How do you sleep at night?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

maybe you need to flush/close the output stream explicitly?

Saboor880 commented: Thanks for your response James. I forgot to flush out the streams. I did that and now the pdf is not crashing +3
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I've always preferred test-at-the-bottom for this pattern - keeps it all more local ...

do
      Get user input
      Do processing
      Ask user "continue?"
while user says "yes"
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Test early, test often

Every requirement document is (a) wrong and (b) incomplete

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Overall you are writing far too much code before you start testing.
Just about every part of that code contains errors, so it's never going to give a sensible output, and you will have no idea where to start fixing it.

Break it down into small steps and get each step working before moving on. eg;
load an image and display it
perform some trivial image transformation and display the result (yes, trivial!)
add a timer and display the updated image as you change one input to the transformation
implement the interesting transformations that I guess are the real point of this app

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Your approach to animation isn't going to work. The loop on line 63 is just going to burn 100% of (one of) your CPU's time.
Use a java.util.Timer or a ScheduledThreadPoolExecutor (but not a javax.swing.Timer) to update your model at the required speed and call repaint on your graphics renderer each time.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That looks like a lot of complex code to do something that should be simple. Why are you using an AWT Canvas in a Swing application? Why not just a simple JPanel and override paintComponent?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Scanner comes with its own set of problems, eg the infamous nextInt/nextLine trap

Just like I said.

Using two Scanners with closing causes you to lose the newline char that's left in the first Scanner's buffer after the nextInt.
BUT ironically as it happens discarding a newline is exactly the fix for the infamous nextInt/nextLine trap that you have fallen in to!

Here's the boilerplate explanation that I get to post on Daniweb at least once every year...

It's a real problem with Scanner's design - so many people fall into this trap.
You have some input with an int followed by some text, eg
101
John Doe
... and you try to read it with
int num = scanner.nextInt();
String name = scanner.nextLine();
... and name is an empty String ("")!

Here's why:
Your input looks like this with the new line characters shown explicitly
101\nJohn Doe\n
nextInt takes the int value from the scanner, and stops when it finds a chaacter that's not part of an int, so it takes the "101", leaving this in the scanner
"\nJohn Doe\n"
then nextLine takes everything up to the first \n character - a zero-length String ("").

Possible fixes:

  1. Add add extra nextLine() between the nextInt and the real nextLine to clear the unwanted \n. This may be difficult if the nextInt and the nextLine are in different areas of code which are not always executed together.

  2. Give up on nextInt (etc) and just read …

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

at the moment I'm using 2 in fact even though they're duly closed

Closing a System.in Scanner is not just useless, it's a problem. System.in buffers input and so do Scanners. When you close a Scanner anything that happens to be in its buffers is lost. You will never get that user input back. Even if its only a carriage return thats enough to screw up the following attempts ro read the next input.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The scope of a local variable declaration in a block (§14.4) is the rest of the block in which the declaration appears (Java Language Spec 6.3)

So the exibited behaviour is what the JLS requires, depending on how you see the multiple assignment, but 4.12.3 seems to clarify that

a local variable could always be regarded as being created when its local variable declaration statement is executed.

because the declaration/intialisation will be executed after the assignment to its right.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Hre's another approach that IMHO is much cleaner... use the id property that's inherited by every JavaFX node.

When creating the controls set their id property to the index i
In the event handler get the node from the MouseEvent and get its id
Now you can use a single event handler, and all the info is kept in the JavaFX control where it belons.

Vin vin commented: thanks man, I forgot the setid and getid thing. this makes my project much easier to work with. +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

eventhandler is a interface, so I had to implement instead of extends

That's right. Sorry about that. I'm still on Swing, so my JavaFX is a bit patchy. I just typed that code on my iPad so had no chance to run it through te compiler.
Still, glad it helped :))
JC

ps: Please mark this "solved" if you are happy with the solution for the benefit of future readers

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You could use an ordinary inner class instead of the anonymous event handlers, and pass i to the constructor. Something like

class MyHandler extends Eventhandler {
  int i;
  MyHandler(int i) { this.i = i;}

   @Override
   public void handle(MouseEvent event) {
        UI_SelectionMenu.selectedTile = i;
         System.out.println(UI_SelectionMenu.selectedTile);
   }
 }

 ...

 for (int i = 0 ; i < imgArrayList.size() ; i++) {
        imgArrayList.get(i).setOnMouseClicked(new MyHandler(i));
}
Vin vin commented: james, thank you very much. btw the eventhandler is a interface, so I had to implement instead of extends. But it still helped me a lot (: +1
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Start your own Topic... explain how far you have got and what's blocking you. Show any relevant code, or at least say what language you are using. Help us to help you.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Nowhere in the posted code do you call ReadTxt. That;s probably why it's never executed, which is why you don't see its output.

See how much better this site works when you give all the relevant info?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

only God knows and they are not talking to me at the moment.

Presuming that you are using "they" as a gender-neutral pronoun, then shouldn't that be "they is not talking to me"?
It sounds so wrong, but it's logical.

If, on the other hand you are referring specifically to the Christian 3-in-1 god, then "are" could be correct.

rproffitt commented: And I didn't account for the no-diety scenario. For that, they are truly on their own. +15
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Maha
Your rude demand for someone to drop whatever they are doing and do your homework for you is attached to a 10 year old dead topic. so 0/10 for post quality.

Think on your mistakes, start your own new topic and show some courtesy and some effort, then maybe someone will want to help you.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Almost 200 lies of code with exactly one comment: "bad loop"
We have import statements inside a class
We have zero logging, tracing, debugging info
We have at least 3 methods with zero code in them
We have a BufferedImage that's created at great cost them immediately garbage collected
We have a problem statement that says it's not showing an image in a terminal window (duh!)

... need I go on?

rproffitt commented: Yes, please do. (Also, I read the OP's post and thought bad thoughts.) +15
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Just had a thought...
if you get a random number and multiply it by 3 then you have a new random number that's divisible by 3.
Can it be that simple?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

is it a better wau to modify the program I have already written, or modyfing the code mentioned above?

The second code doesn't do what you need, and you will have to try to understand it before you can mod it, and it's not your code (which is what your teacher expects). So in my opinion you should ignore it and carry on with your own code.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You're going to need an extra loop to keep trying new random numbers until you get one that is divisible by 3 and not present in the numbers you have already got...
in pseudocode...

int nextGoodRandom() {
     do
          get a random nunber
     until number %3==0 AND number is not in the existing numbers
     return number
}

not in the existing numbers can be determined by keeping a list of the numbers you have already used

matt21mcr commented: Thanks for your help. But since I'm a beginner I'm not sure where should I put this loop inside the code of my program... Thanks in advance. +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

In the server code I can't see where you uodate count. I was expecting a count++ somewhere.

the client code listing seems to be corrupted - main method is missing code and server code replaces it!
please repost the client.

M_27 commented: Great +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

In general you would use another class to represent the set of all Clients, eg "ClientBase".
It would have public methods like addClient, printClients, printClientsSorted etc.
Internally it may hold those Clients in an array, or ot may be that some kind of List or Map works better, but by encapsulating it in a class you are free to change the internal implementation without affecting the rest of the program.
(this is the same logic as havimg a Library class to hold all your instances of Book)

Your driver class should never hold implemention logic like this - it shoud just call public methods of your application classes.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Santosh:

Your code contains exactly the same bug as the original. Didn't you read the whole topic before replying?

Maybe you should visit a good leaning site (eg Oracle's own Java tutorials) before makinga fool of yourself like this.

rproffitt commented: Checked their posts. Looks like a spammer to me. +15
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Sorry Rev Jim. My bad.
JC

Reverend Jim commented: "I think I'm getting better." (MP & the Holy Grail) +0
rproffitt commented: "Ah, thanks very much." MP & The Holy Grail. +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You will be working in your chosen career well through the middle of the 2100's
Computer skills will be absolutely essential for you to use the necessary tools and technologies.
Your teachers are trying to help you acquire those skills. Maybe you won't be using visual studio, but the understanding you gain will be transportable to any other computer situation.

You can sulk and show no interest, and fail, and lack the skills to be employed in your chosen career
or
you can see this for the opportunity it is and get on with learning.
If you choose that second approach (and I hope you do) people here will help you.
If you prefer ingorance and a cheated solution then you have come to the wrong place.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

It's hard to answer this without giving the actual solution (which we prefer not to do - you learn more by working it out for yourself), but here's some pseudo-code to show how to do this

declare and initialise a counter before the main loop
inside the loop:
        each time you print a value increment the counter
        if the counter modulo 10 is zero print a newline
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

If you can't tell the difference then this application is too advanced for your current level of knowledge

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Line 2. What if that test comes up true when it should not?

Yes. If two elements of the buttoms array are both equal to the current source then the switch would execute twice, with the observed results.
A real-time trace or some strategic printlns will give the answer.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

line 5 sets available[i] to 0 then line 11 tests for 0

Well, no. Line 5 sets it, line 8 breaks from the switch, and line 11 is never executed. (To be fair, my first guess ws exactly what you said - I had to check the JLS to be sure.)
As far as I can see there's no way for both cases to executed in one pass of that code.

rproffitt commented: Thanks, I skipped that line and being biologically based made an error. Ooops. +15
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

"over extrapolated" ... a worthy sibling to"mis-spoke".

Don't worry, this is the post-truth age of Trump and Boris. Your 10,000 other visitors or newbies can join the unprecedented millions at Trump's inauguration.

None of this matters. DaniWeb is dead, has been for years, and you don't have the technical resources or marketing muscle to revive it.

Looking at the posting activity you, rproffitt, and I may be the only active remanents of the cohorts who enjoyed the forum-based pre-Dazaster days. Fond memories. Time to move on. That's life.