awt

How do I fire MouseMotionListener events in real-time?

夙愿已清 提交于 2019-11-28 05:40:39
问题 I am trying to create a graphics drawing program that allows the user to draw red pixels on the screen by dragging their mouse over it. So in a way, you can think of this program as Microsoft's Paint program but with only the pencil drawing tool and color red. Unfortunately the mouseDragged() function in my program is not working properly. It will skip some of the pixels on the screen if I move my mouse too fast, like this: import java.awt.*; import java.awt.event.*; import javax.swing.*;

How to use TYPE_BYTE_GRAY to efficiently create a grayscale bufferedimage using AWT

懵懂的女人 提交于 2019-11-28 05:34:00
问题 I need to create a grayscale image from data in an nio ShortBuffer. I have a function that maps the data in the ShortBuffer to unsigned byte but is in an int (easily changed). The method I found uses an RGB plus transparency color model and appears to be quite inefficent. i have not been able to see how to apply the TYPE_BYTE_GRAY and modify the code. i'm new to Java. Here's my code: public void paintComponent(Graphics g) { final BufferedImage image; int[] iArray = {0, 0, 0, 255}; // pixel

Drawing Sierpinski's Triangle in Java

倾然丶 夕夏残阳落幕 提交于 2019-11-28 05:30:34
问题 I'm having some issues with my code to draw a Sierpinski's Triangle (or Sierpinski's Gasket), but I'm not sure what the problem is. The lines for the triangle are drawn, then all the fractals, then it disappears. Help? import javax.swing.*; import java.awt.*; public class SierpinskiGasket extends JFrame { Point x=new Point(5,545), y=new Point(300,25), z=new Point(605,545), current=x, target; private int count=0; public SierpinskiGasket () { super("Sierpinski Gasket"); setSize(610,550);

Why isn't java.awt.image.BufferedImage serializable?

蓝咒 提交于 2019-11-28 03:52:14
问题 I'm trying to serialize a BufferedImage in Java, but running my program I received a NotSerializableException . Looking at the BufferedImage class, I noticed that it does not implements Serializable . Why doesn't BufferedImage implement Serializable ? 回答1: I think you've just discovered a missing feature. Does it make sense to have BufferedImage implements Serializable ? In my opinion it does. Especially if the BufferedImage was not loaded from a file, but created and drawn upon. But even if

Empty String validation for Multiple JTextfield

痞子三分冷 提交于 2019-11-28 03:51:53
问题 Is there a way to validate a number of JTextfields in java without the if else structure. I have a set of 13 fields, i want an error message when no entry is given for any of the 13 fields and to be able to set focus to that particular textbox. this is to prevent users from entering empty data into database. could someone show me how this can be achieved without the if else structure like below. if (firstName.equals("")) { JOptionPane.showMessageDialog(null, "No data entered"); } else if

How to determine if 2 fonts have equivalent glyphs?

 ̄綄美尐妖づ 提交于 2019-11-28 03:46:18
问题 This Q&A was inspired by Unicode char not rendering in Swing, what font is used in real? but since it does not answer the specific question asked, I decided to enter it as its own Q&A. The question here is.. How to determine if two fonts, for a given text, are effectively equivalent in returning identical character glyphs? 回答1: The trick used here is to compare the GlyphVector returned for the String of interest. The crux of this approach can be seen in the method fontsAreEquivalentForText

Create GUI using Eclipse (Java) [duplicate]

我们两清 提交于 2019-11-28 03:42:38
Possible Duplicate: Best GUI designer for eclipse? Is there any Eclipse Plugin tool(s) who can help to create Graphical User Interface for (swing, awt or swt), because I'm tired of writing everytime the code of Panels, Labels, ... Thanks Grzegorz Szpetkowski Yes. Use WindowBuilder Pro (provided by Google). It supports SWT and Swing as well with multiple layouts (Group layout, MiGLayout etc.) It's integrated out of the box with Eclipse Indigo, but you can install plugin on previous versions (3.4/3.5/3.6): There are lot of GUI designers even like Eclipse plugins, just few of them could use both,

Swing and AWT Mixing is bad, but still done, why?

我与影子孤独终老i 提交于 2019-11-28 02:49:32
问题 I have noticed that people recommend not intermixing Swing and AWT Components , however we see this alot: import javax.swing.AbstractButton; import javax.swing.JButton; import javax.swing.JPanel; import javax.swing.JFrame; import javax.swing.ImageIcon; //AWT imports though only for listeners import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.KeyEvent; So why do many including Java (because I got that off their tutorial here) still use AWT imports,

How to eliminate delay in keyPress?

∥☆過路亽.° 提交于 2019-11-28 02:25:49
So I have seen a few threads about this already and I need some help about how to fix it specifically. When you hold down a key, Java will read the first key press, then there will be a small delay, and then it will continuously read the key press until you release the key. public void keyPressed(KeyEvent key) { int code = key.getKeyCode(); if (code == KeyEvent.VK_DOWN) { //Do stuff } if (code == KeyEvent.VK_LEFT) { //Do stuff } if (code == KeyEvent.VK_RIGHT) { //Do stuff } if (code == KeyEvent.VK_UP) { //Do stuff } } That is my current code. I heard that to fix this you can create a timer

Print the whole program layout

大城市里の小女人 提交于 2019-11-28 02:25:41
I have made a Java program ( JFrame based) using Netbeans, I would like to know if it is possible to print the layout of the program I wish to have a button and set the function to "print" and the final layout of the frame will be printed, is it possible? If yes, any reference source? This will depend on what it is you hope to achieve. You could simply print the contents of the frame to a BufferedImage . This allows you to control what you want to capture, in that you could print the content pane instead of the frame. You could use Robot to capture the screen. This will capture what ever is on