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

📄 e5_7.java

📁 java 初学者学习实例
💻 JAVA
字号:
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
class MyLabel extends Label implements ActionListener
{
	TextField text1;TextArea text2;int k = 0;
	MyLabel (String s)
	{
		super(s);
		text1 = new TextField(10);
		text2 = new TextArea(10,10);
	 	text1.addActionListener(this);
	}

	public void actionPerformed(ActionEvent e)
	{
		double n = 0;
		text2.setText(null);
		try{
			n = Double.valueOf(text1.getText()).doubleValue();
			for(int i = 1;i<=n;i++)
			{
				if(n%i == 0)
				    text2.append("\n"+i);
			}
		}
		catch(NumberFormatException e1)
		{
			text1.setText("请输入字符");
		}
		if (n%2==0)
		{
			 this.setBackground(Color.green);
		}
		else
		{
			 this.setBackground(Color.yellow);
		}
		
	}
}
public class E5_7 extends Applet
{
	MyLabel lab;
	 public void init()
	{  
		lab = new MyLabel("请输入一个整数后回车");
		add(lab);add(lab.text1);add(lab.text2);
	}
}

⌨️ 快捷键说明

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