import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
@SuppressWarnings("serial")
public class Applet2017a extends JApplet implements ActionListener {
int x = 0, y = 0;
JPanel drawPanel = new JPanel() {
@Override
public void paint(Graphics g) {
g.clearRect(0, 0, this.getWidth(), this.getHeight());
g.drawLine(x, y, x + 100, y + 100);
}
};
JPanel controlPanel = new JPanel();
JButton button = new JButton("Press me");
{
this.setLayout(new GridLayout(1, 2));
this.add(drawPanel, BorderLayout.EAST);
this.add(controlPanel, BorderLayout.WEST);
controlPanel.add(button);
button.addActionListener(this);
}
@Override
public void actionPerformed(ActionEvent e) {
x += 10;
drawPanel.repaint();
}
}