Java progress bar 📊

preview_player
Показать описание
Java progress bar tutorial

#java #progress #bar
Рекомендации по теме
Комментарии
Автор

Guys I accidentally cut out the part about displaying current/total HP.
You would probably want to add a line such as:
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.setFont(new Font("MV Boli", Font.BOLD, 25));



frame.add(bar);

frame.setSize(420, 420);
frame.setLayout(null);
frame.setVisible(true);

fill();
}

public void fill() {
int counter =0;

while(counter<=100) {

bar.setValue(counter);
try {
Thread.sleep(50);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
counter +=1;
}
bar.setString("Done! :)");
}
}

BroCodez
Автор

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!

EmperorVenn
Автор

I always hate loading bars in video games, but i like loading bars to my game :)

Thank you for tutorial!

cannac
Автор

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

puppylili
Автор

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

pavelkvasnicka
Автор

One of the rare java tutorials that is actually enjoyable because I understand everything!

paraparasolian
Автор

Bro, your tutorials are simply perfect!

amikoss
Автор

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
//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

stevancosovic
Автор

Please make a tutorial for a cool animation in java.

noah
Автор

In Mac it doesn't change the foreground and background colours even though I use the methods in the video. :(

Soyosan
Автор

Nice Tutorial
Can you tell me how to change the font color in the progerssbar???<<<

aryanmehta
Автор

If foregound doesn't change the font color in Progress Bar, so how do we change its color ?

salaheddine
Автор

Superb. Hats off to you sir! Stay awesome!

shaynazoedeguzman
Автор

One day Bro code will learn unity and make unity tutorials! Keep doing what ur doing, your amazing man!

NovusTM
Автор

Thanks for all this videos u create, u helped me a lot! Nice job bro...

aleksandarkalanj
Автор

frame.setSize(420, 420) //i like your style bro

pavelmartchenkov
Автор

Great work bro. Please make video for mobile app
It will very helpful for us...

kaushalprasadyadav
Автор

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 YouTube someday.

girl
Автор

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?

lukaivanic
Автор

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?

Yuipser