我想要一个蓝色边框的爱心
时间: 2024-03-04 15:48:06 浏览: 18
以下是一个使用Java Swing库,并且具有蓝色边框的爱心示例代码:
```
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class LoveHeart extends JPanel {
private static final long serialVersionUID = 1L;
private static final int WIDTH = 300, HEIGHT = 300;
public LoveHeart() {
this.setBackground(Color.WHITE);
}
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
g.setColor(Color.BLUE);
g.drawArc(50, 50, 120, 120, 0, -180);
g.drawArc(110, 50, 120, 120, 0, -180);
g.fillArc(75, 60, 100, 100, 0, -180);
}
public static void main(String[] args) {
JFrame frame = new JFrame("Love Heart");
frame.setSize(WIDTH, HEIGHT);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setResizable(false);
LoveHeart loveHeart = new LoveHeart();
frame.add(loveHeart);
frame.setVisible(true);
}
}
```
运行该程序,将在一个窗口中显示一个带有蓝色边框的爱心形状。