This week's giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Secure Financial Transactions with Ansible, Terraform, and OpenSCAP and have Lucian Maly on-line!
See this thread for details.
Win a copy of Secure Financial Transactions with Ansible, Terraform, and OpenSCAP this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Rob Spoor
  • Henry Wong
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh
  • Jj Roberts

JProgressBar Array

 
Ranch Hand
Posts: 197
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok
 
Saloon Keeper
Posts: 8020
70
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

ronald deux wrote:you want me to understand debugging or use window and console at the same time


Being able to put print statements in your code to see what it is doing is the simplest form of debugging, and yet very powerful. It's a basic skill for program development. It's made a bit more awkward by GUI project that can have two windows, the console (cmd.exe for example in the Windows environment) and the GUI itself.
 
ronald deux
Ranch Hand
Posts: 197
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm still trying to understand
 
Carey Brown
Saloon Keeper
Posts: 8020
70
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not knowing your environment and how you are running your program I'll give you a possible Windows scenario:

Run a command window (e.g. cmd.exe)
A this point you should have the command window that you started and your GUI program window, provided your GUI hasn't thrown an exception. Any prints or exception messages should appear in the command window.
 
ronald deux
Ranch Hand
Posts: 197
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
myproject> dir
Test.java
myproject> javac Test.java
myproject> java Test

I opened my command line and between this information it doesn't work
 
Carey Brown
Saloon Keeper
Posts: 8020
70
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

ronald deux wrote:myproject> dir
Test.java
myproject> javac Test.java
myproject> java Test

I opened my command line and between this information it doesn't work


Can you post a cut-and-past of your command line window? Or, if that doesn't work, a screen snapshot.
 
Carey Brown
Saloon Keeper
Posts: 8020
70
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Note that "myproject>" is just an example of what you might see as your command line prompt, you might see just ">" or something else, but it is not something you type in.
 
ronald deux
Ranch Hand
Posts: 197
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I installed the terminal plug-in on eclipse
does that do the trick ???
 
ronald deux
Ranch Hand
Posts: 197
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't know how to preview the command line

I typed javac Test.java and java Test and a window opened

even if I put bars [0] [0] .setValue (50) there is no null and nullpointerexception
 
Carey Brown
Saloon Keeper
Posts: 8020
70
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

ronald deux wrote:I installed the terminal plug-in on eclipse
does that do the trick ???


Ah. If you're using Eclipse it is even easier. No terminal plug-in required. The default Java editing configuration has a tab labeled "Console" in the bottom center window. If not then you'd have to poke around in settings in order to activate it. Done. When you run a program any prints or error messages will appear there.
 
Saloon Keeper
Posts: 4358
163
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The purpose of all this printing and consoles is to show you that, although you defined a JProgressBar[][], you never filled that array with a JProgressBar. Never did you use:

By printing it out, you would have noticed that all entries are null.

Then, whatever the title says, you went on by showing 45 JProgressBars, stating: it works!
The question was therefore: what works? Certainly not the array. Then you tried to show a frame in which a JProgressBar was animated. Although the code you used, worked by the look of it, you should never do an animation in that way.

It is wise that when you give some code and ask for comment, to first state what you try to achieve with that code. Comments can then be to the point.
 
ronald deux
Ranch Hand
Posts: 197
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I put bars [0] [0] .setValue (0) and the console displays nullpointerexception
and I also put bars [i] [j] = new JProgressBar (...), the console displays nullpointerexception but the progress bars are not displayed on the window
 
Piet Souris
Saloon Keeper
Posts: 4358
163
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you create an array of JProgressBars (or any other type) then java sets each entry to null. So

will give you a 2D array with 3 x 15 = 45 elements, each initially containing null. Therefore, if you do

you will suffer this NullPointerException, since myBars[0][0] is null. So, lets do:

Now

will work.

But having an array full of JProgressBars doesn't make them visible in a frame! For that you must do like you did in a previous reply, where you showed 45 JProgressBars, although you did not use that 2D array for this. Now, go back to that code, try to get that 2D array working and use that array to place the JProgressBars in your frame.

I've written a small demo, in which you will see a JProgressBar showing the progress, after you click the button. If the "download" is not ready yet, and you click the button again, it will pause, and continue on the next click. If the download is finished, then a click will restart the process. But what is a nuisance, is that the buttontext does not change. I would like to have that when a download is underway, then rhe buttontext should be "pause", and when a download is paused, it should report "continue". However, I failed to get that coded. Would you like to give it a try?
 
ronald deux
Ranch Hand
Posts: 197
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you did not manage to code, it's weird
you have more experience than me
I understand your code but it doesn't work
I'm trying to understand the error on the console

Error: Main method not found in class RonaldDeux2, please define the main method as:
  public static void main(String[] args)
or a JavaFX application class must extend javafx.application.Application
 
Carey Brown
Saloon Keeper
Posts: 8020
70
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This depends on which version of Java you are using. You shouldn't be using anything older than Java 8.
 
ronald deux
Ranch Hand
Posts: 197
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have the 8 java

piet mouse works with which java ???
 
Piet Souris
Saloon Keeper
Posts: 4358
163
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My bad. I made a java file called: RonaldDeus2.java, and then muy IDE (NetBeans) just creates a template starting with

and then I just add the Test class. Since this class has a main method, and RonaldDeux2 has not, NetBeans executes Test.main on the run command.

So, delete that line "public  class RonaldDeux2 {}", use Eclipse to create a new class called Test, and copy the code in it. That should do the trick.

PS: case you are wondering why the "2": it is because I already had a class called RonaldDeux, that was about drawing a 6-petal flower.
 
ronald deux
Ranch Hand
Posts: 197
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
well uh, I deleted the class RonaldDeux2 and it gives
Error: Could not find or load main class Main
Caused by: java.lang.ClassNotFoundException: Main
I tried to use netbeans for sure
 
ronald deux
Ranch Hand
Posts: 197
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Great
I managed to run on netbeans
it works as you said

it's good it works on eclipse and netbeans
I will try to find the continue key

 
My first bit of advice is that if you are going to be a mime, you shouldn't talk. Even the tiny ad is nodding:
SKIP - a book about connecting industrious people with elderly land owners
https://coderanch.com/t/skip-book
reply
    Bookmark Topic Watch Topic
  • New Topic