import java.awt.Graphics; import javax.swing.JComponent; import javax.swing.JFrame; import javax.swing.JPanel; public class Painting extends JFrame { public Painting() { JPanel panel = new JPanel(); this.setSize(333, 200); this.setVisible(true); this.add(panel); panel.add(new Extra("Jasmin Rahimic")); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } public static void main(String[] args) { Painting c = new Painting(); } } class Extra extends JComponent { String str; public Extra(String s) { this.setSize(70, 70); this.str = s; } public void paintComponent(Graphics g) { g.drawString(str, 50, 50); } }
Can someone tell me why paintComponent() is not being called.
Thank you.