002
16.04.2006, 22:40 Uhr
FloSoft
Medialer Over-Flow (Administrator)
|
Hi, hier mal ne Anwendung die beides ist, Applet & normale Anwendung:
C++: |
import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*;
public class Circles extends JApplet { private static class CirclesPanel extends JPanel { public CirclesPanel(int nC) { numCircles = nC; }
private void kreis(Graphics g, int x, int y, int w, int n) { // System.out.println(x+ " " + y + " " + w + " " + n); g.setColor(Color.red); g.fillOval(x,y,w*2,w*2); g.setColor(Color.black); g.drawOval(x,y,w*2,w*2);
g.setColor(Color.black);
Font f = new Font("Helvetica",0,12);
g.setFont(f); FontMetrics fm = getFontMetrics(f);
String s = new String(Integer.toString(n+1)); g.drawString(s,x+w - fm.stringWidth(s)/2, y+w + fm.getAscent()/2 - fm.getDescent()/2); }
public void paint(Graphics g) { g.setColor(Color.green); g.fillRect(0,0,getWidth(),getHeight());
for(int i = 0; i < numCircles; ++i) { int x = (int)(Math.random()*(getWidth()+1)); int y = (int)(Math.random()*(getHeight()+1)); int w = (int)(1+Math.random()*(getWidth()/10-1));
kreis(g, x-w, y-w, w, i); } }
private int numCircles; }
public void init() { try { javax.swing.SwingUtilities.invokeAndWait(new Runnable() { public void run() { String s = getParameter("CIRCLES"); Integer nC; try { nC = new Integer(s); } catch(Exception e) { System.out.println("Exception abgefangen, evtl falschen Parameter angeben???"); return; }
CirclesPanel cp = new CirclesPanel(nC); getContentPane().add(cp); } }); } catch (Exception e) { System.err.println("init() ist fehlgeschlagen"); } }
public static void main(String[] args) { Integer nC;
try { nC = new Integer(args[0]); } catch(Exception e) { System.out.println("Exception abgefangen, evtl falschen Parameter angeben???"); return; }
JFrame f = new JFrame("Circles"); CirclesPanel cp = new CirclesPanel(nC);
f.getContentPane().add(cp);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setSize(500,500); f.setVisible(true); } }
|
-- class God : public ChuckNorris { }; |