Java 程序在 Swing 中创建圆形边框
首先,我们创建一个框架 (Frame)
JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setUndecorated(true);
现在,创建圆形边框
double x = 50; double y = 50; frame.setShape(new RoundRectangle2D.Double(x, y, 100, 100, 50, 50));
以下是一个在 Swing 中创建圆形边框的示例
示例
import java.awt.geom.RoundRectangle2D; import javax.swing.JFrame; import javax.swing.JPanel; public class SwingDemo extends JPanel { public static void main(String[] args) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setUndecorated(true); double x = 50; double y = 50; frame.setShape(new RoundRectangle2D.Double(x, y, 100, 100, 50, 50)); frame.setSize(600, 500); frame.setLocationByPlatform(true); frame.setVisible(true); } }
输出
广告