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


Java Canvas.setBackground方法代码示例

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


在下文中一共展示了Canvas.setBackground方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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()
{
	//Creates JFrame with constructor data
	frame = new JFrame(title);
	frame.setSize(width, height);
	frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	frame.setResizable(false);
	frame.setLocationRelativeTo(null);
	frame.setVisible(true);
	
	//Creates a Canvas to draw the game on
	canvas = new Canvas();
	canvas.setBackground(Color.BLACK);
	canvas.setPreferredSize(new Dimension(width, height));
	canvas.setMaximumSize(new Dimension(width, height));
	canvas.setMinimumSize(new Dimension(width, height));
	canvas.setFocusable(false);
	
	//Adds canvas to JFram
	frame.add(canvas);
	frame.pack();
}
 
开发者ID:DasAvh,项目名称:APCS_3rd_Hour_2015,代码行数:23,代码来源:Display.java

示例3: main

import java.awt.Canvas; //导入方法依赖的package包/类
public static void main(String[] args) {
    JFrame frame = new JFrame("Mickey Mouse");
    Canvas canvas = new Mickey();
    canvas.setSize(400, 400);
    canvas.setBackground(Color.white);
    frame.add(canvas);
    frame.pack();
    frame.setVisible(true);
}
 
开发者ID:AllenDowney,项目名称:ThinkJavaCode,代码行数:10,代码来源:Mickey.java

示例4: main

import java.awt.Canvas; //导入方法依赖的package包/类
public static void main(String[] args) {
    JFrame frame = new JFrame("Moire Pattern");
    Canvas canvas = new Moire();
    canvas.setSize(400, 400);
    canvas.setBackground(Color.white);
    frame.add(canvas);
    frame.pack();
    frame.setVisible(true);
}
 
开发者ID:AllenDowney,项目名称:ThinkJavaCode,代码行数:10,代码来源:Moire.java

示例5: Java2DFrame

import java.awt.Canvas; //导入方法依赖的package包/类
public Java2DFrame(Spark game)
{
	super(GraphicsEnvironment.getLocalGraphicsEnvironment()
			.getDefaultScreenDevice().getDefaultConfiguration());

	this.game = game;

	ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
	gd = ge.getDefaultScreenDevice();
	gc = gd.getDefaultConfiguration();

	setTitle("Spark");

	setFocusable(false);
	setBackground(Color.black);
	setFocusTraversalKeysEnabled(false);
	setResizable(false);
	setIgnoreRepaint(true);

	if (game.gameOptions.displayWindowed == false)
		setUndecorated(true);

	setIconImage(new ImageIcon("spark/images/imgIcon.gif").getImage());

	// Invisible cursor
	int[] pixels = new int[16 * 16];
	Image image = Toolkit.getDefaultToolkit().createImage(
			new MemoryImageSource(16, 16, pixels, 0, 16));
	Cursor transparentCursor = Toolkit.getDefaultToolkit()
			.createCustomCursor(image, new Point(0, 0), "invisibleCursor");

	setCursor(transparentCursor);

	drawCanvas = new Canvas(gc);
	drawCanvas.setPreferredSize(new Dimension(game.ResolutionX,
			game.ResolutionY));
	drawCanvas.setBackground(Color.black);
	drawCanvas.setIgnoreRepaint(true);
	drawCanvas.setFocusTraversalKeysEnabled(false);
	drawCanvas.addKeyListener(this);
	drawCanvas.addMouseListener(this);
	drawCanvas.addMouseWheelListener(this);
	drawCanvas.setCursor(transparentCursor);
	add(drawCanvas);

	addWindowListener(this);

	pack();
	setLocationRelativeTo(null);

	if (game.gameOptions.displayWindowed == false)
	{
		setFullScreen();
	}

	setVisible(true);

	drawCanvas.requestFocus();
}
 
开发者ID:TheRemote,项目名称:Spark,代码行数:60,代码来源:Java2DFrame.java

示例6: EpisodePanel

import java.awt.Canvas; //导入方法依赖的package包/类
public EpisodePanel(Frame owner){
	
	this.owner = owner;
	
	this.setLayout(new BorderLayout());
	
	Canvas canvas = new Canvas();
       canvas.setBackground(Color.black);
	
	this.add(canvas, BorderLayout.CENTER);
	
	player.setVideoSurface(new MediaPlayerFactory().newVideoSurface(canvas));
	player.mute(true);
	player.addMediaPlayerEventListener(new MediaPauserEventListener());
	
	this.add(Box.createRigidArea(new Dimension(120, 140)), BorderLayout.SOUTH);
	
}
 
开发者ID:redSpoutnik,项目名称:AutoRename,代码行数:19,代码来源:EpisodePanel.java

示例7: buildPanelFromManager

import java.awt.Canvas; //导入方法依赖的package包/类
@Override
public void buildPanelFromManager(EpisodeManager m) {
	// TODO Auto-generated method stub
	
	if(m != null && m.getObservedFile().exists()){
		
		if(player.isPlaying()){
			player.stop();
		}
	}
		
		Canvas canvas = new Canvas();
        canvas.setBackground(Color.black);
		
		this.add(canvas, BorderLayout.CENTER);
		
		player.setVideoSurface(THE_FACTORY.newVideoSurface(canvas));
		
	if(m != null && m.getObservedFile().exists()){
		
		JPanel pane = new JPanel();
		pane.setLayout(new BorderLayout());
		
		pane.add(new JTextArea(
				" ID: " + m.episode + "\n" +
				" NAME: " + m.getObservedFile().getName() + "\n" +
				" LAST MODIFIED :" + new Date(m.getObservedFile().lastModified()) + "\n\n"
				), BorderLayout.CENTER);
		
		JButton seeEpisode = new JButton("See Episode");
		seeEpisode.addActionListener((event) ->{
			SwingUtilities.invokeLater(()->{
				try {
					VideoUtil.launchVLC(this.manager.getObservedFile());
					((AutoRenameFrame)owner).seasonPanel.manager.incrementNext();
					((AutoRenameFrame)owner).seasonPanel
					.setManager(((AutoRenameFrame)owner).seasonPanel.manager);
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
					new Catcher(e);
				}
			});
		});
		pane.add(seeEpisode, BorderLayout.SOUTH);
		this.add(pane, BorderLayout.SOUTH);
		
		player.playMedia(m.getObservedFile().getAbsolutePath());
		player.setPosition(0.05F);
		
	}else{
		this.add(Box.createRigidArea(new Dimension(120, 140)), BorderLayout.SOUTH);
	}
	
}
 
开发者ID:redSpoutnik,项目名称:AutoRename,代码行数:56,代码来源:EpisodePanel.java

示例8: initialize

import java.awt.Canvas; //导入方法依赖的package包/类
/**
 * Initialize the contents of the frame.
 */	
@SuppressWarnings({ "unchecked", "rawtypes" })
private void initialize() {
	
	frame = new JFrame("Sensor Display");
	
	frame.setBounds(200, 200, 650, 650);
	frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	frame.getContentPane().setLayout(null);
	
	//List Model 
	ListModel model = new DefaultListModel();

	
	//Hashtable in order to store item objects and their name

	//Jlabel to say if an item has been sent

	
	//Selection lister to enable or disable the Jlabel according to the value of item flag
	
	
	JLabel lblNew = new JLabel("Sensors");
	//lblNew.setMaximumSize(new Dimension(10000, 50));
	
	lblNew.setBounds(0, 0, 100, 100);
	frame.getContentPane().add(lblNew);
	
	lblNew.setVisible(true);

		// saving sample_minimal.png
		

	Server serv;
	JLabel lblNew2 = new JLabel("Distribution");
	//lblNew.setMaximumSize(new Dimension(10000, 50));
	
	lblNew2.setBounds(350, 50, 100, 10);
	frame.getContentPane().add(lblNew2);
	
	 canvas = new Canvas();
	  canvas.setBounds(350, 100, 236, 150);

	
	    canvas.setBackground(Color.WHITE);
	    canvas.setVisible(true);
	    canvas.setFocusable(false);

	    frame.getContentPane().add(canvas);
	    
	try {
		
		 serv=new Server(6005,this);
		 new Thread(serv).start();
		 
		 
	} catch (IOException e) {
		e.printStackTrace();
	}
	
	
	//On exit close all connections 


}
 
开发者ID:fmcalcagno,项目名称:Sensors,代码行数:68,代码来源:Interface.java


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