当前位置: 首页>>代码示例>>Java>>正文


Java Canvas.getHeight方法代码示例

本文整理汇总了Java中java.awt.Canvas.getHeight方法的典型用法代码示例。如果您正苦于以下问题:Java Canvas.getHeight方法的具体用法?Java Canvas.getHeight怎么用?Java Canvas.getHeight使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.awt.Canvas的用法示例。


在下文中一共展示了Canvas.getHeight方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: DisplayParentTest

import java.awt.Canvas; //导入方法依赖的package包/类
public DisplayParentTest() throws LWJGLException {
    setTitle( "LWJGL Display Parent Test" );
    setSize( 640, 320 );
    setLayout( new GridLayout( 1, 2 ) );
    final Canvas display_parent = new Canvas();
    final Canvas display_parent_2 = new Canvas();
    display_parent.setFocusable( true );
    display_parent.setIgnoreRepaint( true );
    add( display_parent );
    display_parent_2.setFocusable( true );
    display_parent_2.setIgnoreRepaint( true );
    add( display_parent_2 );
    addWindowListener( new WindowAdapter() {
        public void windowClosing( WindowEvent e ) {
            killswitch = true;
        }
    } );
    setResizable( true );
    setVisible( true );
    Display.setParent( display_parent );
    Display.setVSyncEnabled( true );
    Display.create();
    float angle = 0f;
    while ( isVisible() && !killswitch ) {
        angle += 1.0f;
        int width;
        int height;
        if ( !Display.isFullscreen() ) {
            width = display_parent.getWidth();
            height = display_parent.getHeight();
        }
        else {
            width = Display.getDisplayMode().getWidth();
            height = Display.getDisplayMode().getHeight();
        }
        if ( width < 1 || height < 1 ) {
            continue;
        }
        glViewport( 0, 0, width, height );
        glClearColor( 0.0f, 1.0f, 0.0f, 1.0f );
        glClear( GL_COLOR_BUFFER_BIT );
        glMatrixMode( GL_PROJECTION );
        glLoadIdentity();
        gluOrtho2D( 0.0f, (float) width, 0.0f, (float) height );
        glMatrixMode( GL_MODELVIEW );
        glPushMatrix();
        glTranslatef( width / 2.0f, height / 2.0f, 0.0f );
        glRotatef( 2 * angle, 0f, 0f, -1.0f );
        glRectf( -50.0f, -50.0f, 50.0f, 50.0f );
        glPopMatrix();
        Display.update();
        while ( Keyboard.next() ) {
            // closing on ESCAPE
            if ( Keyboard.getEventKey() == Keyboard.KEY_ESCAPE && Keyboard.getEventKeyState() ) {
                Display.destroy();
                dispose();
                break;
            }
            if ( Keyboard.getEventKey() == Keyboard.KEY_SPACE && Keyboard.getEventKeyState() ) {
                Mouse.setGrabbed( !Mouse.isGrabbed() );
            }
            if ( Keyboard.getEventKey() == Keyboard.KEY_F && Keyboard.getEventKeyState() ) {
                Display.setFullscreen( !Display.isFullscreen() );
            }
            if ( Keyboard.getEventKey() == Keyboard.KEY_4 && Keyboard.getEventKeyState() ) {
                if ( Display.getParent() == display_parent ) {
                    Display.setParent( display_parent_2 );
                }
                else {
                    Display.setParent( display_parent );
                }
            }
        }
        while ( Mouse.next() ) {
            System.out.println( "Mouse.getEventX() = " + Mouse.getEventX() + " | Mouse.getEventY() = " + Mouse.getEventY() );
        }
    }
    Display.destroy();
    dispose();
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:81,代码来源:DisplayParentTest.java

示例2: DisplayParentTest

import java.awt.Canvas; //导入方法依赖的package包/类
public DisplayParentTest() throws LWJGLException {
		setTitle("LWJGL Display Parent Test");
		setSize(640, 320);
		setLayout(new GridLayout(1, 2));
		final Canvas display_parent = new Canvas();
		display_parent.setFocusable(true);
		display_parent.setIgnoreRepaint(true);
		add(display_parent);
		addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent e) {
				killswitch = true;
			}
		});
		setResizable(true);
		setVisible(true);
		Display.setParent(display_parent);
		Display.setVSyncEnabled(true);
		Display.create();
		float angle = 0f;

		while (isVisible() && !killswitch) {
			angle += 1.0f;
			int width;
			int height;
			if (!Display.isFullscreen()) {
				width = display_parent.getWidth();
				height = display_parent.getHeight();
			} else {
				width = Display.getDisplayMode().getWidth();
				height = Display.getDisplayMode().getHeight();
			}

			if(width < 1 || height < 1) {
				continue;
			}

			glViewport(0, 0, width, height);
			glClearColor(0.0f, 1.0f, 0.0f, 1.0f);
			glClear(GL_COLOR_BUFFER_BIT);
			glMatrixMode(GL_PROJECTION);
			glLoadIdentity();
			gluOrtho2D(0.0f, (float) width, 0.0f, (float) height);
			glMatrixMode(GL_MODELVIEW);
			glPushMatrix();
			glTranslatef(width / 2.0f, height / 2.0f, 0.0f);
			glRotatef(2*angle, 0f, 0f, -1.0f);
			glRectf(-50.0f, -50.0f, 50.0f, 50.0f);
			glPopMatrix();
			Display.update();
			while(Keyboard.next()) {
				// closing on ESCAPE
				if(Keyboard.getEventKey() == Keyboard.KEY_ESCAPE && Keyboard.getEventKeyState()) {
					Display.destroy();
					dispose();
					break;
				}

				if(Keyboard.getEventKey() == Keyboard.KEY_SPACE && Keyboard.getEventKeyState()) {
					Mouse.setGrabbed(!Mouse.isGrabbed());
				}
				if(Keyboard.getEventKey() == Keyboard.KEY_F && Keyboard.getEventKeyState()) {
					Display.setFullscreen(!Display.isFullscreen());
				}
			}
/*			while (Mouse.next()) {
System.out.println("				Mouse.getEventX() = " + 				Mouse.getEventX() + " | Mouse.getEventY() = " + Mouse.getEventY());
			}*/
		}
		Display.destroy();
		dispose();
	}
 
开发者ID:mleoking,项目名称:PhET,代码行数:72,代码来源:DisplayParentTest.java

示例3: LwjglGraphics

import java.awt.Canvas; //导入方法依赖的package包/类
LwjglGraphics (Canvas canvas) {
	this.config = new LwjglApplicationConfiguration();
	config.width = canvas.getWidth();
	config.height = canvas.getHeight();
	this.canvas = canvas;
}
 
开发者ID:Osaris31,项目名称:exterminate,代码行数:7,代码来源:LwjglGraphics.java


注:本文中的java.awt.Canvas.getHeight方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。