當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。