aboutsummaryrefslogtreecommitdiffstats
path: root/gl4java/applet/SimpleGLApplet1.java
blob: 8da7104854a545097a893755cec2aef43471852c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/**
 * @(#) SimpleGLApplet.java
 * @(#) author: Sven Goethel
 */

package gl4java.applet;

/* This program is licensed under the LGPL */

import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.lang.*;
import gl4java.GLContext;
import gl4java.GLFunc;
import gl4java.GLUFunc;
import gl4java.awt.GLCanvas;

public class SimpleGLApplet1 extends Applet 
  implements ActionListener,WindowListener
{
    public GLCanvas canvas = null;

    public Button buttonInfo = null;

    Frame fInfo = null;

   /* Initialize the applet */

    public void init()
    {
        setLayout(new BorderLayout());

	buttonInfo = new Button("GL4Java");
	add("South",buttonInfo);
    }


    public void start()
    {
	if(GLContext.gljClassDebug)
		System.out.println("SGLApplet start ..");

	buttonInfo.addActionListener(this);

	canvas.setVisible(true);
	canvas.repaint();
    }


    public void stop()
    {
	if(GLContext.gljClassDebug)
		System.out.println("SGLApplet stop ..");
	buttonInfo.removeActionListener(this);

        canvas.cvsDispose();
    }


    public void destroy()
    {
	if(GLContext.gljClassDebug)
		System.out.println("SGLApplet destroy ..");
	if(fInfo!=null)
	{
		fInfo.dispose();
		fInfo=null;
	}
        canvas.cvsDispose();
    }


    protected void finalize()
    	throws Throwable
    {
	if(GLContext.gljClassDebug)
		System.out.println("SGLApplet finalize ..");
	  
	super.finalize();
    }

    public void actionPerformed(ActionEvent event) 
    {
	    Object source = event.getSource();

	if( source.equals(buttonInfo) )
	{
	  if(fInfo==null && canvas!=null && canvas.getGLContext()!=null)
	     fInfo = showGLInfo();
	}
    }

	public void windowOpened(WindowEvent e)
	{
	}

	public void windowClosing(WindowEvent e)
	{
		Window w = e.getWindow();
		if(w == fInfo && fInfo!=null)
		{
			fInfo.dispose();
			fInfo=null;
		}
	}

	public void windowClosed(WindowEvent e)
	{
		Window w = e.getWindow();
		if(w == fInfo && fInfo!=null)
		{
			fInfo.dispose();
			fInfo=null;
		}
	}

	public void windowIconified(WindowEvent e)
	{
	}

	public void windowDeiconified(WindowEvent e)
	{
	}

	public void windowActivated(WindowEvent e)
	{
	}

	public void windowDeactivated(WindowEvent e)
	{
	}

	public Frame showGLInfo()
	{
		if(canvas==null) return null;

		GLContext glc =  canvas.getGLContext();
		if(glc==null) return null;

		GLFunc    gl  =  glc.getGLFunc();
		if(gl==null) return null;

		GLUFunc   glu =  glc.getGLUFunc();
		if(gl==null) return null;

		Frame f = new Frame("GL4Java Version");
		TextArea info= new TextArea(25, 80);
		info.setEditable(false);
		f.add(info);
		f.setSize(600, 400);

		String str = "null string";
		if( glc.gljMakeCurrent() == false ) 
		{
			str="problem in use() method\n";
		} else {
			str=canvas.getGLContext().gljGetVersions();
			if(str==null)
				str="could not get versions";
			System.out.println(str);
			glc.gljFree();
		}
		info.append(str);

		f.addWindowListener(this);

		f.pack();
		f.setVisible(true);

		return f;
	}
}