3 import static java
.lang
.Math
.*;
4 import java
.util
.logging
.Level
;
5 import java
.util
.logging
.Logger
;
10 * This example shows how to create GUI application which can be run both
11 * as HTML embeded web applet and as standalone application
14 class AppGui
extends JPanel
implements Runnable
{
21 public void paint(Graphics g
) {
23 Graphics2D g2D = (Graphics2D) g; // cast to 2D
24 g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
25 RenderingHints.VALUE_ANTIALIAS_ON);
28 g
.setColor(Color
.BLACK
);
29 g
.fillRect(0, 0, getWidth(), getHeight());
30 g
.setColor(Color
.GREEN
);
31 //g.setXORMode(Color.GREEN);
33 int mid
= round(getHeight()/2);
35 for(int x
= 0;x
<=getWidth();x
++) {
36 y1
=(int)round(mid
+mid
*sin((double)(x
+offA
)/freqA
));
37 y2
=(int)round(mid
+mid
*sin((double)(x
+offB
)/freqB
));
38 g
.drawLine(x
,y1
,x
,y2
);
44 synchronized public void run() {
45 System
.out
.println("FPS::: "+fps
);
48 Thread
.sleep(round(1000 / fps
));
49 } catch (InterruptedException ex
) {
50 Logger
.getLogger(AppGui
.class.getName()).log(Level
.SEVERE
, null, ex
);
52 offA
+= round(speedA
/fps
);
53 offB
+= round(speedB
/fps
);
62 this.setDoubleBuffered(true);
73 this(new Integer(fps
)!=null?
(int)new Integer(fps
):20);
74 System
.out
.println("Setting FPS from string: "+fps
);
77 synchronized public void start() throws InterruptedException
{
81 public void stop() throws InterruptedException
{
85 public void destroy() {
86 this.setVisible(false);
92 public class SinusDiff
extends JApplet
{
94 static AppGui appGui
= null;
98 appGui
= new AppGui(getParameter("fps"));
99 getContentPane().add(appGui
);
102 public static void main(String
[] args
) {
103 JFrame f
= new JFrame("Applet window");
104 f
.setDefaultCloseOperation(javax
.swing
.WindowConstants
.EXIT_ON_CLOSE
);
106 appGui
= new AppGui(args
.length
> 0?args
[0]:"20");
107 f
.getContentPane().add(appGui
);
111 // TODO overwrite start(), stop() and destroy() methods
113 public void start() {
116 } catch (InterruptedException ex
) {
117 Logger
.getLogger(SinusDiff
.class.getName()).log(Level
.SEVERE
, null, ex
);
125 } catch (InterruptedException ex
) {
126 Logger
.getLogger(SinusDiff
.class.getName()).log(Level
.SEVERE
, null, ex
);
131 public void destroy() {
This page took 0.301755 seconds and 4 git commands to generate.