Java slider 🌡️

  Рет қаралды 28,957

Bro Code

Bro Code

Күн бұрын

Пікірлер: 66
@BroCodez
@BroCodez 4 жыл бұрын
//************************************************** public class Main { public static void main(String[] args) { // JSlider = GUI component that lets user enter a value // by using an adjustable sliding knob on a track SliderDemo sliderDemo = new SliderDemo(); } } //************************************************** import java.awt.*; import javax.swing.*; import javax.swing.event.*; public class SliderDemo implements ChangeListener{ JFrame frame; JPanel panel; JLabel label; JSlider slider; SliderDemo(){ frame = new JFrame("Slider Demo"); panel = new JPanel(); label = new JLabel(); slider = new JSlider(0,100,50); slider.setPreferredSize(new Dimension(400,200)); slider.setPaintTicks(true); slider.setMinorTickSpacing(10); slider.setPaintTrack(true); slider.setMajorTickSpacing(25); slider.setPaintLabels(true); slider.setFont(new Font("MV Boli",Font.PLAIN,15)); label.setFont(new Font("MV Boli",Font.PLAIN,25)); //slider.setOrientation(SwingConstants.HORIZONTAL); slider.setOrientation(SwingConstants.VERTICAL); label.setText("°C = "+ slider.getValue()); slider.addChangeListener(this); panel.add(slider); panel.add(label); frame.add(panel); frame.setSize(420,420); frame.setVisible(true); } @Override public void stateChanged(ChangeEvent e) { label.setText("°C = "+ slider.getValue()); } }
@JoaoPedroPF18
@JoaoPedroPF18 2 жыл бұрын
why we cant use this. in frame. ?
@milton5682
@milton5682 3 жыл бұрын
Finally someone who really explains well this
@pgorellana
@pgorellana 25 күн бұрын
I have enjoyed doing the good example about Java Slider. Thanks for that from Chile
@FrizzleTheDizzle
@FrizzleTheDizzle 4 жыл бұрын
BEST JAVA SERIES ON YT
@pavelkvasnicka6856
@pavelkvasnicka6856 Жыл бұрын
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
@hamlek6923
@hamlek6923 3 жыл бұрын
The best coding courses ever
@somerandomuser8005
@somerandomuser8005 2 жыл бұрын
Thanks for everything so far! Definitely will continue watching. This is like a game using the slider and a couple labels. (main method just has to have "new GetThere();" asides from the pre-generated stuff) import java.awt.*; import javax.swing.*; import javax.swing.event.*; import java.util.Random; public class GetThere implements ChangeListener{ //Game variables Random r = new Random(); //Edit Here int min = 0; // any number int max = 100; // must be greater than min int goal = r.nextInt(max-min)+min; int points; //GUI JFrame frame; JPanel panel; JLabel current; JLabel point; JLabel goalLabel; JSlider slider; GetThere(){ frame = new JFrame("Slider Demonstration"); panel = new JPanel(); current = new JLabel(); point = new JLabel(); goalLabel = new JLabel(); slider = new JSlider(min,max,(max+min)/2); // Low , High, Start slider.setPreferredSize(new Dimension(1000,200)); //size of the slider in the frame slider.setPaintTicks(true); // See ticks on the track slider.setPaintTrack(true); // See the track slider.setPaintLabels(true); // See number labels slider.setBackground(Color.black); panel.setBackground(Color.black); //Edit based on slider size slider.setMinorTickSpacing(5); slider.setMajorTickSpacing(25); //Fonts of ... slider.setFont(new Font("MV Boli",Font.BOLD,15)); //Slider numbers slider.setForeground(new Color(25,155,25)); // Text Color current.setFont(new Font("MV Boli",Font.BOLD,15)); //Current current.setForeground(new Color(25,155,25)); point.setFont(new Font("MV Boli",Font.BOLD,18)); //Point point.setForeground(new Color(35,175,35)); goalLabel.setFont(new Font("MV Boli",Font.BOLD,15)); //Goal goalLabel.setForeground(new Color(25,155,25)); //Default Texts current.setText("Current Pos: "+ slider.getValue()); point.setText("| Points: "+ points +" |"); goalLabel.setText("Goal: "+ goal); //slider.setOrientation(SwingConstants.VERTICAL); // Default is horizontal slider.addChangeListener(this); // when you move the thing /* * Only way I could keep things from shaking and having the labels under the slider * and all that stuff (high x-distance between things in FlowLayout). * A better way will prob show up */ panel.setLayout(new FlowLayout(FlowLayout.CENTER,1000,10)); //Add things to the panel panel.add(slider); panel.add(current); panel.add(point); panel.add(goalLabel); //Add things to the FRAME frame.add(panel); //Frame stuff frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(1250,750); //So frame isn't smol frame.setVisible(true); } @Override public void stateChanged(ChangeEvent e) { // TODO Auto-generated method stub //Format: Current Pos: 69 | Points: 1 | Goal: 420 //Updates Text current.setText("Current Pos: "+ slider.getValue()); point.setText(" | Points: "+ points +" | "); goalLabel.setText("Goal: "+ goal); if(slider.getValue() == goal) { goal = r.nextInt(max-min)+min; points ++; } } } //edit was for rearranging sentences
@chchong68
@chchong68 3 жыл бұрын
Thank you very much for sharing this video, easy to understand.
@colonelcanada-9500
@colonelcanada-9500 2 жыл бұрын
Great channel, helped me with my grade 12 summative the whole way through!
@pratikshahegde8554
@pratikshahegde8554 4 жыл бұрын
I have subscribed to your channel. You are amazing. I like the way u introduce yourself 🤩
@BroCodez
@BroCodez 4 жыл бұрын
It's ya bro!
@speklex779
@speklex779 Жыл бұрын
Nice video. Thank you
@rayyanasia4349
@rayyanasia4349 3 жыл бұрын
Thanks very useful tutorial
@irobot3868
@irobot3868 2 жыл бұрын
nice ☺, for to write this " ° " tap "Alt + 248" , your explanation is the best thank you BRO
@babushaikh6582
@babushaikh6582 4 жыл бұрын
Nice work
@kingkock1
@kingkock1 2 жыл бұрын
early mornings with Bro just keep getting better xx
@yusuphmwaigomole3104
@yusuphmwaigomole3104 2 жыл бұрын
Your Guru bro
@sabermmirza
@sabermmirza 4 жыл бұрын
Nice work thanks
@fieldsfury
@fieldsfury 2 жыл бұрын
Another great lesson!
@kemann3815
@kemann3815 3 жыл бұрын
Lovely
@FrizzleTheDizzle
@FrizzleTheDizzle 4 жыл бұрын
its awesome that i can just get ma bro to help me hue hue
@henriquefelinimena3693
@henriquefelinimena3693 3 жыл бұрын
thank you for the content
@VAWAV
@VAWAV 4 жыл бұрын
Keep it up😁
@user-alexkristal
@user-alexkristal 3 жыл бұрын
The degree sumbol Alt + 0176. By the way, keep going with making a videos! Thank you, bro! And LIKE, comment and subscribe are done!
@milton5682
@milton5682 3 жыл бұрын
I also do that with: Shift + | (The key to the left of the 1)
@greeneggsandmushrooms9855
@greeneggsandmushrooms9855 3 жыл бұрын
i can't wait for the waterslides this summer
@VAWAV
@VAWAV 4 жыл бұрын
I love you😍
@MrLoser-ks2xn
@MrLoser-ks2xn 2 жыл бұрын
Thanks
@majid1885
@majid1885 3 жыл бұрын
Thank you very much
@ibrahimylmaz8378
@ibrahimylmaz8378 2 жыл бұрын
thanks bro
@angelcastineira2561
@angelcastineira2561 4 жыл бұрын
//is there a significant difference between this code: slider.addChangeListener(this); @Override public void stateChanged(ChangeEvent e) { label.setText("°C = "+ slider.getValue()); } // and this one?: slider.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { label.setText("°C = "+ slider.getValue()); } });
@BroCodez
@BroCodez 4 жыл бұрын
I believe both would be fine. They perform the same task. The second one might be better for a larger program, because you're using an anonymous inner class. It's more efficient. I have a video on inner classes coming up in this playlist
@angelcastineira2561
@angelcastineira2561 4 жыл бұрын
@@BroCodez thanks!
@lequangnghi194
@lequangnghi194 3 жыл бұрын
I'm wondering why my label is not underneath the slider but on the right side, can someone help me please?
@Arthur-g5n8q
@Arthur-g5n8q 8 күн бұрын
Why use the stateChanged rather than the actionListener?
@giahuypham1857
@giahuypham1857 11 ай бұрын
breaking more utube algorithmsssssssssssssss
@MmdRsh
@MmdRsh Жыл бұрын
king
@uykerrykaberga
@uykerrykaberga 2 жыл бұрын
thnx bruh
@Soyosan22
@Soyosan22 2 жыл бұрын
You forgot: frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
@nehalayaaz9406
@nehalayaaz9406 4 жыл бұрын
thanks 😊
@nawfalnjm5699
@nawfalnjm5699 3 жыл бұрын
thank you
@matheustavares4597
@matheustavares4597 3 жыл бұрын
I rewrote the code i realized i don't need a panel to use JSlider, why did you use panel in this code? example: import javax.swing.JFrame; import javax.swing.JSlider; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; public class Main extends JFrame { JButton b; JPanel panel; JSlider slider; Main(){ b = new JButton(); b.setText("Click here"); b.addActionListener(new event()); slider = new JSlider(0,100); slider.setPaintTicks(true); slider.setMinorTickSpacing(10); slider.setPaintTrack(true); slider.setMajorTickSpacing(25); slider.setPaintLabels(true);// this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setLayout(new FlowLayout()); this.add(b); this.add(slider); this.pack(); this.setVisible(true); } public static void main(String[] args){ new Main(); } class event implements ActionListener{ @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub System.out.println("You have manipulated the temperature to " + slider.getValue()); } } }
@michalj121
@michalj121 2 жыл бұрын
Hi! label.setText(“C “+slider.getValue()); label.setVerticalTextPosition(JLabel.Top); label.setHorizontalTextPosition(JLabel.Left); Whatever position I set (Left,Right,Top etc..), the text doesn’t move after restart the program. Why??
@sehejkumar9984
@sehejkumar9984 2 жыл бұрын
change the left to LEFT and Top to TOP cuz it shld be capitalized
@arpitchauhan5212
@arpitchauhan5212 2 жыл бұрын
how to increase and decrease the Value by taking input from the User?
@jakubmrazek001
@jakubmrazek001 2 жыл бұрын
You can do it with a scanner + method setValue(int value) Scanner scanner = new Scanner(System.in); JSlider slider = new JSlider(); int value = scanner.nextInt(); slider.setValue(value);
@sivanaintharaj2498
@sivanaintharaj2498 Жыл бұрын
👍
@Monsta1291
@Monsta1291 2 жыл бұрын
import java.awt.Dimension; import java.awt.Font; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JSlider; import javax.swing.SwingConstants; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; public class SliderDemo implements ChangeListener { JFrame frame; JPanel panel; JLabel label; JSlider slider; SliderDemo(){ frame = new JFrame("Slider Demo"); panel = new JPanel(); label = new JLabel(); slider = new JSlider(0,100,50); slider.setPreferredSize(new Dimension(400,200)); slider.setPaintTicks(true); slider.setMinorTickSpacing(10); slider.setPaintTicks(true); slider.setMajorTickSpacing(25); slider.setPaintLabels(true); slider.setFont(new Font("MV Boli",Font.PLAIN,15)); label.setFont(new Font("MV Boli",Font.PLAIN,25)); slider.setOrientation(SwingConstants.VERTICAL); label.setText("°C = "+slider.getValue()); slider.addChangeListener(this); panel.add(slider); panel.add(label); frame.add(panel); frame.setSize(420, 420); frame.setVisible(true); } @Override public void stateChanged(ChangeEvent e) { label.setText("°C = "+slider.getValue()); } }
@akshaykumarsharma
@akshaykumarsharma 4 жыл бұрын
How about this. If you have any suggestions just tell me.
@karippaitech8963
@karippaitech8963 Жыл бұрын
My value is not changing
@Christopher-krd
@Christopher-krd Жыл бұрын
KZbin ALGORYTH
@tingping7684
@tingping7684 3 жыл бұрын
It's a great video , I like this . But , I don't know when we should use panel , label . I usually think frame can add everything we want :(
@tanishq_xin
@tanishq_xin 3 жыл бұрын
this comment is to help you, help ME
@dogukan-u2n
@dogukan-u2n Жыл бұрын
I'm the 777th person to like :D
@eugenezuev7349
@eugenezuev7349 7 ай бұрын
noise
@zari_723
@zari_723 2 жыл бұрын
the next comment
@CheerfulBackpacker-hp1kn
@CheerfulBackpacker-hp1kn 7 ай бұрын
My slider shows the progress of read pages off a book: public class Main { public static void main(String[] args) { MySlider mySlider = new MySlider(); } } //************************************************ import javax.swing.*; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import java.awt.*; public class MySlider implements ChangeListener { JFrame frame; JPanel panel; JLabel label; JSlider slider; MySlider() { frame = new JFrame("Page Counter"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); label = new JLabel("Page #: 0"); frame.pack(); panel = new JPanel(); slider = new JSlider(0, 500, 0); slider.setPreferredSize(new Dimension(500, 50)); slider.setPaintTicks(true); slider.setMinorTickSpacing(10); slider.setPaintLabels(true); slider.setFont(new Font("MV Boli", Font.PLAIN, 20)); slider.setOrientation(SwingConstants.HORIZONTAL); slider.addChangeListener(this); panel.add(slider); panel.add(label); frame.add(panel); frame.setSize(700, 80); frame.setVisible(true); } @Override public void stateChanged(ChangeEvent e) { int pageNumber = slider.getValue(); label.setText("Page # = " + pageNumber); } } Thank you, Bro!
@fillaliziad2702
@fillaliziad2702 3 жыл бұрын
thank you
Java progress bar 📊
11:14
Bro Code
Рет қаралды 36 М.
Java lambda λ
18:00
Bro Code
Рет қаралды 99 М.
Мен атып көрмегенмін ! | Qalam | 5 серия
25:41
Гениальное изобретение из обычного стаканчика!
00:31
Лютая физика | Олимпиадная физика
Рет қаралды 4,8 МЛН
Java generics ❓
22:04
Bro Code
Рет қаралды 119 М.
Java GUI 🖼️
12:45
Bro Code
Рет қаралды 135 М.
Java stopwatch ⏱️
27:41
Bro Code
Рет қаралды 65 М.
Java KeyListener 🚀
13:11
Bro Code
Рет қаралды 101 М.
Java BorderLayout 🧭
11:40
Bro Code
Рет қаралды 70 М.
Java threads 🧵
16:01
Bro Code
Рет қаралды 125 М.
Java select a file 🔎
9:33
Bro Code
Рет қаралды 65 М.
Java labels 👨‍💻
18:00
Bro Code
Рет қаралды 102 М.
Java menubar 🗄️
15:17
Bro Code
Рет қаралды 51 М.
Мен атып көрмегенмін ! | Qalam | 5 серия
25:41