The problem with the initialization of Graphics g. The drawing does not start if I call the paint()
method; He demands to transfer argument there. I create the Graphics g argument, it requires it to be initialized, with what and how incomprehensible.
What do you need to add to make paint()
?
import java.awt.FlowLayout; import java.awt.Graphics; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; public class GrSw { react rt = new react(); JFrame fr = new JFrame(); JPanel pn= new JPanel(); JButton bt= new JButton("OK"); FlowLayout fl = new FlowLayout(); GrSw() { bt.addActionListener(rt); pn.add(bt); fr.add(pn); fr.setLayout(fl); fr.setSize(400,100); fr.setVisible(true); } void paint(Graphics g){ g.drawLine(100,100,400,400); } public static void main(String[] args) { GrSw add = new GrSw(); } }