Just need some assistance with drawing random rectangles inside of a JPanel when the form loads. I have a seperate rectangle class created that has a constructor for the following :
It also has a paint method. I also have another JFrame class for my GUI created but I am new to GUIs and not sure how to do this. My panel is named panelRectangles and when the form loads it is supposed to create a whole bunch of random rectangles in the panel to be used for sorting. I am supposed to use the following code to make a seperate class that extends JPanel and will be used to draw my rectangles but not sure where it goes.. in my GUI Frame Class? Thanks for any assistance.Code:public Rectangle(int newX, int newY, int newWidth, int newHeight, Color newColor) { x = newX; y = newY; width = newWidth; height = newHeight; color = newColor; }
Code:staticclass RectanglePanel extends JPanel { public RectanglePanel() { super(); setOpaque(false); // don't paint all the bits setBorder(BorderFactory.createLineBorder(Color.black)); } protectedvoid paintComponent(Graphics g) { // code to paint the rectangles goes here } }




Reply With Quote