Hello, I'm making a Java code for school but unfortunately I have some issues.
This is my script til now on:
import java.awt.*; import javax.swing.*; import javax.swing.event.*; public class Cirkels extends JFrame{ public static void main(String[] args) { Cirkels w = new Cirkels(); w.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); w.setSize(800,650); w.setVisible(true); } private JSlider slider; private JLabel tekstslider; private Paneel mijnpaneel; public Cirkels(){ mijnpaneel = new Paneel(); mijnpaneel.setBackground(Color.GRAY); mijnpaneel.setOpaque(true); slider = new JSlider(SwingConstants.HORIZONTAL, 0, 200, 10); slider.setMajorTickSpacing(10); slider.setPaintTicks(true); slider.addChangeListener( new ChangeListener(){ public void stateChanged(ChangeEvent e){ mijnpaneel.setD(slider.getValue()); } } ); add(slider, BorderLayout.SOUTH) ; add(mijnpaneel, BorderLayout.CENTER) ; } public class Paneel extends JPanel{ private int d = 10; public void paintComponent (Graphics g) { super.paintComponent (g); g.setColor(Color.WHITE); g.drawOval(25, 100, d, d); g.drawOval(175, 100, d, d); g.drawOval(325, 100, d, d); g.drawOval(475, 100, d, d); g.drawOval(625, 100, d, d); g.drawOval(100, 200, d, d); g.drawOval(250, 200, d, d); g.drawOval(400, 200, d, d); g.drawOval(550, 200, d, d); } public void setD(int newD){ d = (newD >= 0 ? newD : 10); repaint(); } public Dimension getPrefferedSize() { return new Dimension(200,200); } public Dimension getMinimumSize() { return getPrefferedSize(); } } }
I want to add a JButton to make the ovals different colors, so for example:
JButton for Red and a JButton for Blue, but when I add the buttons the whole layout mess up and no buttons appear...
Can someone help me with adding the buttons?
Sorry for my English, I'm Dutch