awt

Java小项目之:拼图游戏!

时间秒杀一切 提交于 2020-02-26 08:28:55
Java小项目之:拼图游戏! 今天教大家用java做出一个拼图游戏,很适合java初学者练手。 所用素材: 部分代码: package picture_mosical; import java.awt.Graphics; import java.awt.Image; import java.awt.Toolkit; import java.awt.image.BufferedImage; import java.awt.image.CropImageFilter; import java.awt.image.FilteredImageSource; import java.awt.image.ImageFilter; import java.io.File; import javax.imageio.ImageIO; public class PictureCut { private static int width;// 切割后图片的宽度 private static int height;// 切割后图片的高度 private static String dir_name = "/CutImage";// 存放图片的文件夹名称 public static void cut(String paths, int rows, int cols, String dir) throws

Javadoc注释中的多行代码示例

与世无争的帅哥 提交于 2020-02-25 15:50:23
我有一个小的代码示例,我想在方法的Javadoc注释中包括该代码。 /** * -- ex: looping through List of Map objects -- * <code> * for (int i = 0; i < list.size(); i++) { * Map map = (Map)list.get(i); * System.out.println(map.get("wordID")); * System.out.println(map.get("word")); * } * </code> * * @param query - select statement * @return List of Map objects */ 问题是代码示例显示在Javadoc中,没有换行符,很难阅读。 -- ex: looping through List of Map objects -- for (int i = 0; i list.size(); i++) { Map map = (Map)list.get(i); System.out.println(map.get("wordID")); System.out.println(map.get("word")); } Parameters query - - select statement Returns:

Draw image as a polygon

﹥>﹥吖頭↗ 提交于 2020-02-07 03:38:44
问题 I'm trying to draw an image as a polygon in Swing but I don't know how. Now I only have code to draw filled polygon. This is not a cropped image, it is distorted. What I need (Polygon with texture): What I have - Filled polygon gr.fillPolygon(x_points, y_points, points.length); 回答1: The easiest way to render 3D is using JOGL library which uses OpenGL to render in JPanel. 来源: https://stackoverflow.com/questions/55949306/draw-image-as-a-polygon

Draw image as a polygon

此生再无相见时 提交于 2020-02-07 03:38:25
问题 I'm trying to draw an image as a polygon in Swing but I don't know how. Now I only have code to draw filled polygon. This is not a cropped image, it is distorted. What I need (Polygon with texture): What I have - Filled polygon gr.fillPolygon(x_points, y_points, points.length); 回答1: The easiest way to render 3D is using JOGL library which uses OpenGL to render in JPanel. 来源: https://stackoverflow.com/questions/55949306/draw-image-as-a-polygon

LWJGL Display mounted on Canvas fails to generate Mouse Events

社会主义新天地 提交于 2020-01-25 23:56:13
问题 My ultimate goal is to be able to make use of additional mouse buttons in Java. Currently, LWJGL's JInput doesn't seem capable of detecting more than three buttons. To make use of Java's System.setProperty("sun.awt.enableExtraMouseButtons", "true"), I've tried mounting the Display onto an AWT Canvas, within a JFrame. Unfortunately, this does not appear to work, and I am unsure why. [I should note that I've been away from Java for a some time] import java.awt.Canvas; import java.awt.event

How to get Color object in java from css-style string which describes color?

有些话、适合烂在心里 提交于 2020-01-25 13:11:27
问题 For example, I have strings #0f0 , #00FF00 , green and in all cases I want to transform them to Color.GREEN . Are there any standard ways or maybe some libraries have necessary functionality? 回答1: First, I apologize if the below isn't helpful - that is, if you know how to do this already and were just looking for a library to do it for you. I don't know of any libraries that do this, though they certainly may exist. Of the 3 strings you gave as an example, #00FF00 is the easiest to transform.

Trying to put button and using center mode

一个人想着一个人 提交于 2020-01-25 07:29:49
问题 Im trying to make a option menu to be able to choose flags to be displayed, Im trying to put the tailand button on the left down corner and it seems it does not want to budge. import java.awt.*; import javax.swing.*; public class Flags { public static void startup() { Dimension d = new Dimension(400,300); JFrame menu = new JFrame("Flag Menu"); menu.setResizable(true); JButton tailand = new JButton("Tailand"); JPanel tailandPanel = new JPanel(); tailand.setLayout(null); tailandPanel.setLayout

KeyPressed and KeyTyped Confusion [duplicate]

蓝咒 提交于 2020-01-25 06:08:26
问题 This question already has answers here : KeyListener, keyPressed versus keyTyped (4 answers) Closed 6 years ago . I have searched about difference between KeyPressed and KeyTyped Events but still I'm not clear about that . One thing I have found is Keypressed is triggered first than KeyTyped . Please clarify me when these are triggered exactly . Which is appropriate to use for which purpose ? Thanks in advance 回答1: keyPressed is fired whenever any key press occurs. keyTyped is fired when a

KeyPressed and KeyTyped Confusion [duplicate]

雨燕双飞 提交于 2020-01-25 06:07:31
问题 This question already has answers here : KeyListener, keyPressed versus keyTyped (4 answers) Closed 6 years ago . I have searched about difference between KeyPressed and KeyTyped Events but still I'm not clear about that . One thing I have found is Keypressed is triggered first than KeyTyped . Please clarify me when these are triggered exactly . Which is appropriate to use for which purpose ? Thanks in advance 回答1: keyPressed is fired whenever any key press occurs. keyTyped is fired when a

why is paintComponent() never called by repaint()?

有些话、适合烂在心里 提交于 2020-01-25 05:59:10
问题 I've been working on an program that draws custom JComponents onto a JLayeredPane however all calls to repaint() on the components seem to do nothing yet the paintComponent method is invoked automatically when the window is re-sized. I have been following some of the advice given here: Why is paint()/paintComponent() never called? But none of the solutions seem to fix my problem, update swing components on the EDT, setting component size manually before calling repaint(), calling super