1
\$\begingroup\$

I have some working code with a small circle randomly appearing around a large circle in the middle, kinda like planets. I have implemented a JSlider that controls the speed of the small ball moving around, and has set it's location to BorderLayout.SOUTH. The problem is that you can't see the slider when you run. You have to click fullscreen for it to appear. I have a windows computer and I know that it is blocked by the toolbar, but I kinda don't want to move it. Is there a way to use Java and set it to fullscreen without doing it manually? Here is my code:

     package com.company;

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

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

public class Main extends JPanel {



       private static JFrame frame = new JFrame();
        private static int random = 11;
        private static JSlider timeController = new JSlider(1000, 3000, 3000);
        private static Runnable number = () -> random = (int) (Math.random() * 110) + 1;

        private static ScheduledExecutorService executor1 = Executors.newScheduledThreadPool(1);

        public static void main(String[] args) {
            number = () -> random = (int) (Math.random() * 100) + 1;
            executor1.scheduleWithFixedDelay(number, 0, timeController.getValue(), TimeUnit.MILLISECONDS);
            frame.getContentPane().add(new Main());
            frame.setSize(2000, 1080);
            frame.setLocationRelativeTo(null);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setBackground(Color.GRAY);
            frame.setExtendedState(JFrame.MAXIMIZED_HORIZ);
            frame.setVisible(true);
            frame.setResizable(true);
            timeController.setBackground(Color.RED);

            timeController.setFont(new Font("Arial Black", Font.ITALIC, 10));
            timeController.setForeground(Color.CYAN);
            timeController.setMajorTickSpacing(100);
            timeController.setMinorTickSpacing(10);
            timeController.setPaintTicks(true);
            timeController.setPaintLabels(true);
            timeController.addChangeListener(e -> sliderChanged());
            frame.add(timeController, BorderLayout.SOUTH);

        }

        private static void sliderChanged() {
            executor1.shutdown();
            executor1 = Executors.newScheduledThreadPool(1);
            number = () -> random = (int) (Math.random() * 110) + 1;
            executor1.scheduleWithFixedDelay(number, 0, (timeController.getValue()), TimeUnit.MILLISECONDS);
        }

        public void paint(Graphics g2) {
            Graphics2D g = (Graphics2D) g2;
            g.fillOval(770, 250, 400, 400);
            g.setColor(Color.BLACK);
            if (random > 0 && random <= 15) {
                g.fillOval(920, 3, 100, 100);
            } else

 if (random > 15 && random <= 20) {
            g.fillOval(920, 797, 100, 100);
        } else if (random > 20 && random <= 35) {
            g.fillOval(523, 400, 100, 100);
        } else if (random > 35 && random <= 50) {
            g.fillOval(1317, 400, 100, 100);
        } else if (random > 50 && random <= 65) {
            g.fillOval(620, 143, 100, 100);
        } else if (random > 65 && random <= 80) {
            g.fillOval(1220, 143, 100, 100);
        } else if (random > 80 && random <= 90) {
            g.fillOval(620, 657, 100, 100);
        } else if (random > 90 && random <= 100) {
            g.fillOval(1220, 657, 100, 100);
        }
        frame.repaint();
    }
}
\$\endgroup\$
2
  • \$\begingroup\$ instead of changing a question after an answer has been posted i would suggest that you ask a second question instead, see Edit and here \$\endgroup\$ Commented Feb 12, 2020 at 5:07
  • \$\begingroup\$ Have you tried adding all the components before you make the frame visible? \$\endgroup\$ Commented Feb 12, 2020 at 12:25

0

You must log in to answer this question.

Browse other questions tagged .