JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Good advice, but 9 years too late.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

iPads now run iPadOS, not iPhone IOS. As you may guess it's optimised for the tablet screen sizes.

According to Apple the iPad Pro series run desktop Safari. I use a pro and MacOS and haven't seen any differences.

rproffitt commented: I'll mention there is Chrome for iPad as well. +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

In your case you may wish to start with an array, fill it with the starting data or states then code to follow those rules and iterate (loop) over the rule the number of times you wish.

You can't do this with one array. You need a second array to hold the new values because the alogorithm requires the original values until the whole grid has been evaluated.

rproffitt commented: You're right. But be careful as it can get out of control as some do with cats or other pets. +15
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

My neighbour's son is a freelance 3D graphics artist. He had two years work on his PC when someone in the flat below fell asleep with cigarette in his hand, and burned down the building. That was last month. He had no backups.
He justifies it by saying how rare house fires are. I asked if whether it would be any better if someone stole his PC - not a rare ocurrence.
He's now rebuilding his models as best he can from memory.

He still has no backup plan.

Reverend Jim commented: When you lose, don't lose the lesson. Right? +14
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

A char is a one-byte integer value, used ti hold the ASCII value of a single character.
A string literal (enclosed in double quotes) is equivalent to an array of chars.
So on line 5 you are trying to assign an array (more precisely a pointer to an array) to an integer data type.
If you just want a single char then the correct syntax for the literal is to use single quotes, ie '?'

TLDR: a char and a one-character-long string are completely different animals.

rproffitt commented: I've heard that programmers consume coffee and emit code are animals too. Each one very different from the next. +15
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You are missing a semi-colon on line 238.

(Yes, I know its a guess, but since you didn't say what the problem was, or show us the code, all I had was a guess)

rproffitt commented: The Emperor's New Code. +1 +15
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

maybe I'm just an old-timer who started with binary, but for me flipping the last bit just screams odd/even, but the modulus arithmetic I had to think about. Guess it all depends where you'e coming from

static int MakeOddOrEven(int num, boolean odd) { // java 
    return odd ? num | 1 : num & 0xFFFFFFFE;
}
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

How about ANDing it with 0xFFFFFFFE for even, ORing it with 0x00000001 for odd?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Not quite true any more. SInce the introduction of lambdas Java has "default methods" in interfaces, which are inherited by any class that implements the interface. And yes, because you can implement multiple interfaces, this leads to exactly the same diamond problem as multiple inheritance from classes. There are new rules to determine what to do when a class inherits two methods with the same signature from different interfaces, but IMHO its a bit of a dog'e breakfast. I think it was a situation forced on the designers as a necessary cost of implementing lambdas in a totally backwards-compatible way.
It reminds me of the introduction of generics in 1.5. The implementation is a compromised mess because it had to be crowbarred into existing Java without breaking anything. Ditto Optionals. I'm sure they would love to start again with a clean sheet, or at least the option to be incompatible with some existing code, but then maybe they should just use Swift. :)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Using double buffering works, but it's unnecessary complexity and overhead. Swing already has double buffering internally.

Threre are also sound reasons for not directly painting in a JFrame... eg what happens when you want to add any Swing controls to that JFrame. Using a subclass of JPanel as in your first code is the right way to go.

All you you need is to clear/initialise the panel on only the first call to paintComponent (use a boolean to control that). Easy.

Edit:

Just to make the point, all your original code needed was one line at the start of your paintComponent:

if (count == 0) super.paintComponent(g);

so very close!

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You have (quite rightly) overridden paintComponent.
super's paintComponent is responsible for clearing/setting the background, so you have missed that functionality and and are starting with whatever is left over in one of Swing's graphics buffers.

your paintComponent method needs to start with a super.paintComponent(g); on its first call to ensure that the background is cleared correctly. (Or you can clear it yourself by filling with a suitable coloured rectangle.)

note that paintComponent may be called by Swing at any time (eg when a window is moved/resized etc) and any number of times, so updating the counter and the random numbers should ideally happen in your timer's actionPerformed, not in PaintComponent.

rproffitt commented: Thanks for clarifying their posted code is not a single file. Also, your answer makes sense as to the code behavior, that is, it worked as coded. +15
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Wrong wrong wrong. Terrible advice.
Layout managers are essential for creating apps that run on screens with different resolutions or different fonts.
You need to learn to use them, not turn them off.
See https://docs.oracle.com/javase/tutorial/uiswing/layout/index.html

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

^ like rproffitt said.

The normal way to specify where databases are stored on the server is by specifying a Java system property called derby.system.home on the server. It would be quite bizzare if simply starting a Derby server would allow a remote user to create files anywhere in the server's file system!

The "version incompatability" I mentioned can also refer to the fact that there is no guarantee of compatibility of Java 7 with any 2019 operating system.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Java compilers have an option to compile using the syntax of a previous version, but in any case if you have code that stops running after Java 7 then you need to uodate it anyway.

The 5 is interesting because it sugests you have contacted a running responding server (the normal message is 0 bytes, meaning no reply... the server is not running or otherwize inaccessible). maybe it's a version incompatability?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You are using Java 7 - no public support since 2015. You should be very worried about your security. Current Java is 13. So the first thing is to update all your installations before trying again.
Also that "classForDriver" thing was replaced years and years ago by DriverManager. see https://docs.oracle.com/javase/tutorial/jdbc/basics/connecting.html

Are you sure it's "received only 5 bytes"? Zero bytes is the usual message.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Like rproffitt said:
don't extend a solved topic with a new question. Start a new topic and re-post your question there.
In the meantime have a look at https://docs.oracle.com/javase/tutorial/jdbc/basics/connecting.html
(Also you are using obsolete code on an obsolete version of Java, so anything could happen.)

Saboor880 commented: Ok James +3
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Click on "Reply to this topic" and there's a "Question Solved" slide switch at the bottom.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes, that worked perfectly.

Of course it did! ;)

Glad to have helped
JC

ps: Mark Question Solved?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That could be much easier amd faster of you sorted the List (or create a sorted copy) first. Then just store every record that's equal to the previous record.

If not... have you tried changing line 5 to
for(int j = i+1; ...
... which should fix it for one duplicate, but stilll leaves a problem for multiple duplicates.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

What can I not now rebut your slander?

Yes, of course you can try. You are free to express your opinions (within the DaniWeb Community Rules), as is Reverend Jim.
You may find that you are a lone voice in this community of rational informed thinking people.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Great!
Let me know if/when that's done and I'll help you get the Listener stuff working.
JC

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK. Step 1: Separate the data from the user interface - ie separate the Model from the View.
You should have a class that loads and holds the master list of Items and has public methods for adding and removing items, getting items etc. It has no UI. The windows should be passed the manager instance into their constructors so they can use it to access whatever data or functionality they need.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Sure. I'll get something together tomorrow. Goodnight. J

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes. You can pass the address or the array, but both actually pass the address. Specifying the array size seems to have no real effect other than to document a pre-condition, but maybe there are some subtle differences that are beyond me.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Room1 has three exits but only one connecting room, so any attempt to go in the second or third exit will crash for lack of a corresponding connecting room.

cakeboy commented: Hi, thanks for the reply. I put the extra exits in to test some of the code and forgot to delete it. +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You can start by considering these three options to see which fits your needs best...

  1. Make it public. Very easy, but horrible violation of encapsulation
  2. Have a public method (or methods) in Sale that updates the combo box - eg addItem(Item i) removeItem(Item i). A bit more code, and it encapsulates nicely, but creates an untidy dependency between the main Item list and the Sale window.
  3. Use a Listener/Observer pattern so the Sale window adds itself as a listener to wherever the master list of Items is held. This is the best architecture - classic MVC - but the most code.
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK, I get that.
Although the sale window is not visible, it still exists, with all its components. So you can update the contents of its combo box at any time. So when you add or remove items you need to update the combo box immediately. Then whenever you display the sale window the combo box will be up to date.
You just need to ensure that the code where you add or remove items has access to the combo box object... there are multiple ways to do that, which we can discuss if you want.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I saw this topic briefy late last night (C.E.S.T.) and it seemed odd. Now in the morning it still seems odd. It's not at all clear what is the problem here.
Whenever you add or delete products you need to update the combo box's contents (add or remove an item, or simply re-load the whole contents). What is it about that that is causing you difficulty?

Saboor880 commented: Thanks for your response James. I have added another reply and explained the problem in detail. Kindly go through it. +3
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Here's the help you need:

You won't learn anything from someone else writing the code. Do your best then if you get stuck come back here and explain what you have done and what's stopping you going further.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

map(s -> Optional.of(s)) is transforming those objects into Optionals, correct?

Yes, but more accuratel: .map creates a new Stream from the values returned by the lambda.

There are probably other ways to do it, but this is a really obvious and easy-to-read solution.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Something like this should give you enough info...

        Stream<Integer> si = Stream.of(1, 2, 3, 4, 5);
        List<Optional<Integer>> result = si.filter(i -> i < 4).
                        map(i -> Optional.of(i)).
                        collect(Collectors.toList());
        System.out.println(result);
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

First look at what is inside each loop and decide whether it belongs inside or outside the loop. Eg: how many times do you want to print out the standard deviation? How many times do you need to calcuiate the total?
Second: what is noLoop()?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yeah. The OP was tagged "java", so that's clear enough.
The bracketing style, regardless of what you call it or how you feel about it, is consistent with that used throughout java itself (language reference, offical tutorials, API source code), so it's as de-facto a standard as anything can be.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You must explain exactly what help you need.

rproffitt commented: Should we follow the OP's format? Write it down, snap a picture and upload the reply? (Yes, PLEASE!) +15
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You can't define a method inside another method.

ps: next time post the complete error message with line numbers etc

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

VisiCalc?

TeaGG commented: Good question.... I'll now go off and have a nose around to see if I can find that and see if it sparks any memories... (!). Thank you. +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

probably 2(n+1) that looks like a function call - the multiplication needs to be explicit as in 2*(n+1)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Why go to all this trouble writing everything from scratch?

Blame me; I'm the one who ws pushing this approach. This topic is all about learning about REST and JSON. In my opinion it's near impossible to understand (eg) Spring vs Jackson unless you first understand what JSON is and why it's so totally bloody useless for serving Java objects. Trying to implement a tiny example by hand will make that clear. For a learner it's also a great exercise to write a JSON parser.
But obviously for a real-life application you'ld be mad to do it all yourself from scratch.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Well done. You posted exactly the same question as the first post in this old thread. I guess you didn't read the complete discussion, or the complete solution in the last post. Then you asked for "help" without saying what help you needed.

People here wil help you, but you have to put in some efort and thought yourself.

Start a new topic for your discussion. Post what you have dome so far. Explain exactly what help youqare seeking. The brief spells out the code almost line by line, so it's not clear why you are having difficulty.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Do you mean MVC as in Model-View-Controller?
If so, it's just an architectural principle. A quick Google will point you to dozens of explanations - all less than a page long. There's not much to learn about that.
Depending on language and architecture there are many MVC frameworks and libraries, all of which come with some kind of more-or-less painful learning curve. Sadly those learnings are not redily transferrable between differnet frameworks.

rproffitt commented: My thought exactly. Common as donut shops. +15
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You can...
import static java.lang.Math.PI; and refer to it as PI
or
don't use an import and refer to it as java.lang.Math.PI in your code.

Why???

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

If you start to press the next key before you have fully released the previous one then the release will override the press. Maybe that's part of the problem???

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

No. You just start the same client code twice, or as many times as you want for many clients.
But you do have to enhance the server code to keep track of the clients, and keep separate data input/output streams open for each client, and have separate threads waiting for input from each client.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Great! Well done.
JC

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

We had a long and very productive discussion about exactly this a few years ago. Here's the thread
https://www.daniweb.com/programming/software-development/threads/254810/find-the-differences-between-two-images-and-the-locations-of-the-differences
You need to read the whole thing to get the final answer.
JC

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

if I placed the class just in v7, the error is gone and the music can play, but if the class is inside of v7.v1 then I get that error.

Then just place the class in v7! Faffing around with IDEs just a distraction from learning a language or API.

ps: putting JavaFX code in init() is generally a bad idea. The JavaFX environment is not fully ready at that time. You are much safer ignoring init()and putting everything in start(...)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Looks like some very quiet music. (those numbers are deciBels)
While testing it will be more manageable if you have (say) 8 bands rather than 256.

I thought if I set the interval to 60, I thought it would update 60 times per second

I guessed that was the case. It's a really good example of why you should ALWAYS read the API doc for any method you're not familiar with.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

how do I see when listener is called

OK, you seem to be missing some basic understanding here. It's just like using a listener for someone pressing a button.

You have set this as a audio spectrum listener. Which means:

  • this contains a spectrumDataUpdate listener method
  • when the media is playing JavaFX will reguarly call your spectrumDataUpdate method at the interval you have requested (60 seconds!) passing it the audio spectrum data for the latest interval.
  • In your spectrumDataUpdate method you do whatever you want with that data, eg correct the magnitudes and pass it to another method that displays it

PS: You may want to set a lower interval. The default is 0.1 seconds.

pps: It's best if you reply with a new post rather than a comment because new comments don't get prioretised in the "latest posts" listing that I'm monitoring.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You can’t print those values in the start method. Start runs once and is finished before the music starts playing.
You can only access the values via the spectrum listener when the listener is called.

ps: you may want to have the listener called more that once per minute ;)

Vin vin commented: how do I see when listener is called +0
rproffitt commented: The old PRINT A; A=1: issue. Why did A print? +15
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The last link you posted explains how to get and understand the magnitudes, so what exactly is your question?