awt

In Java, AWT, repaint-method seems to be ignored in favor of start-method

ⅰ亾dé卋堺 提交于 2019-12-24 06:38:12
问题 I'm building an applet of a board game, and handling user input roughly looks like this: public void mousePressed(MouseEvent event) { int row = event.getX() / (getSize().width / 8) ; int column = event.getY() / (getSize().height / 8) ; if(possibleMove(column, row) { makeMove(column,row,whosTurn); repaint(); start(); } } After a human input, the computer chooses a move and calls repaint() and start() like this method does. But the screen seems to update only after the computer has made a move,

how to restrict more than one java application icon on taskbar?

流过昼夜 提交于 2019-12-24 03:18:45
问题 I have created an application in java which have several forms. During application start getting open new form on button click event,On windows's taskbar the number of icons of that form getting increases. what I want is only applicatoin icon should be displayed on task bar whether one form is open or more than one. 回答1: The problem happens because each JFrame gets a task-bar icon. See The Use of Multiple JFrames, Good/Bad Practice? for links to a multitude of solutions. 回答2: I think this

JFormattedTextFiled limit only to 0 or 1

耗尽温柔 提交于 2019-12-24 02:14:19
问题 I want to limit the what characters the user should be allowed to type in a text field. How can I limit JFormattedTextField to accept only 8 digits of either 0 or 1? 回答1: Use DocumentFilter with Pattern for JTextField , then maybe there isn't required to use JFormattedTextField A sample program to help your cause : import java.awt.Toolkit; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JTextField; import javax.swing.SwingUtilities; import javax.swing.text

Java Arabic (Hirji) Calendar

六眼飞鱼酱① 提交于 2019-12-24 01:44:24
问题 I've been trying to find good international Calendar support (Hirji included) for a mobile app. My main constraint is that the JVM is 1.3 and we've got AWT only. There is an option to move over to another JVM that gives us SWT, but I can't seem to find any international date pickers for either UI libs. I know Joda-time is available, but looking at the tech docs there doesn't seem to be a UI layer for it. So really, I want to know if anyone has come across a Hirji date picker for AWT or SWT.

How to rotate an ImageIcon() with actionPerformed()?

好久不见. 提交于 2019-12-24 01:37:30
问题 I am having difficulties rotating an imageicon by using the arrow keys. I currently have the following as my code import java.awt.event.*; import javax.swing.*; import java.awt.*; public class startGame extends JPanel implements ActionListener,KeyListener { Timer time = new Timer(5,this); int x=0,y=0,velX = 0,velY=0; Image car1; public static void main(String[] args) { startGame game = new startGame(); JFrame frame = new JFrame(); frame.setTitle("NEED FOR SPEED"); frame.setSize(800,800);

UncaughtExceptionHandler not catching some exceptions

浪尽此生 提交于 2019-12-24 00:44:08
问题 I have created an UncaughtExceptionHandler as shown in this article. I have also registered this handler to catch exceptions in all threads like this: Thread.setDefaultUncaughtExceptionHandler(new MyExceptionHandler()); However, it is missing some exceptions: Exception occurred during event dispatching: java.lang.RuntimeException: Critical error! at com.acme.MyClass.myMethod(MyClass.java:46) at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209) at java.awt.EventQueue

Drawing graphics on top of a JButton

北城余情 提交于 2019-12-23 21:00:31
问题 I have a situation wherein I have a bunch of JButtons on a GridLayout. I need each of the JButtons to have: a background image (but retain the ability to keep the default button look if needed) custom graphics drawn on top by other classes I have no trouble with the background image, since I am using setIcon() but I am having problems drawing things on top of the background. At one point I was able to draw on top of the button, but after the button was clicked, the drawings disappeared. How

Tile Drawing on Canvas based on file with ints

女生的网名这么多〃 提交于 2019-12-23 19:18:10
问题 So im trying to make a map based on a a file which has ints in it 1111111111 1000000001 1000000001 1000000001 1111111111 And so what i get the code to do is display a grass tile (32x32) for 1 and a dirt tile for 0. This is my code for loading and differentiating between the 2. protected void loadMapFile(String string) throws Exception { // TODO Load Map, Put into int array File f = new File(string); BufferedReader in = new BufferedReader(new FileReader(f)); String line = in.readLine(); cols =

Java A3 printing on Macs coming out at A4 scale

匆匆过客 提交于 2019-12-23 17:45:52
问题 I have an odd problem that seems to be specific to Mac computers. I have a prog that prints the content of an AWT drawing surface to an A3 sheet of paper. On Linux and windows machines the output is OK. Printing from a Mac I get the same dialog with the same preset parameters, the printer prints on an A3 sheet of paper as expected, but for some reason the image is scaled to fit an A4 area. Below are the relevant sections of code: public void print() { PrinterJob printJob = PrinterJob

Alpha Channel Blur

老子叫甜甜 提交于 2019-12-23 17:33:55
问题 I've got this BufferedImage object that's guaranteed to contain only one color. I'm using it to display a sample image to show size, shape & hardness of a brush in a painting tool. I've tried several different blur implementations for hardness... the latest, that seems to work fairly well is this Stack Filter written by Romain Guy. I've got 2 problems. Faster on 1 channel than 4?: None of the blur filters I've tried seem to be quite fast enough... I realize this question has been asked before