awt

The number returned by Font.getNumGlyphs()

这一生的挚爱 提交于 2019-12-02 08:46:16
问题 What does the number returned by Font.getNumGlyphs() actually represent? The docs. state: Returns the number of glyphs in this Font . Glyph codes for this Font range from 0 to getNumGlyphs() - 1 . I thought it represented the number of code points between 0 and Character.MAX_CODE_POINT for which Font.canDisplay(codePoint) returned true . But the output of the code below suggests otherwise. Code Note: Going through 1 million+ code points (the countGlyphs method) for over 200 fonts takes near

custom shape rotation issue

邮差的信 提交于 2019-12-02 08:42:15
I am trying to rotate a custom shape around its center, but can not get the result as expected. what i want is * shape should be rotated around its center without moving itself. * what my solution is currently doing is rotating a whole shape around its center , by every rotation its changing its position. I have multiple shapes so i have created a class to encapsulate a shape with its transform in following class public abstract class Shoe implements Shape, ShoeShape { // variable declaration /** * */ public Shoe() { position = new Point(); lastPosition = new Point(); } public void draw

Coloring an area of BufferedImage

老子叫甜甜 提交于 2019-12-02 08:41:52
I want to color a sub area of a BufferedImage I have. I am presently doing: public BufferedImage paintSubImage(BufferedImage img, int x, int y, int w, int h) { Graphics g = img.getGraphics(); g.setColor(Color.BLACK); g.fillRect(x,y,w,h); return img; } But I am not able to color it. Am I doing it wrong? Given the fact that there is little or no context to go on, it's difficult to know exactly what's wrong. General rule of thumb though, if you create/open it, you should dispose/close it... import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; import java.awt.EventQueue;

How to fix java.awt.HeadlessException in Jenkins on Linux

流过昼夜 提交于 2019-12-02 08:35:27
I use some AWT code in my Java app which ran fine until I unit tested it on Linux Mint Debian Edition via Jenkins and Gradle: I now get that nasty java.awt.HeadlessException which is explained here . The unsuccessful unit test causes my build to fail; how do I fix that? These are the steps that rid me of the HeadlessException: Add the Xvnc plugin to Jenkins Install VNC : sudo apt-get update && sudo apt-get install vnc4server Make sure Jenkins has a shell: sudo usermod -s /bin/bash jenkins Log in as Jenkins: sudo su jenkins Enter the command vnc4server and choose a password Tick Run Xvnc during

Load fonts out of JAR-file and create AWT font (works) and register iText font (does not work)

守給你的承諾、 提交于 2019-12-02 08:32:09
I tried to write an applet that is able to create a PDF with an embedded font. Everything works as long as it is not in an JAR file. The following code part shows that I first create the AWT Font (which works fine with and without beeing stored in a JAR-file). Then I want to register an iText (5.0.3) font. But here comes the error: access denied (java.io.FilePermission http:\host\jarfile\fonts\EXAMPLE.ttf read) java.security.AccessControlException) . private String font = "fonts/EXAMPLE.ttf"; /* iText font */ private Font pdfFont; /* AWT font */ private java.awt.Font javaFont; private

How to stop the auto-repaint() when I resize the Jframe

China☆狼群 提交于 2019-12-02 08:22:43
I am still learning Java, if someone can help me I will be very happy! Sorry for bad english, I am spanish! I am making a tile game, the game uses the classic "game loop" that cap the engine at 60fps The loop sleep and then call repaint(); This works fine! But.. The problem is that repaint event is called when the JFrame is resized or maximized! For example when the JFrame is maximized/resized the game render at 10000fps but when they dont, the game render at the speed I set, so there is a way to disable Automatic repaint and make it work ONLY when the "component.repaint()" is called from my

paintComponent not painting onto JPanel

一曲冷凌霜 提交于 2019-12-02 08:20:45
I am working on a homework assignment where I am supposed to make a program that allows you to paint custom shapes and lines, and move them around the screen. Originally I was using public void paint(g) to paint, but the shapes were flickering when I called repaint. Because of that I switched over to paintComponent(g) . However When I try to paint a shape nothing shows up. I believe this is because it isn't painting on top of the JPanel . The frame has 3 panels in a 3 row BorderLayout . [Button JPanel] [Draw Box JPanel] [Coordinate Jpanel] The panel I would like to draw on is the Draw Box

how to remove an action listener?

二次信任 提交于 2019-12-02 08:20:37
问题 so im making a chess game but only with the knight. this is the method for moving the knight public void caballo(final int row, final int column) { final JButton current = mesa[row][column]; current.setIcon(image); panel.repaint(); acciones(row, column, current); } public void acciones(final int row, final int column, final JButton current) { for (int i = 0; i < HEIGHT; i++) { for (int j = 0; j < WIDTH; j++) { mesa[i][j].addActionListener(e(row, column, current)); } } } public ActionListener

Java GridBagConstraints gridx and gridy not working?

落爺英雄遲暮 提交于 2019-12-02 08:11:03
问题 I am trying to use the gridx and gridy constraints to position my button. But they do not work! If I change the gridx and gridy variables, nothing happens. If I change the fill to GridBagConstraints to NONE , it still does not work. Am I missing something here? import java.awt.*; import javax.swing.*; public class Window extends JFrame{ private static final long serialVersionUID = 1L; JFrame frame = new JFrame("GUI"); JTextField username = new JTextField(20); public void CreateWindow(){

Java: rotating image so that it points at the mouse cursor

╄→гoц情女王★ 提交于 2019-12-02 08:09:16
I want the player image to point towards the mouse cursor. I use this code to get the postion of the mouse cursor: private int cursorX = MouseInfo.getPointerInfo().getLocation().x; private int cursorY = MouseInfo.getPointerInfo().getLocation().y; Note: The default player image points upwards 0x6C38 You'll have to use trigonometry in order to calculate the angle of rotation. For that you'll first need to obtain the location of the image and the cursor. I cannot tell you how to get the position for the image as this may vary. For this example (adapted from here ), I'll assume imageX and imageY