jframe

JFrame.dispose() vs System.exit()

百般思念 提交于 2019-12-17 05:01:35
问题 What is the difference between these two methods - System.exit() and JFrame.dispose() ? If we want to close a Java Swing application when a button is clicked, which method should I use? 回答1: System.exit(); causes the Java VM to terminate completely. JFrame.dispose(); causes the JFrame window to be destroyed and cleaned up by the operating system. According to the documentation, this can cause the Java VM to terminate if there are no other Windows available, but this should really just be seen

How to hide a JFrame in system tray of taskbar

为君一笑 提交于 2019-12-17 04:54:56
问题 I'd created a JFrame and want to hide in taskbar (in windows not visible right in the bottom but hidden in the tray menu items ). Can anybody tell me how to do that? Did I need to make some changes in System settings of windows ? for example, you might have seen some download managers , team viewer , 4shared desktop , etc. are hide in taskbar's tray menu items. 回答1: import java.awt.*; import java.awt.event.*; import javax.swing.JFrame; import javax.swing.UIManager; /** * * @author Mohammad

How to hide a JFrame in system tray of taskbar

家住魔仙堡 提交于 2019-12-17 04:54:18
问题 I'd created a JFrame and want to hide in taskbar (in windows not visible right in the bottom but hidden in the tray menu items ). Can anybody tell me how to do that? Did I need to make some changes in System settings of windows ? for example, you might have seen some download managers , team viewer , 4shared desktop , etc. are hide in taskbar's tray menu items. 回答1: import java.awt.*; import java.awt.event.*; import javax.swing.JFrame; import javax.swing.UIManager; /** * * @author Mohammad

How to capture a JFrame's close button click event?

拟墨画扇 提交于 2019-12-17 03:01:12
问题 I want to call a method confirmExit() when the red close button of the title bar of a JFrame is clicked. How can I capture that event? I'd also like to prevent the window from closing if the user chooses not to proceed. 回答1: import javax.swing.JOptionPane; import javax.swing.JFrame; /*Some piece of code*/ frame.addWindowListener(new java.awt.event.WindowAdapter() { @Override public void windowClosing(java.awt.event.WindowEvent windowEvent) { if (JOptionPane.showConfirmDialog(frame, "Are you

Absolute Positioning Graphic JPanel Inside JFrame Blocked by Blank Sections

隐身守侯 提交于 2019-12-17 02:33:14
问题 I'm trying to improve my understanding of Java, particularly Java GUI, by making a puzzle program. Currently the user selects an image, which is cut up into a specified number of pieces. The pieces are drawn randomly to the screen but they seem to be covered by blank portions of other pieces, and not all of them show up, but I can print out all the coordinates. I am using absolute positioning because a LayoutManager didn't seem to work. I briefly tried layeredPanes but they confused me and

How can I scroll more than one object at the same time?

橙三吉。 提交于 2019-12-17 02:00:11
问题 New question was asked after this one, found here. I'm new to Java, but I am working on a recreation of "Flappy Bird" to learn more about java and the way that graphics are displayed. Any solutions or suggestions to any of my questions is greatly appreciated. Thanks! Right now, my program makes a random pipe and scrolls it, but I don't need it to keep scrolling when x1-3 = -83 ( this is when the pipe will be off of the screen completely and is no longer needed ). Questions How can I make my

Passing values between JFrames

吃可爱长大的小学妹 提交于 2019-12-16 22:50:48
问题 I have two Jframes where frame1 has some text fields and when a button on frame1 is clicked, I open another JFrame which contains a search box and a JTable containing search results. When I click on a result row on JTable, I want that particular values to be reflected in the frame1 text fields. I tried passing the JFrame1's object as a parameter but I have no clear idea on how to achieve this. Any help would be highly appreciated. Thanks 回答1: First of all, your program design seems a bit off,

How to make a JFrame Modal in Swing java

孤街浪徒 提交于 2019-12-16 21:28:10
问题 I have created one GUI in which I have used a JFrame. How should I make it Modal? 回答1: Your best bet is to use a JDialog instead of a JFrame if you want to make the window modal. Check out details on the introduction of the Modality API in Java 6 for info. There is also a tutorial. Here is some sample code which will display a JPanel panel in a JDialog which is modal to Frame parentFrame . Except for the constructor, this follows the same pattern as opening a JFrame . final JDialog frame =

Unresponsive KeyListener for JFrame

狂风中的少年 提交于 2019-12-16 19:59:49
问题 I'm trying to implement a KeyListener for my JFrame . On the constructor, I'm using this code: System.out.println("test"); addKeyListener(new KeyListener() { public void keyPressed(KeyEvent e) { System.out.println( "tester"); } public void keyReleased(KeyEvent e) { System.out.println("2test2"); } public void keyTyped(KeyEvent e) { System.out.println("3test3"); } }); When I run it, the test message comes up in my console. However, when I press a key, I don't get any of the other messages, as

opening JFrame from applet

百般思念 提交于 2019-12-16 18:04:20
问题 So I programmed am applet that makes a ball roll in circles for ever, and I wanted to make the user decide what speed the circle should roll in, but something failed when I added the JFrame: applet(the stop,destroy and update do not appear because they aren't important, and in start there is nothing): public class Main extends Applet implements Runnable{ private Image I; private Graphics GfU; int ballX, ballY=249; static int radius=20; double Memory; int changeY ,changeX=1; Speed S = new