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

📄 exam_2.java

📁 基本的JAva代码
💻 JAVA
字号:
/*
 * @(#)Exam_bookApplet.java 1.0 07/12/07
 *
 * You can modify the template of this file in the
 * directory ..\JCreator\Templates\Template_2\Project_Name.java
 *
 * You can also create your own project template by making a new
 * folder in the directory ..\JCreator\Template\. Use the other
 * templates as examples.
 *
 */
import java.awt.event.*;
import java.awt.*;
import java.applet.*;

class MyLabel extends Label implements ActionListener
{
	String lab;
	TextField inputNumber;
	TextArea showResult;
	Button button;
	MyLabel(String s,Container con)
	{
		super(s);
		lab=s;
		inputNumber=new TextField(10);
		showResult=new TextArea(10,10);
		button=new Button("确定");
		button.addActionListener(this);
		con.add(this);
		con.add(inputNumber);
		con.add(showResult);
		con.add(button);
	}
	public void actionPerfored(ActionEvent e)
	{
		long n=0;
		showResult.setText(null);
		try{
			n=Long.valueOf(inputNumber.getText()).longValue();
			this.setText(lab);
		}
		catch(NumberFormatException e1)
		{
			showResult.setText("请输入整数!");
			return;
		}
		if(e1.getObject()==button)
		{
			sushu(n);
		}
	}
	public void sushu(long n)
	{
		showResult.append("小于"+n+"的素数有:");
		for(int i=1;i<=n;i++)
		{
			int j=0;
			for(j=2;j<i;j++)
			{
				if(i%j==0) break;
			}
			if(j>=i)
			{
				showResult.append("\n"+i);
			}
		}
	}
}
public class exam_2 extends Applet
{
	MyLabel lab;
	public void init()
	{
		lab=new MyLabel("点击\"确定\"按钮计算素数",this);
	}
}
public class Exam_bookApplet extends Applet {
	
	public void init() {
	}

	public void paint(Graphics g) {
		g.drawString("Welcome to Java!!", 50, 60 );
	}
}

⌨️ 快捷键说明

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