package com.gautam.notepad;
import javax.swing.*;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Graphics;
public class main {
public static void main(String[] args) {
panel1 p =new panel1(); // This is the panel1 class object
new App("NOTEPAD",p); // i'm trying to pass panel1 object
}
}
class App extends JFrame {
public App(String title,panel1 panel)
{
this.setTitle(title);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setVisible(true);
this.setLocationRelativeTo(null);
this.setSize(800, 640);
this.setLayout(new FlowLayout());
this.add(panel);
this.setResizable(false);
}
}
class panel1 extends JPanel{
public void paintComponent(Graphics g)
{
g.setColor(Color.green);
g.fillRect(0, 0, this.getWidth(), this.getHeight());
}
}
it works fine but in the paintcomponent method it is g.fillRect() method is not working it is not painting the whole screen only small rectangle is painted in the middle of the screen.what is the problem in this code