当前位置: 技术问答>java相关
请问JCreator里不能直接运行Applet程序吗?一定要用appletviewer或者浏览器啊?麻烦死了
来源: 互联网 发布时间:2015-03-10
本文导语: | 这回可以了,applet属于panel,不能独立运行 import java.applet.Applet; import java.awt.*; import java.aet.event.*; public class SimplePaint extends Applet { public static void main(String[] args) { Frame f = new Frame(); Simp...
|
这回可以了,applet属于panel,不能独立运行
import java.applet.Applet;
import java.awt.*;
import java.aet.event.*;
public class SimplePaint extends Applet
{
public static void main(String[] args)
{
Frame f = new Frame();
SimplePaint sp=new SimplePaint();
f.add(sp);
f.setSize(300,300);
f.setVisible(true);
f.addWindowListener(new WindowAdapter()
{public void windowclosing(WindowEvent e)
{System.exit(0);}
});
}
public void paint(Graphics g)
{
g.setColor(Color.black);
g.fillRect(0, 0, 300, 300);
g.setColor(Color.white);
g.fillOval(30, 30, 50, 50);
}
}
import java.applet.Applet;
import java.awt.*;
import java.aet.event.*;
public class SimplePaint extends Applet
{
public static void main(String[] args)
{
Frame f = new Frame();
SimplePaint sp=new SimplePaint();
f.add(sp);
f.setSize(300,300);
f.setVisible(true);
f.addWindowListener(new WindowAdapter()
{public void windowclosing(WindowEvent e)
{System.exit(0);}
});
}
public void paint(Graphics g)
{
g.setColor(Color.black);
g.fillRect(0, 0, 300, 300);
g.setColor(Color.white);
g.fillOval(30, 30, 50, 50);
}
}