I'm trying to draw a blue square and a red square but treat them as though they are individual components that can be added to the contentPane. With the code below only the red square appears. If I comment out frame.contentPane.add(redAy) the blue square appears. Can anyone tell me what is going on and how to fix it so both squares appear?
Thanks.
 
import javax.swing as swing
import java
 
#-------------------------- blue -----------------------
class BlueAyComp(swing.JPanel):
 x = 0
 y = 0
 w = 0
 h = 0
 
 def __init__(self, ulx, uly, width, hite):
  self.x = ulx
  self.y = uly
  self.w = width
  self.h = hite  
  self.setForeground(java.awt.Color.blue)
  
 def paintComponent(self, g):   
  g.drawRect(self.x, self.y, self.w, self.h)
 
#--------------------------- red ----------------------
class RedAyComp(swing.JPanel):
 x = 0
 y = 0
 w = 0
 h = 0
 
 def __init__(self, ulx, uly, width, hite):
  self.x = ulx
  self.y = uly
  self.w = width
  self.h = hite
  self.setForeground(java.awt.Color.red)
  
 def paintComponent(self, g): 
  g.drawRect(self.x, self.y, self.w, self.h)
 
#-----------------------------------------------------------
frame = swing.JFrame("Class Test", visible = 1, defaultCloseOperation = swing.JFrame.EXIT_ON_CLOSE)
frame.setSize(500,400)
frame.setBackground(java.awt.Color.white)
 
blueAy = BlueAyComp(40, 40, 30, 30)
redAy = RedAyComp(200,200,30,30)
 
frame.contentPane.add(blueAy)
frame.contentPane.add(redAy)
frame.show()