这是选择画出一连串的图形
请问如果要修改成同心圆需要修改哪一些地方呢?
因为我修改了很多次,都是以失败收场。
谢谢大家的指教~
package Shapes;
import java.awt.Graphics;
import javax.swing.JPanel;
public class Shapes extends JPanel
{
private int choice;
public Shapes(int userChioce)
{
choice = userChioce;
}
public void paintComponent(Graphics g)
{
super.paintComponent(g);
for( int i = 0; i<12; i++)
{
switch(choice)
{
case 1:
g.drawRect(10 + i * 10, 10 + i * 10, 50 + i * 10, 50 + i * 10);
break;
case 2:
g.drawOval(10+ i * 10, 10 + i * 10, 50 + i * 10, 50 + i * 10);
break;
}
}
}
}
package Shapes;
import java.awt.Graphics;
import javax.swing.JOptionPane;
import javax.swing.JFrame;
public class ShapesTest
{
public static void main(String args[])
{
String input = JOptionPane.showInputDialog("输入1画矩形\n"+"输入2画椭圆形");
int choice = Integer.parseInt(input);
Shapes panel = new Shapes(choice);
JFrame application = new JFrame();
application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
application.add(panel);
application.setSize(300, 300);
application.setVisible(true);
}
}
该贴被藏剑天策编辑于2016-2-23 15:23:21