我在用不同颜色的 30px 正方形填充框架时遇到了这个奇怪的问题。这是我的尝试,但不起作用(也无法弄清楚如何设置正方形的大小)
import java.awt.Component;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.util.Random;
public class Pixl extends Component
{
public void paint(Graphics g)
{
Graphics2D g2d = (Graphics2D)g;
g.setColor(Color.CYAN);
int x = 25;
int y = 32;
g.drawLine(x,y,x,y);
}
public static void main(String[] args)
{
int frameWidth = 300;
int frameHeight = 300;
javax.swing.JFrame frame = new javax.swing.JFrame();
frame.setSize(frameWidth,frameHeight);
frame.setVisible(true);
frame.getContentPane().add(new DrawingComponent());
}
}
谢谢