bullseye.java

来自「用java application 实现画牛眼问题.」· Java 代码 · 共 69 行

JAVA
69
字号
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 + =
减小字号Ctrl + -
显示快捷键?