awt

Is Google Web Toolkit similar to AWT and Swing

一曲冷凌霜 提交于 2019-11-29 09:05:37
问题 I've looked breifly into GWT and like the idea that I can develop in Java and have the application compile down to HTML and JavaScript. Is the concept behind GWT and AWT and Swing the same or different? 回答1: GWT is very much similar to Swing in its usage of Widgets, Panels and the EventListeners it provides. A different way to look at GWT is to think of Javascript and HTML as Assembly language and GWT as a sort of High level language which generates Javascript and HTML. With GWT its easy to

Getting High Resolution Image from JPanel

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-29 08:52:43
Suppose I have a JPanel Called panel , and already with a paintComponent , I drew some shapes like rectangles. I can get a buffered image out of my panel like: int w = panel.getWidth(); int h = panel.getHeight(); BufferedImage bi = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); Graphics2D g = bi.createGraphics(); panel.paint(g); ImageIO.write(bi1, "png", new File("test.png")); How can I get a High Resolution image out of my panel ? (the current output image is just based on the resolution of my JPanel in my monitor) I tried AffineTransform , but it doesn't do what I need. Note that I

Java search for on-screen text field

匆匆过客 提交于 2019-11-29 08:48:47
I am trying to create a program that automatically searches for a text field on the screen and types a word repetitively into that text field. Is there any class that can find a text field? Or is there any way in which a text field can be found? Because I know that the Robot class can type text, I just need to either get the cursor onto the text field and use the mousePress() and mouseRelease() methods. Thanks Alex Lynch I can't directly give you a solution, but I messed around with some code and may be able to point you in the right direction. Java, as you probably know, runs in the JVM. This

Using PrinterJob to print an Image (Graphics2D)

删除回忆录丶 提交于 2019-11-29 08:40:26
Is there a way I can rig a PrinterJob in Java to NOT actually print to a printer so that I can get the graphics objects for each page? I tried setting the PrintService to null, but Java wouldn't allow that. This is so that I can retrieve an accurate Print Preview for the document without essentially rebuilding PrinterJobs functions from the ground-up in a different context. Here's the code for the print function in my program: public int print(Graphics graphics, PageFormat pageFormat, int page) throws PrinterException { deepCopyString = string; FontMetrics metrics = graphics.getFontMetrics

Make thread run on non EDT (event dispatch thread) thread from EDT

一曲冷凌霜 提交于 2019-11-29 07:51:50
I have a method running on the EDT and within that I want to make it execute something on a new (non EDT) thread. My current code is follows: @Override public void actionPerformed(ActionEvent arg0) { //gathering parameters from GUI //below code I want to run in new Thread and then kill this thread/(close the JFrame) new GameInitializer(userName, player, Constants.BLIND_STRUCTURE_FILES.get(blindStructure), handState); } You can create and start a new Java Thread that executes your method from within the EDT thread : @Override public void actionPerformed(ActionEvent arg0) { Thread t = new Thread

calling invokeAndWait from the EDT

邮差的信 提交于 2019-11-29 07:12:05
I have a problem following from my previous problem . I also have the code SwingUtillities.invokeAndWait somewhere else in the code base, but when I remove this the gui does not refresh. If I dont remove it the error I get is: Exception in thread "AWT-EventQueue-0" java.lang.Error: Cannot call invokeAndWait from the event dispatcher thread at java.awt.EventQueue.invokeAndWait(Unknown Source) at javax.swing.SwingUtilities.invokeAndWait(Unknown Source) at game.player.humanplayer.model.HumanPlayer.act(HumanPlayer.java:69) The code in HumanPlayer.act is: public Action act(final Action[]

Java Panel Double Buffering

北战南征 提交于 2019-11-29 07:10:18
wondered if anyone could point me in the right directon, i have developed a pong game and it needs double buffering due to flickering. Iv tryed some of the post on here to try and make it work, but im still a beginner with the swing awt suff, any help would be amazing thanks. public class PongPanel extends JPanel implements Runnable { private int screenWidth = 500; private int screenHeight = 300; private boolean isPaused = false; private boolean isGameOver = false; private int playToPoints = 10; private Padel player1,player2; private Ball ball; private Thread gameThread; private Image dbImage;

How to flip BufferedImage in java

北战南征 提交于 2019-11-29 06:37:31
I get RGB24 byte array and want to show it in Java. public void getByteArray(byte byteArray[]){ int count1 = 0; byte temp1 = 0; for (int i = 0; i < byteArray.length; i++) { //The order of RGB24 is red,green and blue.Change the //order to blue,green and red so that java can use TYPE_3BYTE_BGR to recognize it if (count1 == 0) { temp1 = byteArray[i]; count1++; } else if(count1 == 1) { //do nothing count1++; } else if(count1 == 2) { byteArray[i - 2] = byteArray[i]; byteArray[i] = temp1; count1=0; } } image = new BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR); image.getWritableTile(0, 0

AWT Window Close Listener/Event

*爱你&永不变心* 提交于 2019-11-29 05:51:33
问题 I am sorry if this is a n00b question, but I have spent way too long for this once I create the Window listener, window event, and everything else, how do I specify what method to invoke? Here is my code: private static void mw() { Frame frm = new Frame("Hello Java"); WindowEvent we = new WindowEvent(frm, WindowEvent.WINDOW_CLOSED); WindowListener wl = null; wl.windowClosed(we); frm.addWindowListener(wl); TextField tf = new TextField(80); frm.add(tf); frm.pack(); frm.setVisible(true); } I am

What is the best way to cut, copy, and paste in Java?

妖精的绣舞 提交于 2019-11-29 05:14:21
I've created an application using Swing with a text area (JTextArea). I want to create an "edit" menu, with options to cut and copy text from the text area, and paste text from the clipboard into the text area. I've seen a couple of ways to do this, but I wanted to know what the best way is. How should I implement the cut/copy/paste? Robin I would personally opt for re-using the standard cut, copy and paste actions. This is all explained in the Swing drag-and-drop tutorial: adding cut, copy and paste . The section about text components is the most relevant for you. A quick copy-paste of some