⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bullseye.java

📁 用java application 实现画牛眼问题.
💻 JAVA
字号:
import java.awt.*;
import java.awt.event.*;
public class BullsEye extends Frame
{
	int Circle=5;
	int i;
	TextField T1=new TextField(4);
	Label L1=new Label("Number of Circles:");
	public static void main(String argv[])
	{
		BullsEye BullsEyeEvent=new BullsEye();
		BullsEyeEvent.setLayout(new FlowLayout());
		BullsEyeEvent.setTitle("BullsEye");
		BullsEyeEvent.setSize(800,600);
		BullsEyeEvent.setVisible(true);
		BullsEyeEvent.setResizable(false);
	}
	public void paint(Graphics E)
	{
		E.setColor(Color.white);
		E.fillRect(0,0,800,600);
		for(i=1;i<=Math.abs(Circle);i++)
		{
			if(i%2==0)
				E.setColor(Color.red);
			else
				E.setColor(Color.black);
			E.fillOval(75+i*30,0+i*30,650-i*60,650-i*60);
			if(Circle>10)
			{
				E.setColor(Color.cyan);
				E.drawString("The number of the Circle should less than 10",275,325);
			}
			if(Circle<-10)
			{
				E.setColor(Color.cyan);
				E.drawString("The number of the Circle should bigger than -10",265,325);
			}
		}
	}
	public BullsEye()
	{
		T1.setText("5");
		L1.setBackground(Color.white);
		add(L1);
		T1.addKeyListener(new KeyLis());
		add(T1);
		addWindowListener(new WindowAdapter()
		{
			public void windowClosing(WindowEvent x)
			{
				dispose();
				System.exit(0);
			}
		});
	}
	class KeyLis extends KeyAdapter
	{
		public void keyTyped(KeyEvent L)
		{
			if(L.getKeyChar()=='\n')
			{
				Circle=Integer.parseInt(T1.getText());
				T1.setText("");
				repaint();
			}
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -