jframe

JFrame buttons that change background color of window

浪子不回头ぞ 提交于 2019-12-25 05:33:25
问题 I am trying to make a program with buttons, that when you click them, change the background color of the frame import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; import java.awt.Color; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class ColorFrame { public static void main(String[] args){ JFrame frame = new JFrame(); JPanel panel = new JPanel(); frame.setSize(300, 200); frame.setVisible(true); frame.setDefaultCloseOperation

How to create a JFrame within a Java applet or vice versa

☆樱花仙子☆ 提交于 2019-12-25 05:33:15
问题 I am trying to create a Java applet with JInternalFrames. For this I believe you need a JFrame in one form or another. I heard you could wrap your applet in a JFrame, is that best? If you could tell me what I should do I would appreciate it. TYIA -Roland /** * @(#)rebuiltgui.java * * rebuiltgui Applet application * * @author * @version 1.00 2013/1/21 */ import javax.swing.JInternalFrame; import javax.swing.JDesktopPane; import javax.swing.plaf.basic.BasicInternalFrameUI; import java.awt.event

How to create a JFrame within a Java applet or vice versa

﹥>﹥吖頭↗ 提交于 2019-12-25 05:33:06
问题 I am trying to create a Java applet with JInternalFrames. For this I believe you need a JFrame in one form or another. I heard you could wrap your applet in a JFrame, is that best? If you could tell me what I should do I would appreciate it. TYIA -Roland /** * @(#)rebuiltgui.java * * rebuiltgui Applet application * * @author * @version 1.00 2013/1/21 */ import javax.swing.JInternalFrame; import javax.swing.JDesktopPane; import javax.swing.plaf.basic.BasicInternalFrameUI; import java.awt.event

Maximizing JFrame in Java

怎甘沉沦 提交于 2019-12-25 04:50:44
问题 There have been several questions related to this, for example here and here, that both say the way to maximize a JFrame is to use the following code: frame.setExtendedState(JFrame.MAXIMIZED_BOTH); //Some answers have these lines frame.setVisible(true); //reversed However, for me, not sure if this is a windows 10 bug/java 8 bug or not, when I use this code the result is this (no matter which way round the two lines of code above are): As you can see in the image, the window is the correct

How to hide a JFrame when a JDialog class is open

强颜欢笑 提交于 2019-12-25 04:19:29
问题 I am tring to Hide a JFrame when a JDialog box opened, please how doi do this usuing the addActionListener(); 回答1: When you create a JDialog you should be specifying the JFrame as the owner of the dialog, then you can use the getOwner() method of the dialog to get the frame reference at any time. In you JDialog you should be able to use a WindowListener . In the windowOpened event you hide the frame in the windowClosed event you show the frame. 来源: https://stackoverflow.com/questions/22334749

how to properly set size of JButton with image?

青春壹個敷衍的年華 提交于 2019-12-25 04:17:12
问题 This is what I have now: This is what I want the image to look like: I have two java files, one extends JFrame and part with Jpanel looks basically ShinyButtons panel = new ShinyButtons(); panel.setLocation(10, 10); getContentPane().add(panel); another one extends JPanel with JButtons import javax.swing.*; public class ShinyButtons extends JPanel{ public static byte RED = 0; public static byte ORANGE = 1; public static byte YELLOW = 2; public static byte GREEN = 3; public static byte BLUE = 4

how to properly set size of JButton with image?

巧了我就是萌 提交于 2019-12-25 04:17:07
问题 This is what I have now: This is what I want the image to look like: I have two java files, one extends JFrame and part with Jpanel looks basically ShinyButtons panel = new ShinyButtons(); panel.setLocation(10, 10); getContentPane().add(panel); another one extends JPanel with JButtons import javax.swing.*; public class ShinyButtons extends JPanel{ public static byte RED = 0; public static byte ORANGE = 1; public static byte YELLOW = 2; public static byte GREEN = 3; public static byte BLUE = 4

Pack method called from actionPerformed functions only sometimes

允我心安 提交于 2019-12-25 04:12:29
问题 Problem Upon compiling and running my program multiple times, sometimes pack() works and the components of newGamePanel are compressed, and sometimes it doesn't work, and newGamePanel expands to fill the JFrame values set by setSize() . I have been unable to reliably reproduce either result-- it really seems to be random. Note: As I cut down on the amount of GUI formatting to have a reasonable amount of code to review, the GUI is pretty trash. However, the problem is still easy to identify.

How to add multiple classes to a single JFrame?

北战南征 提交于 2019-12-25 04:06:15
问题 So I'm trying to add multiple classes to my JFrame 'frame' using a JPanel 'panel' but it doesn't seem to have any effect. Here's my main class: import java.awt.Color; import javax.swing.JFrame; import javax.swing.JPanel; public class Frame { public static void main (String[] args) { JPanel panel = new JPanel(); panel.setBackground (Color.WHITE); panel.add (new Player()); // Class with paintComponent method. panel.add (new Terrain()); // Class with paintComponent method. JFrame frame = new

How to add multiple classes to a single JFrame?

筅森魡賤 提交于 2019-12-25 04:06:04
问题 So I'm trying to add multiple classes to my JFrame 'frame' using a JPanel 'panel' but it doesn't seem to have any effect. Here's my main class: import java.awt.Color; import javax.swing.JFrame; import javax.swing.JPanel; public class Frame { public static void main (String[] args) { JPanel panel = new JPanel(); panel.setBackground (Color.WHITE); panel.add (new Player()); // Class with paintComponent method. panel.add (new Terrain()); // Class with paintComponent method. JFrame frame = new