Ik heb het nu zo en werkt nog niet. Volgens mij heb ik het wel goed gedaan...
//paint(graphics);
Als ik bij deze regel het commentaar weg haal, dan print het 2 strepen extra. Die logica snap ik al helemaal niet.
Ik hoop dat er iemand is die mij kan helpen.
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Toolkit;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
public class Lijnen extends JFrame {
/**
*
*/
private static final long serialVersionUID = 1L;
private JLabel jlblBanner = new JLabel("Banner");
public static void main(String[] args) {
new Lijnen();
}
public Lijnen() {
add(jlblBanner);
setTitle("TestGetGraphics");
setLocationRelativeTo(null); // Center the frame
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(800, 600);
setVisible(true);
// Center the JFrame
// Get the size of the screen
Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
// Determine the new location of the window
int wWidth = getSize().width;
int wHeight = getSize().height;
int x = (dim.width - wWidth) / 2;
int y = (dim.height - wHeight) / 2;
// Move the window
setLocation(x, y);
JOptionPane.showMessageDialog(null,
"Delay on purpose\nClick OK to dismiss the dialog");
Graphics graphics = jlblBanner.getGraphics();
//paint(graphics);
}
public void paint(Graphics graphics) {
// Hier ga je dus tekenen
// werkt niet, alleen 1 steeds wel
graphics.drawLine(240, 140, 300, 200);
graphics.drawLine(235, 135, 295, 195);
graphics.drawLine(230, 130, 290, 190);
graphics.drawLine(225, 125, 285, 185);
graphics.drawLine(220, 120, 280, 180);
// werkt wel
graphics.drawLine(500, 500, 550, 550);
}
}