Guys I accidentally cut out the part about displaying current/total HP. You would probably want to add a line such as: bar.setString(currentHP+"/"+maximumHP+" HP"); //****************************************************************** public class Main{
public static void main(String[] args) {
ProgressBarDemo demo = new ProgressBarDemo();
}
} //****************************************************************** import java.awt.*; import javax.swing.*; public class ProgressBarDemo { JFrame frame = new JFrame(); JProgressBar bar = new JProgressBar(0,100);
Maaaaaan... you actually need more attention, amazing, thanks for the hard work dude! Have you never subscribed to me never would i have found your tutorials. Just wanting to become a software developer and learning python for now and next would be java. I have plans to become a software developer in a year so your tutorials are perfect. Once again, thanks!
You really should get a patreon, there'll be so many people willing to even donate a single dollar just so you can make your already great content 100x better
This is the best Java tutorial for beginners, so you can learn Java and English in one hit. Please keep going! I vote for Java advance tutorial. Thanks a lot Bro
If anyone has problem with JProgressBar showing up until it reaches 100%, here is how I fixed it. You need to create a class which extends Thread class. In this class you should have JProgressBar which can be updated in redefined run method. Also a start button in GUI, here's the example: //Creating a child class of Thread class public class ThreadBar extends Thread { JProgressBar bar;
public ThreadBar(JProgressBar newBar) { this.bar = newBar; }
@Override public void run() { int percentage = 0; while (percentage < 100) { try { sleep(1000); } catch (InterruptedException e) { return; } percentage += 10; bar.setValue(percentage); } } //Starting the Thread "tb" with "Start" button on GUI public JButton getStartButton() { if (startButton == null) { startButton = new JButton("START"); startButton.setBounds(90, 127, 225, 38); StartButtonEvent sbe = new ButtonEvent(); //Event object created in sub-class below startButton.addActionListener(sbe); //Adding the object to the ActionListener } return startButton; }
private class StartButtonEvent implements ActionListener { @Override public void actionPerformed(ActionEvent e) { ThreadBar tb = new ThreadBar(getBar()); //Our thread tb.start(); //Calls the redefined "run" method above } } P.S. I hope it was helpful
I also fixed this by running setVisible(true) inside the method public void fillBar() { int count = 0; setVisible(true); though i really dont understand why it works XD
Thank you so much. You always cost your time to read every comment or questions of us. And thanks to other people who watches this channel too, because they gave me some advice too. And I tried make videos on Chinese platform about how to learning Japanese and how to code or what game I enjoy. But I felt very unhappy because I don’t know why lots of people laughs me, make fun of me, insults me and I didn’t offend them. But I love coding, I will not give up it because it is really fun and I love learning other languages too. I just want to give up making videos on China’s platform, I want to delete all videos I made because it gives me bad memories but I also don’t want because I spend much time on it. But still I loves making videos. I will upload my videos on UA-cam someday.
I would like to watch your videos if you upload them. People will insult you no matter what if you make yourself public, even if you do everything perfect. I get insulted all the time and I only teach coding. Some people just love to hurt others. Don't take it personal.
Could you explain how to make the fill function on a button click, I am asking because I have a for loop with repaint(), when I run the function normally (on the start of the program like you) it works perfectly, but when I activate it on a button click it "freezes" and repaints only when the for loop is done, any clue how to fix this?
You could write something like this. Have a method that is called with a button click public void actionPerformed(ActionEvent e) { if(e.getSource == button){ bar.fill(); } } public void fill(){ bar.setValue(current+x); }
@@BroCodez I got that, the problem is when I put a for loop which has repaint() in the function, it's a common problem but none of the solutions worked for me
@@BroCodez I posted a question so I don't post here chaotically:stackoverflow.com/questions/62679294/jpanel-only-updates-after-the-for-loop-is-finished Also this is the whole code so you can easily run it. Thanks for the help
@@BroCodez I solved it by putting a swing worker around the function, I edited the stack overflow question to the working code, thanks for the help tho!
Absolute Best! Hey Its a really nice way of teaching ! do you have any idea how do i do something like this , lets say , only when i click on a button then the ProgressBar will start running , because in this tutorial it start immediately when we run the program! you are doing the god works! :D Bro Code!
Hey bro Im busy learning Java from your videos and firstly just want to say thanx bro😂 but my actual question is how do u know what to import and what not🤷🏼♂️
You can but it depends on the layout manager you're using. I would recommend creating a JPanel and adding the progress bar to the JPanel. If you're using no layout manager, this should do the trick: final int FRAME_HEIGHT = 600; final int FRAME_WIDTH = 600; final int BAR_WIDTH = 200; final int BAR_HEIGHT = 50; bar.setBounds( (FRAME_WIDTH/2)-(BAR_WIDTH/2), (FRAME_HEIGHT/2)-(BAR_HEIGHT/2), BAR_WIDTH, BAR_HEIGHT); //... panel.setSize(FRAME_WIDTH , FRAME_HEIGHT );
@@BroCodez Yes, but bar.setForeground sets the bar color, not the text color, right? I see from the video that the text color is (looks) blue against the white background but (looks) white against the red background when the bar becomes bigger. Can you set (fix) the font color independent of the bar color?
Brother, if you have any questions go ask it on stackoverflow.com, youtubers have so much to do, and they don't have time, and also stack overflow is a large community so programmers would respond in minutes, wish you the best!
Hello So i just wanna Write a easy Programm which works like this You press on a Button and the progressbar Starts filling. The filling process should be 10 sec. My Problem is that the Animation isnt working. So its just from 0 to 100% with a 10 sec delay. Can you help me out?
Guys I accidentally cut out the part about displaying current/total HP.
You would probably want to add a line such as:
bar.setString(currentHP+"/"+maximumHP+" HP");
//******************************************************************
public class Main{
public static void main(String[] args)
{
ProgressBarDemo demo = new ProgressBarDemo();
}
}
//******************************************************************
import java.awt.*;
import javax.swing.*;
public class ProgressBarDemo {
JFrame frame = new JFrame();
JProgressBar bar = new JProgressBar(0,100);
ProgressBarDemo(){
bar.setValue(0);
bar.setBounds(0,0,420,50);
bar.setStringPainted(true);
bar.setFont(new Font("MV Boli",Font.BOLD,25));
bar.setForeground(Color.red);
bar.setBackground(Color.black);
frame.add(bar);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(420, 420);
frame.setLayout(null);
frame.setVisible(true);
fill();
}
public void fill() {
int counter =0;
while(counter
currentHP and maxHP variables doesn't exit error
@@goodgamershow6505 if they doesn't exist then just create em
@@goodgamershow6505 Are you like new to programming? Create and declare the variables fool!
bar.setString(counter+"/" +"500"+" HP");
@@luke17.10 Awesome thanks :)
Maaaaaan... you actually need more attention, amazing, thanks for the hard work dude!
Have you never subscribed to me never would i have found your tutorials.
Just wanting to become a software developer and learning python for now and next would be java.
I have plans to become a software developer in a year so your tutorials are perfect. Once again, thanks!
thanks for watching! I wish you luck on your pursuits!
@@BroCodez My pleasure! And thank you!
I always hate loading bars in video games, but i like loading bars to my game :)
Thank you for tutorial!
You really should get a patreon, there'll be so many people willing to even donate a single dollar just so you can make your already great content 100x better
This is the best Java tutorial for beginners, so you can learn Java and English in one hit. Please keep going! I vote for Java advance tutorial. Thanks a lot Bro
One of the rare java tutorials that is actually enjoyable because I understand everything!
Bro, your tutorials are simply perfect!
Please make a tutorial for a cool animation in java.
Nice video
One day Bro code will learn unity and make unity tutorials! Keep doing what ur doing, your amazing man!
no promises on Unity lol
Superb. Hats off to you sir! Stay awesome!
Well done
If foregound doesn't change the font color in Progress Bar , so how do we change its color ?
Thanks for all this videos u create, u helped me a lot! Nice job bro...
If anyone has problem with JProgressBar showing up until it reaches 100%, here is how I fixed it. You need to create a class which extends Thread class. In this class you should have JProgressBar which can be updated in redefined run method. Also a start button in GUI, here's the example:
//Creating a child class of Thread class
public class ThreadBar extends Thread
{
JProgressBar bar;
public ThreadBar(JProgressBar newBar)
{
this.bar = newBar;
}
@Override
public void run()
{
int percentage = 0;
while (percentage < 100)
{
try
{
sleep(1000);
}
catch (InterruptedException e)
{
return;
}
percentage += 10;
bar.setValue(percentage);
}
}
//Starting the Thread "tb" with "Start" button on GUI
public JButton getStartButton()
{
if (startButton == null)
{
startButton = new JButton("START");
startButton.setBounds(90, 127, 225, 38);
StartButtonEvent sbe = new ButtonEvent(); //Event object created in sub-class below
startButton.addActionListener(sbe); //Adding the object to the ActionListener
}
return startButton;
}
private class StartButtonEvent implements ActionListener
{
@Override
public void actionPerformed(ActionEvent e)
{
ThreadBar tb = new ThreadBar(getBar()); //Our thread
tb.start(); //Calls the redefined "run" method above
}
}
P.S. I hope it was helpful
Thank you so much dude
I also fixed this by running setVisible(true) inside the method
public void fillBar() {
int count = 0;
setVisible(true);
though i really dont understand why it works XD
In Mac it doesn't change the foreground and background colours even though I use the methods in the video. :(
Cool, thanks for the tutorial
Great work bro. Please make video for mobile app development.....
It will very helpful for us...
Awesome
Nice Tutorial
Can you tell me how to change the font color in the progerssbar???
Nice Explain sir
thanks for watching gauruv
you are best teacher
good luck
You're awesome bro
awesome
best course
Thank you so much. You always cost your time to read every comment or questions of us. And thanks to other people who watches this channel too, because they gave me some advice too. And I tried make videos on Chinese platform about how to learning Japanese and how to code or what game I enjoy. But I felt very unhappy because I don’t know why lots of people laughs me, make fun of me, insults me and I didn’t offend them. But I love coding, I will not give up it because it is really fun and I love learning other languages too. I just want to give up making videos on China’s platform, I want to delete all videos I made because it gives me bad memories but I also don’t want because I spend much time on it. But still I loves making videos. I will upload my videos on UA-cam someday.
I would like to watch your videos if you upload them. People will insult you no matter what if you make yourself public, even if you do everything perfect. I get insulted all the time and I only teach coding. Some people just love to hurt others. Don't take it personal.
Thank you for the content
AWESOME !!
Could you explain how to make the fill function on a button click, I am asking because I have a for loop with repaint(), when I run the function normally (on the start of the program like you) it works perfectly, but when I activate it on a button click it "freezes" and repaints only when the for loop is done, any clue how to fix this?
You could write something like this. Have a method that is called with a button click
public void actionPerformed(ActionEvent e) {
if(e.getSource == button){
bar.fill();
}
}
public void fill(){
bar.setValue(current+x);
}
@@BroCodez I got that, the problem is when I put a for loop which has repaint() in the function, it's a common problem but none of the solutions worked for me
hmmm I'm having a difficult time visualizing this. Could you post the code that you have?
@@BroCodez I posted a question so I don't post here chaotically:stackoverflow.com/questions/62679294/jpanel-only-updates-after-the-for-loop-is-finished
Also this is the whole code so you can easily run it. Thanks for the help
@@BroCodez I solved it by putting a swing worker around the function, I edited the stack overflow question to the working code, thanks for the help tho!
frame.setSize(420, 420) //i like your style bro
My program freezes when the progress bar starts and unfreezes when the progress bar is done
thanks bro
Thank you very much
Absolute Best! Hey Its a really nice way of teaching ! do you have any idea how do i do something like this , lets say , only when i click on a button then the ProgressBar will start running , because in this tutorial it start immediately when we run the program! you are doing the god works! :D Bro Code!
Hey bro Im busy learning Java from your videos and firstly just want to say thanx bro😂 but my actual question is how do u know what to import and what not🤷🏼♂️
why can't I see a frame until the progress bar is 100%?
how can I set my bar to not show me percentages, i want to see only number 20/100 for example
Thank you brother ♥
Why my jprogressbar not showing the progress. When run the frame not show up but after a few second it show 100% progressbar?
I have the same problem
Problem with run method.
can progress bar stay at the center of the jframe? if its possible, i think it will look better.
You can but it depends on the layout manager you're using. I would recommend creating a JPanel and adding the progress bar to the JPanel. If you're using no layout manager, this should do the trick:
final int FRAME_HEIGHT = 600;
final int FRAME_WIDTH = 600;
final int BAR_WIDTH = 200;
final int BAR_HEIGHT = 50;
bar.setBounds(
(FRAME_WIDTH/2)-(BAR_WIDTH/2),
(FRAME_HEIGHT/2)-(BAR_HEIGHT/2),
BAR_WIDTH,
BAR_HEIGHT);
//...
panel.setSize(FRAME_WIDTH , FRAME_HEIGHT );
how to set text color in JProgressBar
bar.setForeground(Color.red);
@@BroCodez Yes, but bar.setForeground sets the bar color, not the text color, right? I see from the video that the text color is (looks) blue against the white background but (looks) white against the red background when the bar becomes bigger. Can you set (fix) the font color independent of the bar color?
I cant change the foreground color and background color even though I copy the same code. I am coding on mac Eclipse, anyone knows why?
Please Help me.. I'm New to Java. How to put this Progress bar to bottom??
Thank you bro code
Thanks
Mine only updates visually when the loop completes. Anyone know how to fix this?
You're the Bro
thanks!
No problem!
Thanks bro:)
Bro! How can I remove the percentage sign
hi bro ,I follow all of your code ,but my progressbar's color can't change ,how to solve this question ,thx!!!!
Brother, if you have any questions go ask it on stackoverflow.com, youtubers have so much to do, and they don't have time, and also stack overflow is a large community so programmers would respond in minutes, wish you the best!
Hello
So i just wanna Write a easy Programm which works like this
You press on a Button and the progressbar Starts filling. The filling process should be 10 sec.
My Problem is that the Animation isnt working. So its just from 0 to 100% with a 10 sec delay. Can you help me out?
I have the same problem
that's cool
Thanks 🌸🤍🌸
I guess were making progress
bro i do exactly in video but the progress bar is only in 100 percent
@@eternalexcalibur run method problem...guys you need to learn alone..
Comment down below ...
thanks Tomasz!
bro
hi
i made progress
64th. Thank you, ma Bro Sensei!