java编程100例
源代码在线查看: ells.java~39~
package dot; import java.awt.*; import java.awt.event.*; import java.applet.*; public class ells extends Applet { int x,y; int i,j,k; Color mycolor; boolean isStandalone = false; /**Get a parameter value*/ public String getParameter(String key, String def) { return isStandalone ? System.getProperty(key, def) : (getParameter(key) != null ? getParameter(key) : def); } public void init() { try { jbInit(); } catch(Exception e) { e.printStackTrace(); } } /**Construct the applet*/ public ells() { } /**Initialize the applet*/ /**Component initialization*/ private void jbInit() throws Exception { this.setBackground(SystemColor.window); this.setForeground(Color.orange); this.addMouseListener(new java.awt.event.MouseAdapter() { public void mousePressed(MouseEvent e) { this_mousePressed(e); } }); } /**Get Applet information*/ public String getAppletInfo() { return "Applet Information"; } /**Get parameter info*/ public String[][] getParameterInfo() { return null; } void this_mousePressed(MouseEvent e) { x=e.getX(); y=e.getY(); repaint(); } public void paint(Graphics g){ if(x>255) i=x-255; else i=x; if(y>255) j=y-255; else j=y; if(i+j>255) k=i+j-255; else k=i+j; mycolor=new Color(i,j,k); g.setColor(mycolor); g.fillOval(x-10,y-10,20,20); } }