Java Code Examples for java.awt.Canvas#setSize()
The following examples show how to use
java.awt.Canvas#setSize() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Mickey.java From ThinkJavaCode2 with MIT License | 5 votes |
public static void main(String[] args) { JFrame frame = new JFrame("Mickey Mouse"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Canvas canvas = new Mickey(); canvas.setSize(400, 400); canvas.setBackground(Color.WHITE); frame.add(canvas); frame.pack(); frame.setVisible(true); }
Example 2
Source File: Moire.java From ThinkJavaCode2 with MIT License | 5 votes |
public static void main(String[] args) { JFrame frame = new JFrame("Moire Pattern"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Canvas canvas = new Moire(); canvas.setSize(400, 400); canvas.setBackground(Color.WHITE); frame.add(canvas); frame.pack(); frame.setVisible(true); }
Example 3
Source File: Drawing.java From ThinkJavaCode2 with MIT License | 5 votes |
public static void main(String[] args) { JFrame frame = new JFrame("My Drawing"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Canvas drawing = new Drawing(); drawing.setSize(400, 400); frame.add(drawing); frame.pack(); frame.setVisible(true); }
Example 4
Source File: GMeansTest.java From AILibs with GNU Affero General Public License v3.0 | 5 votes |
/** * Creates random datapoints and clusters. Then creates a UI to visualize the clusters. Not a Unit test for obvious reasons. * * @param args Nothing to see here */ public static void main(String[] args) { Random rand = new Random(SEED); // generate random points ArrayList<DoublePoint> data = new ArrayList<>(DATA_POINT_NUMBER); for (int i = 0; i < DATA_POINT_NUMBER; i++) { data.add(new DoublePoint( new int[] {rand.nextInt(500), rand.nextInt(500)})); } // create Cluster and results GMeans<DoublePoint> cluster = new GMeans<>(data); List<CentroidCluster<DoublePoint>> result = cluster.cluster(); // create Window JFrame frame = new JFrame("Simple Result UI"); @SuppressWarnings("serial") Canvas c = new Canvas() { @Override public void paint(Graphics g) { // paint points colored by cluster for (CentroidCluster<DoublePoint> centroidCluster : result) { g.setColor(new Color(rand.nextInt(255), rand.nextInt(255), rand.nextInt(255))); for (DoublePoint point : centroidCluster.getPoints()) { g.fillOval((int)point.getPoint()[0]-2, (int)point.getPoint()[1]-2, 4, 4); } } } }; c.setSize(500, 500); frame.getContentPane().add(c); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(500, 500); frame.setVisible(true); }
Example 5
Source File: Moire.java From Think-Java-Exercises with GNU General Public License v3.0 | 5 votes |
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); }
Example 6
Source File: Mickey.java From ThinkJavaCode with MIT License | 5 votes |
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); }
Example 7
Source File: Moire.java From ThinkJavaCode with MIT License | 5 votes |
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); }
Example 8
Source File: Drawing.java From ThinkJavaCode with MIT License | 5 votes |
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); }
Example 9
Source File: TestSafeCanvas.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
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); }
Example 10
Source File: AppletGameContainer.java From slick2d-maven with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * @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"); } }
Example 11
Source File: TestSafeCanvas.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
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); }
Example 12
Source File: AWTFontCalibration.java From phoebus with Eclipse Public License 1.0 | 4 votes |
@Override public void run() { Logger.getLogger("").setLevel(Level.CONFIG); for (Handler handler : Logger.getLogger("").getHandlers()) handler.setLevel(Level.CONFIG); final double factor = getCalibrationFactor(); final Frame frame = new Frame("Java AWT: Calibration factor " + factor); frame.setSize(text_width, text_height); // Would like to use TextField or Label, but: // "Peered AWT components, such as Label and TextField, // can only use logical fonts." (Javadoc for 'Font') // Sure enough at least on Windows the font family is // ignored, only the style and size are honored // by Label.setFont() or TextField.setFont() // --> Use canvas and draw the text with font. final Canvas text = new Canvas() { private static final long serialVersionUID = 1L; @Override public void paint(final Graphics gc) { super.paint(gc); gc.setFont(font); final FontMetrics metrics = gc.getFontMetrics(); // drawString x/y is 'baseline' of text final int y = metrics.getLeading() + metrics.getAscent(); gc.drawString(FontCalibration.TEXT, 0, y); // Show baseline and 'leading' gc.setColor(Color.RED); gc.drawLine(0, y, text_width, y); gc.setColor(Color.GREEN); gc.drawLine(0, metrics.getLeading(), text_width, metrics.getLeading()); } }; text.setSize(text_width, text_height); frame.add(text); frame.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent windowEvent) { System.exit(0); } }); frame.pack(); frame.setVisible(true); if (Math.abs(factor - 1.0) > 0.01) System.err.println("Calibration is not 1.0 but " + factor); }