awt

Create a Trailing line of blood behind a player

强颜欢笑 提交于 2019-11-28 12:19:49
问题 I am currently working on a simple top down shooter. The object is a ball that slides around the screen, and I am trying to make a sort of wet-dragging affect. I am using Java Swing and just the default Graphics2d lib inside. This is what I have: and this is my goal: I need to know how I can make a curved line that has the ability to change alpha at the trailing end. I have searched online but I can only find non-dynamic solutions. (The tail needs to update as the player moves across the

Double Buffering with awt

邮差的信 提交于 2019-11-28 12:17:52
Is double buffering (in java) possible with awt? Currently, I'm aware that swing should not be used with awt, so I can't use BufferStrategy and whatnot (I already have some code written in awt that I don't want to rewrite in swing). If double buffering is possible with awt, do I have to write the buffer by hand? Unlike swing, awt doesn't seem to have the same built-in double buffering capability. If I do have to write the code by hand, is there a good tutorial to look at? Or is it just easier/advisable for a novice programmer to use swing instead? Sorry about the multi-step question. Thanks

drawing simple rectangles on a Jframe in java

女生的网名这么多〃 提交于 2019-11-28 12:17:05
I am extending JFrame like this: public GameFrame() { this.setBounds(30, 30, 500, 500); this.setDefaultCloseOperation(EXIT_ON_CLOSE); initializeSquares(); } private void initializeSquares(){ for(int i = 0; i < 5; i++){ this.getContentPane().add(new Square(i*10, i*10, 100, 100)); } this.setVisible(true); } However, only one square is being drawn on the screen, does anybody know why? also My Square class looks like this: private int x; private int y; private int width; private int height; public Square(int x, int y, int width, int height){ this.x = x; this.y = y; this.width = width; this.height

How to check for key being held down on startup in Java

陌路散爱 提交于 2019-11-28 12:11:30
I'm trying to write a resolution selection dialog that pops up when a program first starts up. To prevent boring the user, I want to implement the fairly standard feature that you can turn off that dialog with a checkbox, but get it back by holding down the alt key at startup. Unfortunately, there is no obvious way to ask java whether a given key is currently being pressed . You can only register to be informed of new key presses via a KeyListener, but that doesn't help if the keypress starts before the app launches. public class LockingKeyDemo { static Toolkit kit = Toolkit.getDefaultToolkit(

How to make a line curve through points

只谈情不闲聊 提交于 2019-11-28 12:06:41
I'm looking for a way to make a line curve through a number of points. It would be preferable to use 3 points although I've considered that in order to give context to the angle of the line entering a point more may be needed to give context to the curve so to speak. In general a start point P1, a control point P2 and an end point P3, the line should curve to P2 from P1 and then curve from P2 to P3. In fact here is a perfect example of the effect I would like to achieve: If I could do this I really would be eternally grateful! In Java so far, I have tried playing around with things such as

Widgets behaving strangely when using “setlayout(null)”

雨燕双飞 提交于 2019-11-28 11:49:03
问题 I'm doing the following call in my code: ... setLayout(null); ... I'm trying to place a button and a textfield by specifying their x and y coordinates. The problem when I run the program (either with Eclipse or BlueJ) is that I need to run on the panel up to the position of the button and the textfield in order to see respectively the button and the textfield. When I find the textfield, it is small. Only when I start writing it assumes the size I specified. Does anyone know how to solve it?

MediaTracker - how to use it, what are the benefits, or is there an alterative?

大憨熊 提交于 2019-11-28 11:25:51
In the codebase we inherited the usage of MediaTracker was always done locally in each code block. new MediaTracker(new Canvas()); mediatracker.addImage(i, 1); try { mediatracker.waitForAll(); } catch (InterruptedException e) { } mediatracker.removeImage(i); Deciding this was inefficient, I eventually replaced it with a static instance and method: final static protected MediaTracker mediatracker = new MediaTracker(new Canvas()); static protected void checkImageIsReady(Image i) { mediatracker.addImage(i, 1); try { mediatracker.waitForAll(); } catch (InterruptedException e) { } mediatracker

Why does a Latin-characters-only Java font claim to support Asian characters, even though it does not?

天涯浪子 提交于 2019-11-28 11:22:07
When rendering a chart with JFreeChart, I noticed a layout problem when the chart's category labels included Japanese characters. Although the text is rendered with the correct glyphs, the text was positioned in the wrong location, presumably because the font metrics were wrong. The chart was originally configured to use the Source Sans Pro Regular font for that text, which supports only Latin character sets. The obvious solution is to bundle an actual Japanese .TTF font and ask JFreeChart to use it. This works fine, in that the output text uses the correct glyphs and it is also laid out

Animated GIF leads to SplashScreen being null

落花浮王杯 提交于 2019-11-28 10:48:20
问题 I know this is probably close to a duplicate of this thread: Animated GIF in Splashscreen But since it seems unanswered and I can't comment on it or anything I'm sorry to repost this but it would be awesome if someone could give me an answer. I am making a game and this game takes quite a lot of time to start. Therefore I want to give the user feedback during the loading screen so he knows the application hasn't crashed. That's why I use the SplashScreen API from java 7. In eclipse, when I

How java swing draws to screen from different operating systems?

╄→尐↘猪︶ㄣ 提交于 2019-11-28 10:35:57
问题 I know Swing use Java2d which extends AWT to draw on screen but, what low level toolkit is used by swing to render? GTK or QT for example? 回答1: Concrete implementations of Graphics2D on each supported platform direct painting to a heavyweight peer component provided by the host, e.g. Quartz on Mac OS X, Graphics Device Interface on Windows, and Xlib/XCB, part of the X Window System often used on Linux. 来源: https://stackoverflow.com/questions/29440313/how-java-swing-draws-to-screen-from