本文整理汇总了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);
}
示例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");
}
}
示例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");
}
}
示例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;
}
示例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;
}
示例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");
}
}
示例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);
}
示例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();
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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();
}
示例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();
}