I am a new programmer and I'm reading the "Sams Teach Yourself Java in 24 Hours" and I'm doing a chapter on the color class. The program displays two rectangles on blue and on a random color I made and also a string which is red. But when I run it the only thing that comes up is the frame. I'm using NetBeans in linux. Here is the code for a class I named Peach and for a class named eric(I know there dumb names but they are just random names I thought of.) Can someone tell me why it doesn't work. It works in the book but not for me.
Peach class
import java.awt.*; import javax.swing.*; public class Peach extends JPanel{ public void paintComponet(Graphics g){ super.paintComponent(g); this.setBackground(Color.WHITE); g.setColor(Color.BLUE); g.fillRect(25, 25, 100, 30); g.setColor(new Color(190, 81, 215)); g.fillRect(25, 65, 100, 30); g.setColor(Color.RED); g.drawString("this is text", 25, 120); } }
eric class
import javax.swing.*; public class eric{ public static void main(String[] args){ JFrame f = new JFrame("Title"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setSize(400,250); Peach p = new Peach(); f.add(p); f.setVisible(true); } }