awt

best example for programmatically creating SplashScreen with text

蓝咒 提交于 2019-11-28 02:14:28
I need to create a SplashScreen programmatically and add text to it (and change it). Most examples work with thecommand line parameters. Are there solutions working without? Guillaume Polet You can use an undecorated dialog with a background image and a progress bar while loading stuffs in a SwingWorker . When done, hide the dialog and start the UI as usual. Components added to the dialog/splashcreen must be non-opaque in order to "see" the background image. Here is a working example: import java.awt.BorderLayout; import java.awt.Color; import java.awt.Frame; import java.net

How to rotate a rectangle after reaching specified position?

落爺英雄遲暮 提交于 2019-11-28 02:14:05
I would like to rotate a rectangle when e.g. y position achieve specified position. I would like to behave a rectangle as a car on a junction - just turn e.g. right. I prefer just rotate and continue. A draft code looks like that: Graphics2D g2d = (Graphics2D) g.create(); g2d.setPaint(new Color(150, 150, 0)); //1. when rectangle achieve 500 on y dimension just rotate left/right if(y==500) { _rotate = true; g2d.rotate(Math.toRadians(90.)); } if(_rotate) { //if rotate, continue way on x dimension ++x ; g2d.fillRect(x, y, 20, 40); } else { //else go to the north --y; g2d.fillRect(x, y, 20, 40); }

Once exported, java cannot find/draw images

浪尽此生 提交于 2019-11-28 02:12:52
Hello stackoverflowites, I am in the process of developing a 2d game, and when I run it inside of eclipse, my program loads all of it's images and resources fine. However, I am using the not-necessarily-recommended way of creating my images and image icons, which is shown below: bannerLogo.setIcon(new ImageIcon("/res/client/BannerHeader.jpg")); Now, when exporting to a jar, it does not show the image (which is expected since im not using the correct way.) I searched for the correct way to do it, which I found was: URL imgURL = getClass().getResource("/res/client/BannerHeader.jpg"); Image

Getting High Resolution Image from JPanel

拥有回忆 提交于 2019-11-28 02:12:37
问题 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

Show HTML file in JEditorPane

被刻印的时光 ゝ 提交于 2019-11-28 02:04:48
I am working on a Swing application in which I have to show HTML files. I am using JEditorPane control for it. It is showing the content of HTML file but not in the same format as originally in the actual HTML file. JEditorPane does not support the object element. Rather than loading the object file its just showing ? . Is there any other inbuilt control in Swing to browse the HTML file rather than JEditorPane ? I am using the following code: JEditorPane HtmlPane= new JEditorPane(); File file1= new File("path of the file"); HtmlPane.setContentType("text/html"); HtmlPane.setEditable(false);

Java AWT Threads

妖精的绣舞 提交于 2019-11-28 02:04:23
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 list. In its current state the UI is no longer not responding, however the processEvents isn't adding

Using PrinterJob to print an Image (Graphics2D)

折月煮酒 提交于 2019-11-28 02:01:56
问题 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

mouse motion listener only in one direction

怎甘沉沦 提交于 2019-11-28 01:45:23
i have been working on mouse motion listener in Java couldn't sort it out completely because i want the object to move towards the direction where ever on the screen the mouse is pointed at but unforunately when the mouse is inside the applet window, the object moves only towards a single direction. Here is my code below.. import java.awt.*; import java.awt.geom.*; import java.util.*; import java.applet.*; import java.awt.event.*; import javax.swing.*; public class MouseOver extends Applet implements KeyListener, MouseListener, MouseMotionListener { private int[] Xpoints = { 0, -5, 5 };

Closing a Web Browser for a specific URL from the java program

旧街凉风 提交于 2019-11-28 01:36:23
I want to close an open web browser/browser tab for a specific URL from the java program. I am able to open the URL in internet explorer using the Desktop API from java. Below is the code snippet to open the browser in IE java.awt.Desktop desktop = java.awt.Desktop.getDesktop(); desktop.browse(new java.net.URI("http://www.xyzz.com")); Now When I run the program again I want to make sure that there is no already instance where the above URL is opened in the browser. If it is so, close it and open it again in a new TAB or Browser window. This may look little weird requirement. I know the basic

Java Double Buffering

落花浮王杯 提交于 2019-11-28 01:23:40
I'm working on a project and I've read up as much as I can on double buffering in java. What I want to do is add a component or panel or something to my JFrame that contains the double buffered surface to draw to. I want to use hardware acceleration if possible, otherwise use regular software renderer. My code looks like this so far: public class JFrameGame extends Game { protected final JFrame frame; protected final GamePanel panel; protected Graphics2D g2; public class GamePanel extends JPanel { public GamePanel() { super(true); } @Override public void paintComponent(Graphics g) { g2 =