當前位置: 首頁>>代碼示例>>Java>>正文


Java Canvas.setSize方法代碼示例

本文整理匯總了Java中java.awt.Canvas.setSize方法的典型用法代碼示例。如果您正苦於以下問題:Java Canvas.setSize方法的具體用法?Java Canvas.setSize怎麽用?Java Canvas.setSize使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.awt.Canvas的用法示例。


在下文中一共展示了Canvas.setSize方法的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: 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

示例3: 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

示例4: 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

示例5: 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

示例6: init

import java.awt.Canvas; //導入方法依賴的package包/類
/**
 * @see java.applet.Applet#init()
 */
public void init() {
   removeAll();
   setLayout(new BorderLayout());
   setIgnoreRepaint(true);

   try {
      Game game = (Game) Class.forName(getParameter("game")).newInstance();
      
      container = new Container(game);
      canvas = new ContainerPanel(container);
      displayParent = new Canvas() {
         public final void addNotify() {
            super.addNotify();
            startLWJGL();
         }
         public final void removeNotify() {
            destroyLWJGL();
            super.removeNotify();
         }

      };

      displayParent.setSize(getWidth(), getHeight());
      add(displayParent);
      displayParent.setFocusable(true);
      displayParent.requestFocus();
      displayParent.setIgnoreRepaint(true);
      setVisible(true);
   } catch (Exception e) {
      Log.error(e);
      throw new RuntimeException("Unable to create game container");
   }
}
 
開發者ID:j-dong,項目名稱:trashjam2017,代碼行數:37,代碼來源:AppletGameContainer.java

示例7: WebcamCanvas

import java.awt.Canvas; //導入方法依賴的package包/類
public WebcamCanvas(Webcam w) {
	super();
	cam = w;
	canvas = new Canvas();
	setSize(w.getViewSize());
	canvas.setSize(w.getViewSize());
	add(canvas);
	initBox();
	canvas.addMouseListener(this);
}
 
開發者ID:ForOhForError,項目名稱:MTG-Card-Recognizer,代碼行數:11,代碼來源:WebcamCanvas.java

示例8: init

import java.awt.Canvas; //導入方法依賴的package包/類
public void init() {
	System.out.println("*** init ***");

	setLayout(new BorderLayout());
	try {
		test = (Test) Class.forName(getParameter("test")).newInstance();
		Canvas canvas = (Canvas) test;
		canvas.setSize(getWidth(), getHeight());
		add(canvas);
	} catch (Exception e) {
		e.printStackTrace();
	}
	test.start();
}
 
開發者ID:mleoking,項目名稱:PhET,代碼行數:15,代碼來源:AppletLoaderTest.java

示例9: main

import java.awt.Canvas; //導入方法依賴的package包/類
public static void main(String[] args) throws InterruptedException{
    AppSettings settings = new AppSettings(true);
    settings.setWidth(640);
    settings.setHeight(480);

    final TestSafeCanvas app = new TestSafeCanvas();
    app.setPauseOnLostFocus(false);
    app.setSettings(settings);
    app.createCanvas();
    app.startCanvas(true);

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

    

    Thread.sleep(3000);

    JFrame frame = new JFrame("Test");
    frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    frame.addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent e) {
            app.stop();
        }
    });
    frame.getContentPane().add(canvas);
    frame.pack();
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);

    Thread.sleep(3000);

    frame.getContentPane().remove(canvas);

    Thread.sleep(3000);

    frame.getContentPane().add(canvas);
}
 
開發者ID:mleoking,項目名稱:PhET,代碼行數:41,代碼來源:TestSafeCanvas.java

示例10: 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

示例11: 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

示例12: main

import java.awt.Canvas; //導入方法依賴的package包/類
public static void main(String[] args) {
    JFrame frame = new JFrame("My Drawing");
    Canvas drawing = new Drawing();
    drawing.setSize(400, 400);
    frame.add(drawing);
    frame.pack();
    frame.setVisible(true);
}
 
開發者ID:AllenDowney,項目名稱:ThinkJavaCode,代碼行數:9,代碼來源:Drawing.java

示例13: main

import java.awt.Canvas; //導入方法依賴的package包/類
public static void main(String[] args) {
	JFrame frame = new JFrame();
	frame.setSize(800, 800);
	frame.setResizable(false);
	frame.setTitle("Cubic Spline Demo");
	frame.setVisible(true);
	frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
	
	Canvas canvas = new PaintCanvas();
	canvas.setSize(800, 800);
	canvas.setVisible(true);
	
	frame.add(canvas);
}
 
開發者ID:CrushedPixel,項目名稱:CubicSplineDemo,代碼行數:15,代碼來源:Main.java

示例14: GreedSnake

import java.awt.Canvas; //導入方法依賴的package包/類
public GreedSnake() {
  mainFrame = new JFrame("GreedSnake");

  Container cp = mainFrame.getContentPane();

  labelScore = new JLabel("Score:");
  cp.add(labelScore, BorderLayout.NORTH);

  paintCanvas = new Canvas();
  paintCanvas.setSize(canvasWidth+1,canvasHeight+1);
  paintCanvas.addKeyListener(this);
  cp.add(paintCanvas, BorderLayout.CENTER);

  JPanel panelButtom = new JPanel();
  panelButtom.setLayout(new BorderLayout());
  JLabel labelHelp;
  labelHelp = new JLabel("PageUp, PageDown for speed;", JLabel.CENTER);
  panelButtom.add(labelHelp, BorderLayout.NORTH);
  labelHelp = new JLabel("ENTER or R or S for start;", JLabel.CENTER);
  panelButtom.add(labelHelp, BorderLayout.CENTER);
  labelHelp = new JLabel("SPACE or P for pause",JLabel.CENTER);
  panelButtom.add(labelHelp, BorderLayout.SOUTH);
  cp.add(panelButtom,BorderLayout.SOUTH);

  mainFrame.addKeyListener(this);
  mainFrame.pack();
  mainFrame.setResizable(false);
  mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  mainFrame.setVisible(true);
  begin();
}
 
開發者ID:CodeDogandCat,項目名稱:CarApp,代碼行數:32,代碼來源:GreedSnake.java

示例15: init

import java.awt.Canvas; //導入方法依賴的package包/類
public void init ()
{
  cursorChoice = new Choice();
  cursorChoice.add ("Default");
  cursorChoice.add ("Crosshair");
  cursorChoice.add ("Text");
  cursorChoice.add ("Wait");
  cursorChoice.add ("Southwest Resize");
  cursorChoice.add ("Southeast Resize");
  cursorChoice.add ("Northwest Resize");
  cursorChoice.add ("Northeast Resize");
  cursorChoice.add ("North Resize");
  cursorChoice.add ("South Resize");
  cursorChoice.add ("West Resize");
  cursorChoice.add ("East Resize");
  cursorChoice.add ("Hand");
  cursorChoice.add ("Move");

  cursorChoice.addItemListener(this);

  add (cursorChoice, "North");

  cursorCanvas = new Canvas ()
    {
      public void paint (Graphics g)
      {
        Dimension d = this.getSize();
        g.setColor(Color.white);
        g.fillRect(0, 0, d.width, d.height/2);
        g.setColor(Color.black);
        g.fillRect(0, d.height/2, d.width, d.height/2);
        g.setColor(this.getBackground());
        g.fillRect(d.width/3, d.height/3, d.width/3,
                    d.height/3);
      }
    };

  cursorCanvas.setSize (80,80);

  add (cursorCanvas, "Center");

  Button cb = new Button ("Close");
  cb.addActionListener(new ActionListener () {
      public void actionPerformed (ActionEvent e) {
        dispose();
      }
    });

  add (cb, "South");
  setTitle ("Cursors");
  pack();
}
 
開發者ID:vilie,項目名稱:javify,代碼行數:53,代碼來源:Demo.java


注:本文中的java.awt.Canvas.setSize方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。