I figured it out. Now it works. Have a look on the following code:
<CODE>
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.util.*;
public class TestFrame
{
public JButton button;
public JFrame jFrame = new JFrame();
public JScrollPane scrollPane;
public JSplitPane jSplitpane;
public PaintPanel panel;
public static void main(
String[] args)
{
TestFrame frame = new TestFrame();
}
public TestFrame()
{
jFrame.setSize(300,300);
jFrame.setLocation(300,300);
panel = new PaintPanel();
panel.setBackground(Color.black);
panel.setSize(1000,1000);
scrollPane = new JScrollPane(panel);
panel.setPreferredSize(new Dimension(1000,1000));
button = new JButton();
button.setText("Step");
jSplitpane = new JSplitPane(JSplitPane.VERTICAL_SPLIT,button,scrollPane);
jSplitpane.setContinuousLayout(true);
jFrame.getContentPane().add(jSplitpane);
jFrame.setVisible(true);
button.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
button_actionPerformed(e);
}
});
}
void button_actionPerformed(ActionEvent e) {
this.panel.repaint();
}
}
class PaintPanel extends JPanel
{
private int x1 = 0;
private int x2 = 0;
private int y1 = 0;
private int y2 = 0;
private Random r = new Random();
private ArrayList arrayList = new ArrayList();
protected void paintComponent(Graphics g)
{
super.paintComponent(g);
g.setColor(Color.white);
paintLine(g);
}
protected void paintLine(Graphics g)
{
ArrayList v = new ArrayList();
v = createNewData();
arrayList.add(v);
for (int n=0;n<arrayList.size()-1;n++)>
{
v = (ArrayList) arrayList.get(n);
x1 = ((Integer) v.get(0)).intValue();
y1 = ((Integer) v.get(1)).intValue();
x2 = ((Integer) v.get(2)).intValue();
y2 = ((Integer) v.get(3)).intValue();
g.drawLine(x1,y1,x2,y2);
}
}
public ArrayList createNewData()
{
ArrayList v = new ArrayList();
for (int n=0;n<4;n++){
Integer a = new Integer((int)(r.nextInt(1000)));
v.add(a);
}
return v;
}
}
</CODE>
Thanks,
Fredwurst