I am trying to add a panel to my frame, but it keeps giving me one error that I don't seem to understand.
Multiple markers at this line
- Debug Current Instruction Pointer
- The method add(Component) in the type Container is
not applicable for the arguments (TestPanel)
import javax.swing.*;
public class FrameTest3 {
public static void main(String[] args) {
TestPanel samplePanel=new TestPanel();
JFrame sampleFrame = new JFrame();
sampleFrame.getContentPane().add(samplePanel);
sampleFrame.setSize(300,200);
sampleFrame.setVisible(true);
System.out.println("Done");
}
}
import java.awt.*;
import javax.swing.*;
public class TestPanel extends JPanel {
public void paintComponent(Graphics g) {
g.setColor(Color.red);
g.drawString("hello", 30, 80);
}
}