import java.awt.Graphics;
import javax.swing.JPanel;
import java.awt.Color;
public class DrawPanel extends JPanel {
public void paintComponent(Graphics g) {
int height = getHeight();
int width = getWidth();
g.drawRect(350, 510, 110, 170);
g.drawRect(470, 510, 110, 170);
g.drawRect(590, 510, 110, 170);
g.drawRect(710, 510, 110, 170);
g.drawRect(830, 510, 110, 170);
g.drawRect(350, 30, 110, 170);
g.drawRect(470, 30, 110, 170);
g.drawRect(590, 30, 110, 170);
g.drawRect(710, 30, 110, 170);
g.drawRect(830, 30, 110, 170);
g.setColor(Color.RED);
g.drawRect(110, 450, 110, 170);
g.drawRect(110, 60, 110, 170);
}
}
Run Code Online (Sandbox Code Playgroud)
我需要为每个Rectangle(我的意思是在Rectangle内)着色红色,但是使用这个g.setColor(Color.RED); 我只能为Rectanlge的外部部分着色