我正在尝试制作一个gui应用程序,在用户运行时显示彩虹.无论出于何种原因,半圆都不会出现在窗口中.我做了一个调试方法,它显示x和y都是0.有人能告诉我什么是错的吗?
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Container;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class Rainbow extends JPanel
{
// Declare skyColor:
static Color skyColor = Color.CYAN;
public Rainbow()
{
setBackground(skyColor);
}
// Draws the rainbow.
public void paintComponent(Graphics g)
{
super.paintComponent(g);
int width = getWidth();
int height = getHeight();
// Declare and initialize local int variables xCenter, yCenter
// that represent the center of the rainbow rings:
int xCenter = (1/2)*width;
int yCenter = (3/4)*height;
// Declare and initialize the radius …Run Code Online (Sandbox Code Playgroud)