java生成圆形怎么写

1.怎么样用JAVA编写出一个圆形import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics; import javax.swing.JFrame; import javax.swing.JPanel; public class TestSw extends JFrame { public static void main(String[] args) { new TestSw(); } public TestSw(){ super("Test"); this.setSize(new Dimension(400,300)); this.setContentPane(new Mypane()); this.setVisible(true); this.(JFrame.EXIT_ON_CLOSE); } class Mypane extends JPanel{ public void paint(Graphics g) { super.paint(g); g.setColor(Color.red); g.setXORMode(Color.white); g.drawArc(20, 20, 100, 100, 0, 360); ///此方法将画一个直径100的圆.红色. } } } 。
2.java如何制作图片一样形状的按钮你可以用setIcon方法为按钮设置背景图片,例如:button1.setIcon(new ImageIcon("image.jpg"));你可以把图片裁剪成你希望的大小,再来加载 。
下面是一个具体的演示程序:public class WinTest4{ public static void main(String[] args) { JFrame frame = new JFrame(); frame.(JFrame.EXIT_ON_CLOSE); frame.setExtendedState(JFrame.MAXIMIZED_BOTH); frame.setLayout(new FlowLayout()); JButton button1 = new JButton(); button1.setIcon(new ImageIcon("image.jpg")); frame.add(button1); frame.setVisible(true); }} 。
【java生成圆形怎么写】

java生成圆形怎么写

文章插图