awt

Java AWT Threads

喜夏-厌秋 提交于 2019-11-26 22:05:03
问题 I'm having an issue with Threads using netbeans Swing GUI. This is my first time really trying to develop a GUI for a backup program using Java's File System Notifier. I have two files SyncUI.java and Sync.java . Pretty much what I want to happen is you enter a directory path in the jTextField1 text field which creates a sync thread that creates a new sync object and then calls processEvents on that object. When a file in that directory is changed I want to add text about the change to the

creating huge BufferedImage

放肆的年华 提交于 2019-11-26 21:52:46
问题 I'm unable to create a huge BufferedImage (lack of memory is not the problem). Does anyone have any ideas? 1. new BufferedImage(10000, 1000000, BufferedImage.TYPE_3BYTE_BGR); Exception in thread "main" java.lang.NegativeArraySizeException at java.awt.image.DataBufferByte.<init>(DataBufferByte.java:42) at java.awt.image.Raster.createInterleavedRaster(Raster.java:253) at java.awt.image.BufferedImage.<init>(BufferedImage.java:368) 2. new BufferedImage(10000, 1000000, BufferedImage.TYPE_INT_RGB);

JTextArea on JPanel inside JScrollPane does not resize properly

梦想与她 提交于 2019-11-26 21:49:41
问题 I'd like to achieve the following: +------------------Other container(s)-----------------+ | +------JScrollPane (vertical)-------+ | | | JTextField | | | | Box.createRigidArea (vertical) | | | | JTextArea | | | | { etc.. any other J-component } | | | | | | | | | | | | | | | | | | | +-----------------------------------+ | +-----------------------------------------------------+ The closest I'm able to get is with the following (pseudo) code: JPanel container = new JPanel(new BorderLayout());

How To Remove The Last Image In An Animation

青春壹個敷衍的年華 提交于 2019-11-26 21:45:48
问题 What I am trying to do is create an animation that creates a 'running' motion. Whenever I draw it on the screen, the last frame in the animation is left behind (So there is a trail of animation frames left behind when the sprite moves). I've tried if statements and changing the image's draw position when the frame changes: if(a2.sceneNum() == 0) spectre_Draw1 = (screenWidth() / 2 - 120 / 2 + 120 - 6); else spectre_Draw1 = 0; g.drawImage(pic[2], spectre_Draw1, (screenHeight() / 2 - 180 / 2),

How can I catch AWT thread exceptions in Java?

隐身守侯 提交于 2019-11-26 21:12:18
问题 We'd like a trace in our application logs of these exceptions - by default Java just outputs them to the console. 回答1: There is a distinction between uncaught exceptions in the EDT and outside the EDT. Another question has a solution for both but if you want just the EDT portion chewed up... class AWTExceptionHandler { public void handle(Throwable t) { try { // insert your exception handling code here // or do nothing to make it go away } catch (Throwable t) { // don't let the exception get

Problems with Java's Paint method, ridiculous refresh velocity

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-26 21:07:33
I'm developing a very simple version of R-Type as work for the university, but despite it works, the craft velocity is a lot of slow, so the movement is ugly and clumsy. I use the method repaint for refresh the screen, there are others methods or ways best than it? Video of Movement Paint method at main Panel @Override public void paint(Graphics g) { super.paint(g); Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.drawImage(fondo, 0, 0,1200,600,this); pj.paint(g2); g2D=g2; } PJ's paint method public void paint

Choosing a file in-pane with Swing

浪子不回头ぞ 提交于 2019-11-26 20:57:24
I'm writing a GUI in Swing where I want to do a file chooser that is in the main window, looking something like the image below: while there seem to be quite a few tutorials on how to write a popup file chooser, i don't see much information on how this type of chooser might be accomplished in swing. also sorry if this has been asked before, i did a good bit of searching around and wan't able to find anything else.. JFileChooser actually extends JComponent, so you can use like any other component. Here is an example with two in-pane file choosers: public class TestInPaneChoosers { public static

Is there a simple way to compare BufferedImage instances?

耗尽温柔 提交于 2019-11-26 20:37:31
问题 I am working on part of a Java application that takes an image as a byte array, reads it into a java.awt.image.BufferedImage instance and passes it to a third-party library for processing. For a unit test, I want to take an image (from a file on disk) and assert that it is equal to the same image that has been processed by the code. My expected BufferedImage is read from a PNG file on disk using ImageIO.read(URL) . My test code reads the same file into a BufferedImage and writes that to a

Is Java Swing still in use?

[亡魂溺海] 提交于 2019-11-26 20:32:05
问题 I am planning on making a Java Swing application and was wondering if Swing is still used or if it has been replaced with something else. Thanks in advance! 回答1: We still use it. Not everything is a web app, so far there have been some tentative replacements (such as SWT, which eclipse is written in) SWT has a native layer that wraps the underlying calls to the native windowing layer. It only works for a limited set of platforms and of course requires some third party shared libraries. I

Drawing in Java using Canvas

家住魔仙堡 提交于 2019-11-26 20:17:23
问题 I want to draw in Java's Canvas but can't get it work because I don't know what I'm doing. Here's my simple code: import javax.swing.JFrame; import java.awt.Canvas; import java.awt.Graphics; import java.awt.Color; public class Program { public static void main(String[] args) { JFrame frmMain = new JFrame(); frmMain.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frmMain.setSize(400, 400); Canvas cnvs = new Canvas(); cnvs.setSize(400, 400); frmMain.add(cnvs); frmMain.setVisible(true); Graphics