/********************************************************
2.编写一个小应用程序求100以内的全部素数.
*********************************************************/
import java.awt.*;
import javax.swing.JApplet;
public class exercise2_1 extends JApplet
{
private static final long serialVersionUID=1L;
public void paint(Graphics g)
{
String str1="", str2="", str3="", str4="";
super.paint( g );
g.drawLine( 15, 30, 180, 30 );
g.drawLine( 15, 30, 15, 150 );
g.drawLine( 180, 30, 180, 150 );
g.drawLine( 15, 150, 180, 150 );
g.drawString( "The primes between 1 and 100 are:", 5, 20 );
g.drawString( getprime(2,25,str1), 20, 50 );
g.drawString( getprime(26,50,str2), 20, 80 );
g.drawString( getprime(51,75,str3), 20, 110 );
g.drawString( getprime(76,100,str4), 20, 140 );
}
public String getprime(int m, int n, String str)
{
int i,j;
str="";
for(i=m;i<=n;i++)
{
boolean is_prime=true;
int sqr=(int)Math.sqrt((double)i);
for(j=2;j<=sqr;j++)
{
if (i%j==0)
{
is_prime=false;
continue;
}
}
if(is_prime)
{
str+=" "+i;
}
}
return str;
}
}
执行之后总出这个:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException: component argument pData
at sun.awt.windows.Win32SurfaceData.initOps(Native Method)
at sun.awt.windows.Win32SurfaceData.<init>(Unknown Source)
at sun.awt.windows.Win32SurfaceData.createData(Unknown Source)
at sun.awt.Win32GraphicsConfig.createSurfaceData(Unknown Source)
at sun.awt.windows.WComponentPeer.replaceSurfaceData(Unknown Source)
at sun.awt.windows.WComponentPeer.replaceSurfaceData(Unknown Source)
at sun.awt.windows.WComponentPeer$2.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
请问有人知道是什么意思吗?
嵌入网页 浏览器状态栏也显示有错