jframe

Painting Graphics2D in a JFrame

為{幸葍}努か 提交于 2019-12-23 22:09:02
问题 I'm making a 2d vertical shooter game, in which everything is coded (and working) but the graphics. I have not used the Graphics classes before, so this is all new to me. The following is the code I use to paint everything to the JFrame: public void paintAll() { Graphics h = new Graphics2D(); for(Bullet j : GameState.getEnBullets()){ h.drawImage(j.getImage(),j.getX(), j.getY(), null);} for(Enemy j : GameState.getEnemies()){ h.drawImage(j.getImage(),j.getX(), j.getY(), null);} for(Bullet j :

JFrame.getLocationOnScreen() for minimized window

倖福魔咒の 提交于 2019-12-23 20:19:03
问题 I call getLocationOnScreen() from JFrame in my Swing application. If JFrame is minimized -32000, -32000 is returned. It is expected: Location Coordinates On Computer Showing X=-32000, Y=-32000 But I need to know the location of the window before it was minimized or would be the location if it is maximized again without actual maximizing it. Because I need to position JDialog relatively to the JFrame even though it is minimized. Possible solution: Add WindowListener to JFrame and on

Java Odd pack() Behavior

时光怂恿深爱的人放手 提交于 2019-12-23 19:44:50
问题 My main issue is with the following piece of code when setting up a JFrame: public Frame(){ JPanel panel = new JPanel(); add(panel); panel.setPreferredSize(new Dimension(200, 200)); pack(); // This is the relevant code setResizable(false); // This is the relevant code setVisible(true); } With the following print statements we receive faulty dimensions for panel: System.out.println("Frame: " + this.getInsets()); System.out.println("Frame: " + this.getSize()); System.out.println("Panel: " +

How can I close a JFrame by click on a button?

落花浮王杯 提交于 2019-12-23 18:53:14
问题 I would like to have a button in my window such that if I click it (button) the window is closed. I found out that I can close a window in the following way: referenceToTheFrame.hide(); //hides the frame from view refToTheFrame.dispose(); //disposes the frame from memory But if I do this way, compiler complains: Note: myProgram.java uses or overrides a deprecated API Note: Recompile with -Xlint:deprication for details. Do I do something unsafe? 回答1: The recommended way is to use:

SwingUtilities.windowForComponent(JFrame) returns null

倖福魔咒の 提交于 2019-12-23 18:02:18
问题 frame is the only JFrame in my Swing app. Since JFrame extends Window I have believed from description and method name that the code should return the frame itself. SwingUtilities.windowForComponent(frame) public static Window windowForComponent(Component aComponent) Return aComponent's window But it returns null , because implementation is like this public static Window windowForComponent(Component c) { return getWindowAncestor(c); } public static Window getWindowAncestor(Component c) { for

JFileChooser showing outside Full screened JFrame

余生颓废 提交于 2019-12-23 17:25:42
问题 import java.awt.DisplayMode; import java.awt.GraphicsDevice; import java.awt.GraphicsEnvironment; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFileChooser; import javax.swing.JFrame; import javax.swing.JPanel; public class Sample { public static String audioName; /** * @param args the command line arguments */ public static void main(String[] args) { final JFrame frame = new JFrame(); frame.setTitle("Frame"); frame

Retrieve Data from MySQL DB and show in JTable

吃可爱长大的小学妹 提交于 2019-12-23 16:01:33
问题 I am using the following code for retrieving the data from MySQL Database. The code connects to the database properly. My problem is in retrieving the data from MySQL DB and showing it in the JTable. package student; import java.awt.*; import javax.swing.*; import java.awt.*; import java.sql.*; import java.util.*; import javax.swing.*; import java.awt.event.*; import javax.swing.table.*; public class student1 extends javax.swing.JFrame { // public Connection Conn; Vector data = new Vector() ;

Java Swing: dispose() a JFrame does not clear its controls

陌路散爱 提交于 2019-12-23 15:40:20
问题 I have a closeWindow() method which uses dispose() for the current JFrame to close down. When I show the window again, the controls (textboxes, lists, tables etc.) still have their previous values in place that were there when I dispose():d the frame... Why is that? Is there another way to completley close and clear a frame? This is the code that another JFrame uses to show the other window, am I doing something wrong here? @Action public void showAddProductToOrderView() { if

Iterate through all objects in Jframe

久未见 提交于 2019-12-23 15:04:59
问题 I have a simple question. I have a project made with javax.swing.JFrame. I would like to iterate through all the objects that i Have added in the Jframe. Is that possible, how can I do it? 回答1: this will iterate through all components inside your JFrame's contentPane and print them to the console: public void listAllComponentsIn(Container parent) { for (Component c : parent.getComponents()) { System.out.println(c.toString()); if (c instanceof Container) listAllComponentsIn((Container)c); } }

Is there a way to tell if a JFrame is “Maximised” (MS Windows) [duplicate]

﹥>﹥吖頭↗ 提交于 2019-12-23 12:28:29
问题 This question already has answers here : JFrame in full screen Java (12 answers) Closed 6 years ago . I've been Java applications on OS X, and haven't had the opportunity to fully test in different places. There are 2 different JFrame s. The second is loaded exactly in place of the first one, and as such needs to have its size and location set to the same as the first. This works fine, but I noticed a lot of Windows users seem to maximise the first window. When the second JFrame loads, it has