Eclipse do not show output

I'm making 2D drawing on Eclipse Oxygen, there are no error in my code but why it does not show any output. I mean when I click run there are no progress.

import java.awt.Color;
import java.awt.Frame;
import java.awt.Graphics2D;
import java.awt.geom.Arc2D;
import java.awt.geom.Rectangle2D;

public class HOUSE1 extends Frame {
    public void paint(Graphics2D g) {
        Graphics2D g2d = (Graphics2D) g;

        g2d.drawString("HOME SWEET HOME",80,60);
        setBackground(Color.white);

        Arc2D arc1 = new Arc2D.Double(250,50,500,300,225,90,Arc2D.Double.PIE);
        g2d.draw(arc1);
        g2d.setColor(Color.red);
        g2d.fill(arc1);

        Rectangle2D rect = new Rectangle2D.Double(325,300,350,300);
        g2d.draw(rect);
        g2d.setColor(Color.blue);
        g2d.fill(rect);

        Rectangle2D rect1 = new Rectangle2D.Double(325,300,350,300);
        g2d.draw(rect1);
        g2d.setColor(Color.black);
        g2d.fill(rect1);            
    }

    public static void main(String[]args){
        HOUSE1 f = new HOUSE1();
        f.setTitle("HOUSE");
        f.setSize(300,100);         
    }

}

3 answers

  • answered 2018-01-14 10:57 BluEOS

    You forgot to make your frame visible.

    Just add :

    f.setVisible(true);
    

    You have to fix your paint method declaration to :

    @override
    public void paint(Graphics g) {
        // your code
    }
    

  • answered 2018-01-14 10:57 Kevin Anderson

    Your window is blank because your paint method is never called. Your method

    public void paint(Graphics2D g)    // DOESN'T WORK
    

    needs to be changed to

    public void paint(Graphics g)    // Correct
    

    so that it overrides the paint method in Frame. The graphics system will only call paint(Graphics); if your method called paint isn't overriding the method paint(Graphics) in Frame, the one in Frame gets called instead of yours.

  • answered 2018-01-14 10:57 kobar1990

    1st: In your main void you need to set your frame (f) to visible --> f.setVisible(true)

    2nd: Also you might want to f.pack(); right before you set it to visible to to make sure your components are behaving like expected.

    3th: In java we use a capital first letter in class like this "House", fully capital words are used for final's.