本文整理匯總了Java中java.awt.Canvas.setPreferredSize方法的典型用法代碼示例。如果您正苦於以下問題:Java Canvas.setPreferredSize方法的具體用法?Java Canvas.setPreferredSize怎麽用?Java Canvas.setPreferredSize使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.awt.Canvas
的用法示例。
在下文中一共展示了Canvas.setPreferredSize方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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);
}
示例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();
}
示例3: Window
import java.awt.Canvas; //導入方法依賴的package包/類
public Window(KTech gc) {
image = new BufferedImage(gc.getWidth(), gc.getHeight(), BufferedImage.TYPE_INT_RGB); //Passes through the width and height
canvas = new Canvas();
Dimension s = new Dimension((int)(gc.getWidth() * gc.getScale()), (int)(gc.getHeight() * gc.getScale()));
canvas.setPreferredSize(s);
canvas.setMaximumSize(s);
canvas.setPreferredSize(s);
//Setting up the JFrame
frame = new JFrame(gc.getTitle());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout(new BorderLayout());
frame.add(canvas, BorderLayout.CENTER);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setResizable(false);
frame.setVisible(true);
canvas.createBufferStrategy(1);
bs = canvas.getBufferStrategy();
g = bs.getDrawGraphics();
}
示例4: 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();
}
示例5: start
import java.awt.Canvas; //導入方法依賴的package包/類
/**
* Starts displaying the game.
*/
public void start()
{ requestFocus();
loop.setPanel(this);
if(mode==0)
{ int width = getPreferredSize().width;
int height = getPreferredSize().height;
image = createImage(width, height);
}
else if(mode==1)
image = createVolatileImage();
else if(mode==2)
{ Canvas canvas = new Canvas();
canvas.setPreferredSize(getPreferredSize());
add(canvas);
canvas.createBufferStrategy(2);
bufferStrategy = canvas.getBufferStrategy();
}
}
示例6: getPanel
import java.awt.Canvas; //導入方法依賴的package包/類
private Container getPanel() {
Dimension d3Dim = new Dimension (800, 600);
AppSettings settings = new AppSettings(true);
settings.setWidth(d3Dim.width);
settings.setHeight(d3Dim.height);
settings.setSamples(4);
settings.setVSync(true);
settings.setFrameRate(60);
setSettings(settings);
createCanvas();
JmeCanvasContext ctx = (JmeCanvasContext) getContext();
ctx.setSystemListener(this);
Canvas canvas = ctx.getCanvas();
canvas.setPreferredSize(d3Dim);
JPanel panel = new JPanel(new BorderLayout());
panel.add( canvas, BorderLayout.CENTER );
return panel;
}
示例7: Unit
import java.awt.Canvas; //導入方法依賴的package包/類
public Unit(){
getBestSize();
net = new Net(new int[]{4,5,4}, true);
graph = new TimeGraph(net,0,GAME_HEIGHT-200,GAME_WIDTH, 200, "errorRate");
frame = new Frame();
canvas = new Canvas();
canvas.setPreferredSize(new Dimension(canvasWidth, canvasHeight));
canvas.addKeyListener(new InputHandler());
canvas.addMouseListener(new InputHandler());
canvas.addMouseMotionListener(new InputHandler());
frame.add(canvas);
frame.pack();
frame.setResizable(false);
frame.setLocationRelativeTo(null);
frame.addWindowListener(new WindowAdapter(){
@Override
public void windowClosing(WindowEvent e){
Test.quit(net);
}
});
frame.setVisible(true);
gc = canvas.getGraphicsConfiguration();
vImage = gc.createCompatibleVolatileImage(GAME_WIDTH, GAME_HEIGHT);
}
示例8: Unit
import java.awt.Canvas; //導入方法依賴的package包/類
public Unit(){
getBestSize();
net = new Net(new int[]{2,5,2});
graph = new TimeGraph(net,0,GAME_HEIGHT-200,GAME_WIDTH, 200, "errorRate");
frame = new Frame();
canvas = new Canvas();
canvas.setPreferredSize(new Dimension(canvasWidth, canvasHeight));
canvas.addKeyListener(new InputHandler());
canvas.addMouseListener(new InputHandler());
canvas.addMouseMotionListener(new InputHandler());
frame.add(canvas);
frame.pack();
frame.setResizable(false);
frame.setLocationRelativeTo(null);
frame.addWindowListener(new WindowAdapter(){
@Override
public void windowClosing(WindowEvent e){
Test.quit(net);
}
});
frame.setVisible(true);
gc = canvas.getGraphicsConfiguration();
vImage = gc.createCompatibleVolatileImage(GAME_WIDTH, GAME_HEIGHT);
}
示例9: create
import java.awt.Canvas; //導入方法依賴的package包/類
public static void create(int width, int height, String title, int _clearColor, int numBuffers) {
if (created)
return;
window = new JFrame(title);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
content = new Canvas();
Dimension size = new Dimension(width, height);
content.setPreferredSize(size);
window.setResizable(false);
window.getContentPane().add(content);
window.pack();
window.setLocationRelativeTo(null);
window.setVisible(true);
buffer = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
bufferData = ((DataBufferInt) buffer.getRaster().getDataBuffer()).getData();
bufferGraphics = buffer.getGraphics();
((Graphics2D) bufferGraphics).setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
clearColor = _clearColor;
content.createBufferStrategy(numBuffers);
bufferStrategy = content.getBufferStrategy();
created = true;
}
示例10: 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();
}
示例11: QuickFrame
import java.awt.Canvas; //導入方法依賴的package包/類
/**
* Builds a new frame.
*
* @throws IllegalArgumentException
* Problem while accessing the game data.
* @throws SecurityException
* Problem while accessing the game data.
* @throws ParserConfigurationException
* Problem while accessing the game data.
* @throws SAXException
* Problem while accessing the game data.
* @throws IOException
* Problem while accessing the game data.
* @throws IllegalAccessException
* Problem while accessing the game data.
* @throws NoSuchFieldException
* Problem while accessing the game data.
* @throws ClassNotFoundException
* Problem while accessing the game data.
*/
public QuickFrame() throws IllegalArgumentException, SecurityException, ParserConfigurationException, SAXException, IOException, IllegalAccessException, NoSuchFieldException, ClassNotFoundException
{ // init
super("TBB v."+GameData.VERSION+" (Quicklaunch)");
// panel size
Dimension contentDimension = Configuration.getVideoConfiguration().getPanelDimension();
// create canvas
canvas = new Canvas();
canvas.setIgnoreRepaint(true);
// canvas.setSize(dim);
canvas.setMinimumSize(contentDimension);
canvas.setPreferredSize(contentDimension);
canvas.setMaximumSize(contentDimension);
add(canvas);
// create progress bar
remove(canvas);
loadProgressBar = new JProgressBar();
// loadProgressBar.setSize(dim);
loadProgressBar.setMinimumSize(contentDimension);
loadProgressBar.setPreferredSize(contentDimension);
loadProgressBar.setMaximumSize(contentDimension);
loadProgressBar.setStringPainted(true);
loadProgressBar.setFont(GuiConfiguration.getMiscConfiguration().getFont().deriveFont(contentDimension.height/2f));
getContentPane().add(loadProgressBar);
// tournament
QuickStartConfiguration quickStartConfiguration = Configuration.getGameConfiguration().getQuickStartConfiguration();
tournament = quickStartConfiguration.loadQuickstart();
List<Profile> selectedProfiles = new ArrayList<Profile>();
ProfilesSelection profilesSelection = quickStartConfiguration.getProfilesSelection();
selectedProfiles = ProfileLoader.loadProfiles(profilesSelection);
tournament.setProfiles(selectedProfiles);
tournament.init();
tournament.progress();
// match
Match match = tournament.getCurrentMatch();
match.progress();
//round
round = match.getCurrentRound();
round.setPanel(this);
int limit = round.getProfiles().size()+3;
loadProgressBar.setMinimum(0);
loadProgressBar.setMaximum(limit);
}
示例12: Screen
import java.awt.Canvas; //導入方法依賴的package包/類
/**
* Constructs a new Screen object with the given width, height and title.
* The screen can be resized.
* @param width The screen width
* @param height The screen height
* @param title The screen title
*/
public Screen(final int width, final int height, final String title) {
frame = new JFrame(title);
canvas = new Canvas();
mouse = new Mouse();
keyboard = new Keyboard();
final WindowAdapter closingAdapter = new WindowAdapter() {
@Override
public void windowClosing(final WindowEvent w) {
close();
if (closingCallback != null) {
closingCallback.run();
}
}
};
final ComponentAdapter resizeAdapter = new ComponentAdapter() {
@Override
public void componentResized(final ComponentEvent c) {
calculateViewport();
if (redrawOnResize) {
redraw();
}
}
};
open = true;
initialWidth = canvasWidth = renderWidth = width;
initialHeight = canvasHeight = renderHeight = height;
resizeBehavior = ResizeBehavior.STRETCH;
canvas.setPreferredSize(new Dimension(width, height));
canvas.setIgnoreRepaint(true);
canvas.addMouseListener(mouse);
canvas.addMouseMotionListener(mouse);
canvas.addMouseWheelListener(mouse);
canvas.addKeyListener(keyboard);
frame.addMouseListener(mouse);
frame.addMouseMotionListener(mouse);
frame.addMouseWheelListener(mouse);
frame.addKeyListener(keyboard);
frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
frame.setIgnoreRepaint(true);
frame.addWindowListener(closingAdapter);
frame.addComponentListener(resizeAdapter);
frame.add(canvas);
frame.pack();
frame.setLocationRelativeTo(null);
}