Campbell Ritchie

+ Follow
since Oct 13, 2005
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Rancher Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Campbell Ritchie

Welcome to the Ranch

Joseph Zhao wrote:. . . I have tried to create another jframe that creates a JProgressBar  . . .

I can't see where you are creating the progress bar, not even by using ctrfl‑F. You are not going to solve anything in the midst of so much code. Your code has problems:
  • 1: Use of public variables
  • 2: Subclassing too many display classes: don't subclass frames, for example.
  • 3: Inconsistent indentation and too many blank lines. Don't double space your code.
  • 4: Methods too long. Your paintComponent() method occupies 150 lines and does calculations which should be done elsewhere.
  • I suggest you follow the examples in the Java™ Tutorials, and you may need to use a worker thread/SwingWorker object to update the data and the progress bar.
    7 hours ago

    Paul Clapham wrote: . . . String literals go into the string pool. . . .

    I thought all Strings that are compile‑time constants go into the String pool, and you can add an existing String to the pool with the intern() method. Yes, that is what the intern() link says.

    PP: remember you rarely need to know this information. The fact that a String pool is mentioned in the documentation like that commits Oracle to maintaining the String pool for ever.
    7 hours ago
    Please avoid screenshots and please always tell us where the material comes from. Is it another question from Boyarsky and Selikoff? Please tell us the book title and page number.
    Did you run the code? I think the way to solve that sort of question is to write down on paper what each object is, and what its fields point to.

    Remember that is very poor quality code, which should only ever be seen in cert. exams or cert. exam revision books
    The substring() method might work, but you will have to work out the indices to split on. You will have to look for semicolons, angle signs, etc. The whole thing looks error‑prone to me. You would have similar problems with String#split(), even if you already know how to write the appropriate regular expressions.
    17 hours ago
    Your changes to remove the error messages make my reply look like nonsense; I have changed them back.

    Don't try writing new FizzSwitch() because FizzSwitch isn't a type. It is inappropriate to start a method name with F; start it with f. If you change line 6 to read...then,
  • 1: Where does it say anything about nulls?
  • 2; What is the reference returned from that method? Is it the same as f1, the same as f2, or different?
  • 3: What changes has that method made to f1 and f2? Or has it made no changes?
  • You obviously have an old .class file left over from a previous compilation attempt. I copied your code onto JShell and it compiled without error. I don't know how you got those errors. You appear to have introduced errors when you included the spaces in the print statement.

    It should be obvious why your output is falsetrue. Look at the effects of the == operator, and you should be able to work it out for yourself. I don't know what the swtchFizz() method will do because I haven't seen how you are using it.
    Are you sure you copied the code right? Line 12: should read args[1]. Not that it helped when I corrected that. I am getting no sound either. Sorry I can't help any more.
    18 hours ago

    Jeanne Boyarsky wrote:. . . . They was a solar Eclipse . . . .

    I have seen that photograph somewhere; there is a tiny little star which apparently moves a tiny little distance from the Sun during the eclipse.
    23 hours ago

    Jeanne Boyarsky wrote:. . . . The correct link is here[/url]. . . .

    Well done finding it; I can see the difference now you pointed it out.
    It would be a good idea for OP to get a friend to review his resumé/CV. Checking that all the links open would only be a small part of that process.
    1 day ago
    So, when was general relativity actually published?
    1 day ago
    What you are doing in a Predicate<T> is taking a T an applying it to the test() method. But test() takes a T as its parameter. So you have a T somewhere.
    You are trying to find the equivalent of s.isEmpty(). The test(T) call must use the T somewhere, so it goes into the λ to work out where. It would usually execute s.isEmpty() in which case you write the method reference as String::isEmpty. That might look like a static method call, but it isn't because isEmpty() is an instance method. The T cannot be applied to the method because isEmpty() takes no parameters, so the no‑args method is called, and the T is transferred to become the object on which the method is called.
    If you write str::isEmpty, the object name has already been used, so there is nowhere to pass an object anywhere.
    Please show us the original question, so we can see what you changed.
    Line 16 shows you setting the monitor, line 17 shows which object you are using as the monitor, and line 24 shows the monitor being released. I am not sure what lines 26‑29 30 do.

    [Edit] change line numbers; I am quoting the numbers on the left not the right.
    Regular readers will already know that Manning are giving a 50% discount on all “MEAP” books today.
    1 day ago