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


Java Canvas类代码示例

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


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

示例1: createFrame

import java.awt.Canvas; //导入依赖的package包/类
public static void createFrame(DefaultResourcePack mcDefaultResourcePack,
	Logger logger) throws LWJGLException
{
	// check if frame should be created
	if(!isAutoMaximize() && !WurstBot.isEnabled())
		return;
	
	// create frame
	frame = new JFrame("Minecraft " + WMinecraft.DISPLAY_VERSION);
	
	// add LWJGL
	Canvas canvas = new Canvas();
	canvas.setBackground(new Color(16, 16, 16));
	Display.setParent(canvas);
	Minecraft mc = Minecraft.getMinecraft();
	canvas.setSize(mc.displayWidth, mc.displayHeight);
	frame.add(canvas);
	
	// configure frame
	frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	frame.pack();
	frame.setLocationRelativeTo(null);
	
	// add icons
	InputStream icon16 = null;
	InputStream icon32 = null;
	try
	{
		icon16 = mcDefaultResourcePack.getInputStreamAssets(
			new ResourceLocation("icons/icon_16x16.png"));
		icon32 = mcDefaultResourcePack.getInputStreamAssets(
			new ResourceLocation("icons/icon_32x32.png"));
		ArrayList<BufferedImage> icons = new ArrayList<>();
		icons.add(ImageIO.read(icon16));
		icons.add(ImageIO.read(icon32));
		frame.setIconImages(icons);
	}catch(Exception e)
	{
		logger.error("Couldn't set icon", e);
	}finally
	{
		IOUtils.closeQuietly(icon16);
		IOUtils.closeQuietly(icon32);
	}
	
	// show frame
	if(!WurstBot.isEnabled())
		frame.setVisible(true);
}
 
开发者ID:Wurst-Imperium,项目名称:Wurst-MC-1.12,代码行数:50,代码来源:FrameHook.java

示例2: createDisplay

import java.awt.Canvas; //导入依赖的package包/类
private void createDisplay(){
	frame = new JFrame(title);
	frame.setSize(width, height);
	frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	frame.setResizable(false);
	frame.setLocationRelativeTo(null);
	frame.setVisible(true);
	
	canvas = new Canvas();
	canvas.setPreferredSize(new Dimension(width, height));
	canvas.setMaximumSize(new Dimension(width, height));
	canvas.setMinimumSize(new Dimension(width, height));
	
	frame.add(canvas);
	frame.pack();
}
 
开发者ID:squirlemaster42,项目名称:Game-Needs-A-Name,代码行数:17,代码来源:Display.java

示例3: AView

import java.awt.Canvas; //导入依赖的package包/类
/**
 * Initiates a new View instance.
 * 
 * @param title
 *            The title displayed on the frame.
 * @param width
 *            The width of the frame.
 * @param height
 *            The height of the frame.
 * @param manager
 *            The RenderManager of this View, managing render layers.
 */
public AView(String mTitle, int mWidth, int mHeight, RenderManager mManager) {
	super(0, 0, mWidth, mHeight);

	manager = mManager;
	title = mTitle;
	height = mHeight;
	width = mWidth;

	frame = new JFrame(title);
	frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	frame.setResizable(false);
	frame.setSize(width, height);
	frame.setLocationRelativeTo(null);
	frame.setVisible(false);

	canvas = new Canvas();
	canvas.setPreferredSize(new Dimension(width, height));
	canvas.setMaximumSize(new Dimension(width, height));
	canvas.setMinimumSize(new Dimension(width, height));
	canvas.setFocusable(false);
	canvas.setBounds(0, 0, width, height);

	frame.add(canvas);

}
 
开发者ID:Ativelox,项目名称:Rummy,代码行数:38,代码来源:AView.java

示例4: init

import java.awt.Canvas; //导入依赖的package包/类
@Override
public void init() {
    SwingUtilities.invokeLater(new Runnable() {

        @Override
        public void run() {

            final Image image1 = getImage(getCheckBox("Deselected", false));
            final Image image2 = getImage(getCheckBox("Selected", true));

            Canvas canvas = new Canvas() {

                @Override
                public void paint(Graphics g) {
                    super.paint(g);
                    g.drawImage(image1, 0, 0, scaledWidth, scaledHeight, this);
                    g.drawImage(image2, 0, scaledHeight + 5,
                            scaledWidth, scaledHeight, this);
                }
            };

            getContentPane().add(canvas, BorderLayout.CENTER);
        }
    });
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:26,代码来源:bug8032667.java

示例5: shouldFocusOnClick

import java.awt.Canvas; //导入依赖的package包/类
public static boolean shouldFocusOnClick(Component component) {
    boolean acceptFocusOnClick = false;

    // A component is generally allowed to accept focus on click
    // if its peer is focusable. There're some exceptions though.


    // CANVAS & SCROLLBAR accept focus on click
    final ComponentAccessor acc = AWTAccessor.getComponentAccessor();
    if (component instanceof Canvas ||
        component instanceof Scrollbar)
    {
        acceptFocusOnClick = true;

    // PANEL, empty only, accepts focus on click
    } else if (component instanceof Panel) {
        acceptFocusOnClick = (((Panel)component).getComponentCount() == 0);


    // Other components
    } else {
        ComponentPeer peer = (component != null ? acc.getPeer(component) : null);
        acceptFocusOnClick = (peer != null ? peer.isFocusable() : false);
    }
    return acceptFocusOnClick && acc.canBeFocusOwner(component);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:27,代码来源:KeyboardFocusManagerPeerImpl.java

示例6: main

import java.awt.Canvas; //导入依赖的package包/类
public static void main(final String[] args) {
	final JFrame frame = new JFrame();
	frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

	frame.setSize(WIDTH1, HEIGHT1);
	final JPanel pane = (JPanel) frame.getContentPane();
	final Canvas canvas = new Deprecated();
	frame.add(canvas);

	frame.setVisible(true);

	final InputMap iMap = pane.getInputMap();
	final ActionMap aMap = pane.getActionMap();
	iMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_R, 0), "R");
	aMap.put("R", new AbstractAction() {
		private static final long	serialVersionUID	= 3205299646057459152L;

		@Override
		public void actionPerformed(final ActionEvent arg0) {
			frame.remove(canvas);
			frame.add(canvas);
		}
	});
}
 
开发者ID:phil294,项目名称:Caterwolor,代码行数:25,代码来源:Deprecated.java

示例7: createAwtImage

import java.awt.Canvas; //导入依赖的package包/类
/**
 * Creates a <CODE>java.awt.Image</CODE>. A successful call to the method <CODE>generate()</CODE>
 * before calling this method is required.
 * @param foreground the color of the bars
 * @param background the color of the background
 * @return the image
 */    
public java.awt.Image createAwtImage(Color foreground, Color background) {
    if (image == null)
        return null;
    int f = foreground.getRGB();
    int g = background.getRGB();
    Canvas canvas = new Canvas();

    int w = width + 2 * ws;
    int h = height + 2 * ws;
    int pix[] = new int[w * h];
    int stride = (w + 7) / 8;
    int ptr = 0;
    for (int k = 0; k < h; ++k) {
        int p = k * stride;
        for (int j = 0; j < w; ++j) {
            int b = image[p + (j / 8)] & 0xff;
            b <<= j % 8;
            pix[ptr++] = (b & 0x80) == 0 ? g : f;
        }
    }
    java.awt.Image img = canvas.createImage(new MemoryImageSource(w, h, pix, 0, w));
    return img;
}
 
开发者ID:albfernandez,项目名称:itext2,代码行数:31,代码来源:BarcodeDatamatrix.java

示例8: JMEModule

import java.awt.Canvas; //导入依赖的package包/类
public JMEModule( Frame parentFrame, Function1<Frame, PhetJMEApplication> applicationFactory ) {
    super( JMECanvasFactory.createCanvas( parentFrame, applicationFactory ) );

    // gets what we created in the super-call
    canvas = (Canvas) getContent();

    // stores the created application statically, so we need to retrieve this
    app = JMEUtils.getApplication();

    addListener( new Listener() {
        public void activated() {
            app.startCanvas();
        }

        public void deactivated() {
        }
    } );

    // listen to resize events on our canvas, so that we can update our layout
    canvas.addComponentListener( new ComponentAdapter() {
        @Override public void componentResized( ComponentEvent e ) {
            app.onResize( canvas.getSize() );
        }
    } );
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:26,代码来源:JMEModule.java

示例9: init

import java.awt.Canvas; //导入依赖的package包/类
/**
 * initialise applet by adding a canvas to it, this canvas will start the LWJGL Display and game loop
 * in another thread. It will also stop the game loop and destroy the display on canvas removal when
 * applet is destroyed.
 */
public void init() {
	setLayout(new BorderLayout());
	try {
		display_parent = new Canvas() {
			public void addNotify() {
				super.addNotify();
				startLWJGL();
			}
			public void removeNotify() {
				stopLWJGL();
				super.removeNotify();
			}
		};
		display_parent.setSize(getWidth(),getHeight());
		add(display_parent);
		display_parent.setFocusable(true);
		display_parent.requestFocus();
		display_parent.setIgnoreRepaint(true);
		setVisible(true);
	} catch (Exception e) {
		System.err.println(e);
		throw new RuntimeException("Unable to create display");
	}
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:30,代码来源:GameApplet.java

示例10: privilegedLockAndInitHandle

import java.awt.Canvas; //导入依赖的package包/类
private boolean privilegedLockAndInitHandle(final Canvas component) throws LWJGLException {
	// Workaround for Sun JDK bug 4796548 which still exists in java for OS X
	// We need to elevate privileges because of an AWT bug. Please see
	// http://192.18.37.44/forums/index.php?topic=10572 for a discussion.
	// It is only needed on first call, so we avoid it on all subsequent calls
	// due to performance..
       
	if (firstLockSucceeded)
		return lockAndInitHandle(lock_buffer, component);
	else
		try {
			firstLockSucceeded = AccessController.doPrivileged(new PrivilegedExceptionAction<Boolean>() {
				public Boolean run() throws LWJGLException {
					return lockAndInitHandle(lock_buffer, component);
				}
			});
			return firstLockSucceeded;
		} catch (PrivilegedActionException e) {
			throw (LWJGLException) e.getException();
		}
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:22,代码来源:AWTSurfaceLock.java

示例11: initHandle

import java.awt.Canvas; //导入依赖的package包/类
protected void initHandle(Canvas component) throws LWJGLException {
	boolean forceCALayer = true;
	String javaVersion = System.getProperty("java.version");
	
	if (javaVersion.startsWith("1.5") || javaVersion.startsWith("1.6")) {
		// On Java 7 and newer CALayer mode is the only way to use OpenGL with AWT
		// therefore force it on all JVM's except for the older Java 5 and Java 6
		// where the older cocoaViewRef NSView method maybe be available.
		forceCALayer = false;
	}
	
	Insets insets = getInsets(component);
	
	int top = insets != null ? insets.top : 0;
	int left = insets != null ? insets.left : 0;
	
	window_handle = nInitHandle(awt_surface.lockAndGetHandle(component), getHandle(), window_handle, forceCALayer, component.getX()-left, component.getY()-top);
	
	if (javaVersion.startsWith("1.7")) {
		// fix for CALayer position not covering Canvas due to a Java 7 bug
		// http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7172187
		addComponentListener(component);
	}
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:25,代码来源:MacOSXCanvasPeerInfo.java

示例12: init

import java.awt.Canvas; //导入依赖的package包/类
/**
 * initialise applet by adding a canvas to it, this canvas will start the LWJGL Display and game loop
 * in another thread. It will also stop the game loop and destroy the display on canvas removal when
 * applet is destroyed.
 */
public void init() {
	setLayout(new BorderLayout());
	try {
		display_parent = new Canvas() {
			public void addNotify() {
				super.addNotify();
				startLWJGL();
			}
			public void removeNotify() {
				stopLWJGL();
				super.removeNotify();
			}
		};
		display_parent.setSize(getWidth(),getHeight());
		add(display_parent);
		display_parent.setFocusable(true);
		display_parent.requestFocus();
		display_parent.setIgnoreRepaint(true);
		//setResizable(true);
		setVisible(true);
	} catch (Exception e) {
		System.err.println(e);
		throw new RuntimeException("Unable to create display");
	}
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:31,代码来源:GearsApplet.java

示例13: createCanvas

import java.awt.Canvas; //导入依赖的package包/类
public Canvas createCanvas() {
    String appClass = TestEditor.class.getName();
    AppSettings settings = new AppSettings(true);
    settings.setWidth(640);
    settings.setHeight(480);
    settings.setFrameRate(30);

    try {
        Class<? extends LegacyApplication> clazz = (Class<? extends LegacyApplication>) Class.forName(appClass);
        app = clazz.newInstance();
        app.setPauseOnLostFocus(false);
        app.setSettings(settings);
        app.createCanvas();
        app.startCanvas();

        JmeCanvasContext context = (JmeCanvasContext) app.getContext();
        Canvas canvas = context.getCanvas();
        canvas.setSize(settings.getWidth(), settings.getHeight());

        return canvas;
    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException ex) {
        ex.printStackTrace();
    }
    return null;
}
 
开发者ID:huliqing,项目名称:LuoYing,代码行数:26,代码来源:TestSwing2.java

示例14: createCanvas

import java.awt.Canvas; //导入依赖的package包/类
public static Canvas createCanvas() {
    String appClass = TestEditor.class.getName();
    AppSettings settings = new AppSettings(true);
    settings.setWidth(640);
    settings.setHeight(480);
    settings.setFrameRate(60);

    try {
        Class<? extends LegacyApplication> clazz = (Class<? extends LegacyApplication>) Class.forName(appClass);
        LegacyApplication app = clazz.newInstance();
        app.setPauseOnLostFocus(false);
        app.setSettings(settings);
        app.createCanvas();
        app.startCanvas();

        JmeCanvasContext context = (JmeCanvasContext) app.getContext();
        Canvas canvas = context.getCanvas();
        canvas.setSize(settings.getWidth(), settings.getHeight());

        return canvas;
    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException ex) {
        ex.printStackTrace();
    }
    
    return null;
}
 
开发者ID:huliqing,项目名称:LuoYing,代码行数:27,代码来源:SwingUtils.java

示例15: show

import java.awt.Canvas; //导入依赖的package包/类
public static void show(int width, int height) {
    frame = new JFrame();
    frame.setTitle("Raycasting test #3 - ceil and floor");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(width, height);
    frame.setLocationRelativeTo(null);
    frame.add(canvas = new Canvas());
    frame.setVisible(true);
    
    canvas.requestFocus();
    canvas.addKeyListener(new KeyHandler());
    canvas.createBufferStrategy(2);
    canvasBufferStrategy = canvas.getBufferStrategy();
    
    init();
    
    new Thread(new MainLoop()).start();
}
 
开发者ID:Redbricksnake,项目名称:hi,代码行数:19,代码来源:Game.java


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