Intermediate Java Tutorial – 25 – Finishing the Oval Slider Program

Facebook –
GitHub –
Google+ –
LinkedIn –
reddit –
Support –
thenewboston –
Twitter –






21 responses to “Intermediate Java Tutorial – 25 – Finishing the Oval Slider Program”

  1. Souhel Ayoub Avatar

    Can anybody tell me what is wrong with this Slider? I still have error next to the line < new ChangeListener()>.
    package eng;
    import java.awt.BorderLayout;
    import java.awt.Color;
    import javafx.beans.value.ChangeListener;
    import javax.swing.JFrame;
    import javax.swing.JSlider;
    import javax.swing.SwingConstants;
    import javax.swing.event.ChangeEvent;

    public class TheWindow extends JFrame{

    private JSlider slider;
    private DrawOval myPanel;

    public TheWindow(){
    super("the Title");
    myPanel=new DrawOval();
    slider=new JSlider(SwingConstants.HORIZONTAL,0,200,10);

    new ChangeListener(){
    /*anynomous ….is not abstract and does not override abstract method changed(ObservableValue, Object,Object)in Changelistener.. … can't be converted to javax.swing.event.ChangeListener ….. */
    public void stateChanged(ChangeEvent e){
    add(slider, BorderLayout.SOUTH);
    add(myPanel, BorderLayout.CENTER);

  2. Vaishnav Garodia Avatar

    Bucky you are a expert in so many languages that I think Microsoft would really accept you as their lead programmer

  3. Patrascu Lucian Avatar

    This oval is a circle. Also, if you use g.fillOval(10, 10, 200, 100); you just draw an eclipse, which is awesome especially if you're using eclipse

  4. Roshan Zaid Avatar

    All what i get is a grey box as the output. neither the oval nor the slider. bucky roberts! i care of your piece of cake. need a solution soon.

  5. Tom Spencer Avatar

    FYI for anyone who is interested:-

    g.fillOval(110-(d/2), 110-(d/2), d, d);

    put that in paintCompnent in the drawOval class in place of the original g.fillOval line and it will draw the circle in the center of the screen so it won't grow from the corner, but instead expand out from the center.

  6. Tom Spencer Avatar

    /Finishes slider program /Sits there sliding the slider back and forth very fast /Feels like hees being sucked into a black hole /Realises Bucky is a James Bond villain who is trying to destroy us all!!!!!!

  7. West Brown Avatar

    yeah, the paintComponent() was paint() for me.

  8. Mark Alexa Avatar

    "….. leading manager for building circles !" cracked me up so hard ….

  9. paul hunter Avatar

    .setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); ,isn't working it is showing error(The method setDefaultCloseOperation(int) is undefined for the type animationscontinue)

  10. hello Avatar

    did any made a game or any app using knowledge upto this tutorial ……..if yes then PLEASE reply ….because that will help everyone to come up with something new and MOST important Interest will persist

  11. kadinscido Avatar

    So lemme get this straight….there's a method, inside a method, inside an argument? (ChangeListener)

  12. meriem karoun Avatar

    If you have problem with the oval not showing, it s in the method PaintComponent, make sure you spell it right!

  13. Kidane Yosief Avatar

    Why could not I see my circle in the Panel please?

  14. vljzlj Avatar

    if you press ctrl + Shift + o in eclipse it imports every thing your program needs to run correctly , just press that after u finished coding 🙂 so u dont need to mess with ' ah i cant remember what I need to import'

  15. bibek shakya Avatar

    programmer +comedian

  16. Jeremy Chen Avatar

    import java.awt.*;
    import javax.swing.*;
    import javax.swing.event.*;

    public class TheWindow extends JFrame{

        private JSlider slider;
        private DrawOval myPanel;

        public TheWindow() {
            super("The title");

            myPanel = new DrawOval();

            slider = new JSlider(SwingConstants.HORIZONTAL, 0, 200, 10);
                    new ChangeListener() {
                        public void stateChanged(ChangeEvent e) {

            add(slider, BorderLayout.SOUTH);
            add(myPanel, BorderLayout.CENTER);



    import java.awt.*;
    import javax.swing.*;

    public class DrawOval extends JPanel{

        private int d = 10;

        public void paintComponent(Graphics g) {
            g.fillOval(10, 10, d, d);

        public void setD(int newD) {
            d = (newD >=0 ? newD : 10);

        public Dimension getPreferredSize() {
            return new Dimension(200, 200);

        public Dimension getMinimumSize() {
            return getPreferredSize();

  17. The Humanity Avatar

    the paintComponent() method doesn't register as the JPanel built in method. For me, the paint() method worked with super.paint(g) instead of paintComponent

  18. Suman Gurung Avatar

    I checked and re checked. did exactly like in the video and when i execute it 
    it only shows window with slider Heeeelp !! WTF is happening

  19. Shivashriganesh Mahato Avatar

    Have a fun time in Microsoft!

  20. Kristiyan Gostev Avatar

    If you are linux user (I use GNOME), add
    add(slider, BorderLayout.SOUTH);
    add(myPanel, BorderLayout.CENTER);
    or the circle will not show.


    thanks for your clean and understandable tutorials

Leave a Reply

Your email address will not be published. Required fields are marked *