ronak07 ronak07 - 4 months ago 52
Java Question

drawLine using AWT

I just started with GUI using AWT. The frame is opening but the Line is not being displayed.

frame image

import java.awt.*;
import java.awt.event.*;

class A extends Frame
public static void main(String args[])
Frame f= new Frame();
f.setTitle("New Frame");
f.addWindowListener(new WindowAdapter(){public void windowClosing(WindowEvent we){System.exit(0);}});

public void paint(Graphics g)


You're creating a Frame object, not an A object, and so your paint method is never called.

Instead of

Frame a = new Frame();


A a = new A();

Side comment: your paint method override should call the super's method within it.

Having said this, why are you using AWT, a library that has now been superseded by not one but two newer graphics libraries, first Swing and now JavaFx? AWT is beyond dead at this point.