awt

Animating dashed-line with java.awt.BasicStroke

笑着哭i 提交于 2019-11-26 14:09:59
问题 Is there a way to produce animated dashed line using BasicStroke from java.awt? My desire is to have a running dashed-line in the same way that photoshop's rectangle marque tool has its line animated. 回答1: Use a dashed line, a Thread (or a Swing Timer ) & combine them with repaint() and some tweaking of where the dashes start and end - and there you have it. Example package test; import java.awt.BasicStroke; import java.awt.Color; import java.awt.Graphics2D; import java.awt.Shape; import java

Setting java.awt.headless=true programmatically

僤鯓⒐⒋嵵緔 提交于 2019-11-26 13:49:03
问题 I'm trying to set java.awt.headless=true during the application startup but it appears like I'm too late and the non-headless mode has already started: static { System.setProperty("java.awt.headless", "true"); /* java.awt.GraphicsEnvironment.isHeadless() returns false */ } Is there another way set headless to true beside -Djava.awt.headless=true ? I would prefer not configure anything on the console. 回答1: I was working with a main() in a class which statically loads different parts of

How to make AWT Button() and use ImageIcon(), Icon()?

夙愿已清 提交于 2019-11-26 12:48:42
问题 How can I apply a GIF image to my AWT Button ? AWT: does not work Icon warnIcon = new ImageIcon(\"/src/world.gif\"); Button button1 = new Button(warnIcon); Icon warnIcon = new ImageIcon(\"/src/world.gif\"); JButton button1 = new JButton(warnIcon); 回答1: AWT is a bit different from Swing. There's no constructor button(image) , hence your "not working". Take a look at Learn how to extend the AWT with your own image buttons to see how to make that image on a AWT button. 回答2: Back to your three

Mirroring animated gif on load in Java - ImageIcon

烂漫一生 提交于 2019-11-26 12:48:23
问题 So I have an animated gif that I load into an ImageIcon like this: Image image = new ImageIcon(\"image.gif\").getImage(); and I can draw it using this: g.drawImage(image, x, y, null); I know that I can mirror it on the fly using AffineTransform, but I need to be able to mirror it horizontally after loading, so that I can draw the mirrored one instead if needed without the overhead of transforming it every time it gets redrawn. Is there a way to do this using swing/awt? A library that could do

Java Animate JLabel

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-26 12:31:52
So I am creating a basic application that I want to have a JLabel at the bottom of the screen that starts at the left bottom corner and moves, animation style, to the right bottom corner in a set time, and a static image in the center. To do this, I created a JFrame with a JPanel using BorderLayout. There is a JLabel with an ImageIcon added to BorderLayout.CENTER and a JPanel at BorderLayout.SOUTH. My code, while hastily written and far from pretty, is: import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; import java.awt.event.ActionEvent; import java.awt.event

Convert text content to Image

♀尐吖头ヾ 提交于 2019-11-26 11:57:45
问题 Is there out any Java library that allows converting text content to image files? I only know of ImageMagick (JMagick in this case) but I wouldn\'t like to install any external binaries (my app will be deployed as a .war file in a Tomcat server so I don\'t want any other dependencies more than Java). For example, from the string \"Hello\", I would like to generate this simple image: 回答1: The Graphics 2D API should be capable of achieving what you need. It has some complex text handling

How do you import a font?

倖福魔咒の 提交于 2019-11-26 11:54:30
I'm wondering how you would go about importing a font. I'm trying to use a custom downloaded font but since most computers that would go to run this would not have this font as it's not a default font. How would I go about making the font work even if they don't have the font? I'm using it for a gameover screen and need to display a score with it and want the score text to be the same font. This is the image, In case it matters the font name on my computer is Terminal Edit: I'm assuming it would have to have the font in the directory of the java file and there would be some way of using that

How to print a JTable object in the Java application

我的梦境 提交于 2019-11-26 11:41:18
问题 Question Now once the data is fetched from the database and shown in the JTable object \"table\" embedded in the scrollPane, how do we create a print job that makes it possible to print the displayed table as such in A3 sized paper ? My code to fetch the data from the database is shown below: try { Class.forName(\"com.mysql.jdbc.Driver\"); Connection con=DriverManager.getConnection(\"jdbc:mysql://localhost/newb\",\"root\",\"pass\"); Statement stat=con.createStatement(); ResultSet res=stat

AffineTransform.rotate() - how do I xlate, rotate, and scale at the same time?

吃可爱长大的小学妹 提交于 2019-11-26 11:39:47
问题 I have the following code which does (the first part of) what I want drawing a chessboard with some pieces on it. Image pieceImage = getImage(currentPiece); int pieceHeight = pieceImage.getHeight(null); double scale = (double)side/(double)pieceHeight; AffineTransform transform = new AffineTransform(); transform.setToTranslation(xPos, yPos); transform.scale(scale, scale); realGraphics.drawImage(pieceImage, transform, this); that is, it gets a chess piece\'s image and the image\'s height, it

KeyListener vs. Key Bindings

泪湿孤枕 提交于 2019-11-26 11:38:59
问题 People here keep suggesting to me to use Key Binding instead of KeyListener in Java 2D games. What are the advantages and disadvantages of each one? Is Key Bindings really better for 2D games? 回答1: KeyListener is a much lower level API which requires the component that it is registered to be focused AND have keyboard focus. This can cause issues when you have other components within your game that may grab keyboard focus, for example. KeyListener is generally more difficult to maintain and