Hier ist mein jetziger Code!
Vielen Dank ! :-)
public class GUI extends JFrame {
public JPanel contentPane;
private Linien grafik;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
GUI frame = new GUI();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public GUI() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
final JSlider slider = new JSlider();
slider.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent arg0) {
grafik.d=((JSlider)arg0.getSource()).getValue();
System.out.println(grafik.d);
grafik.repaint();
}
});
grafik = new Linien();
JPanel panel = new Linien();
panel.setBounds(77, 34, 137, 140);
contentPane.add(panel);
panel.setBackground(Color.ORANGE);
slider.setMajorTickSpacing(100);
slider.setValue(10);
slider.setPaintLabels(true);
slider.setBounds(125, 196, 200, 37);
contentPane.add(slider);
}
}
und hier die Linien.java
public class Linien extends JPanel
{
public int d;
public Linien()
{
System.out.println("Lininen-d-Wert: "+d);
}
public void paintComponent(Graphics g){
super.paintComponent(g);
g.fillOval(10,10,d ,d);
repaint();
}
}