package cis2168_1; import javax.swing.*; import java.awt.*; import java.awt.event.*; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; /** * * @author Rolf */ public class Main extends JPanel implements ChangeListener{ JFrame theFrame; Container cPane; int posX = 0, posY = 0; public Main() { theFrame = new JFrame("Graphics Test"); theFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); cPane = theFrame.getContentPane(); cPane.setLayout(new BorderLayout()); JSlider slider = new JSlider(); cPane.add(slider,BorderLayout.SOUTH); this.setPreferredSize(new Dimension(800,800)); cPane.add(this,BorderLayout.CENTER); slider.addChangeListener(this); theFrame.pack(); theFrame.setVisible(true); } public void paintComponent(Graphics g){ g.setColor(Color.PINK); g.fillRect(0,0,800,800); g.setColor(Color.RED); g.fillOval(posX, posY, 100,100); } public static void main(String[] args) { new Main(); } public void stateChanged(ChangeEvent e) { JSlider s = (JSlider)e.getSource(); posX = s.getValue() * 8; double py = (double)s.getValue(); py = py/100.0*Math.PI*2; posY = (int)(Math.sin(py)*300)+400; this.repaint(); } }