package com;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
public class DrawDemo extends JFrame implements ActionListener{
JButton btnSelect;
int level=10;
public DrawDemo() {
super("绘图Demo");
btnSelect = new JButton("输入数量");
btnSelect.addActionListener(this);
add(btnSelect,BorderLayout.NORTH);
setSize(700,700);
setVisible(true);
setResizable(false);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
}
@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource() == btnSelect) {
//用输入对话框获取用户的值
String s=JOptionPane.showInputDialog("请输入(1~50)的数字", 10);
//点击了取消按钮
if(s==null) {
return;
}
level = Integer.parseInt(s);
repaint();
}
}
@Override
public void paint(Graphics g) {
super.paint(g);
//画图
int r = 50;
int x0=getSize().width/2;
int y0=getSize().height/2;//圆心
for(int i=0;i<level;i++) {
r += 10;
g.setColor(Color.RED);
g.drawOval(x0,y0,r,r);//椭圆
}
}
public static void main(String[] args) {
new DrawDemo();
}
}
这个也没什么思路,会用swing写GUI的应该就搞定了,自己弄吧