aboutsummaryrefslogtreecommitdiffstats
path: root/demos/SwingDemos/test/GLPanel-AWTGraphics/test1.java
blob: b9786a0236bcad84ad58c52629c5d2386529beec (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
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.Dimension;
import javax.swing.*;
import gl4java.*;
import gl4java.awt.*;
import gl4java.swing.*;
import gl4java.utils.glut.*;
import gl4java.utils.glut.fonts.*;

public class test1 extends JApplet 
  implements GLEnum, GLUEnum
{
    static {
            if(GLContext.loadNativeLibraries(null, null, null)==false)
	      System.out.println("GLCanvas could not load def. native libs.");
    } 
    
    protected class test1Panel extends GLPanel 
	  implements ActionListener, ItemListener
    {
	public test1Panel() {
	    super();
	    GLContext.gljNativeDebug = true;
	    GLContext.gljClassDebug  = true;
	    //String[] data = {"one", "two", "three", "four"};
	    //JList dataList = new JList(data);
	    //add("North", dataList);
	    JButton b1, b2;
	    add("East", (b1 = new JButton("E")));
	    b1.setActionCommand("east");
	    b1.addActionListener(this);
	    add("West", (b2 = new JButton("W")));
	    b2.setActionCommand("west");
	    b2.addActionListener(this);

	    JCheckBox c1;
	    add("South", (c1 = new JCheckBox("SouthButton", true)));
	    c1.addItemListener(this);
	}


	public void init() {
	    System.out.println("<i>");
	    //glg = new GLGraphics(gl, glu);
	    reshape(getSize().width, getSize().height);
	}

	public void display() 
	{
	    if( glj.gljMakeCurrent() == false ) {
		System.out.println("problem in use() method");
		return;
	    }
	  
	    System.out.println("<p>");

	    int i;

	    gl.glPushMatrix();
	    gl.glClear(GL_COLOR_BUFFER_BIT);

	    gl.glColor4f(0f, 0f, 1f, 1f);

	    int width=getSize().width;
	    int height=getSize().height;

	    gl.glBegin(GLEnum.GL_LINES);
                gl.glVertex3i( 0, 0, 0);
                gl.glVertex3i( 10, 10, 0);
                gl.glVertex3i( 0, 10, 0);
		gl.glVertex3i( 10, 0, 0);
            gl.glEnd();

	    gl.glPopMatrix();

	    glj.gljSwap();
	    glj.gljCheckGL();
	    glj.gljFree();
	}

        public void reshape( int width, int height )
        {
	  System.out.println("reshape("+width+", "+height+")");
	  System.out.println("reshape bounds("+getBounds()+")");
		gl.glViewport(0,0, width, height);
		gl.glMatrixMode(GL_PROJECTION);
		gl.glLoadIdentity();
		gl.glOrtho(0, 10, 0, 10, -50.0,50.0);
		gl.glMatrixMode(GL_MODELVIEW);
        }    

	public void actionPerformed(ActionEvent e) {
		if (e.getActionCommand().equals("east")) {
			System.out.println("East pressed");
		} else if (e.getActionCommand().equals("west")) {
			System.out.println("West pressed");
		}
        }

	public void itemStateChanged(ItemEvent e) {
		Object source = e.getItemSelectable();
		System.out.println("item changed: "+source);
	}

    }

    test1Panel tst1cvs1;    

    public void init()
    {
		tst1cvs1 = new test1Panel();
		tst1cvs1.setSize(400,400);
		setContentPane(tst1cvs1);
    }

    public static void main(java.lang.String[] args) {
	try {
		Frame mainFrame = new Frame("test1");

	        test1 applet=new test1();

		applet.setSize(400, 400);
		applet.init();
		applet.start();

		mainFrame.add(applet);

		mainFrame.pack();
		mainFrame.setVisible(true);
	} catch (Throwable exception) {
	    	System.err.println("Exception occurred in main()");
	    	exception.printStackTrace(System.out);
	}
    }
}