jframe

How to change Background color when i click a button

爷,独闯天下 提交于 2019-12-13 07:17:20
问题 My Problem is only just a little part that change color.I want to change the whole background when i click those buttons.I search already in google nothing happens. I Use Panel but it seems not only a little part that it can changes i want a whole background. import java.awt.event.MouseListener; import javax.swing.JOptionPane; import java.awt.event.*; /** * * * @author Christopher Porras * @Version 0.1 * @Doing GUI */ public class Button extends JFrame { private JButton bred; private JButton

how to randomly set jbutton color from array of colors?

不问归期 提交于 2019-12-13 07:12:47
问题 i have the following code for jframe that is 25 buttons and i am trying to use my array of colors to make each button one of the colors randomly. import java.awt.event.*; // Needed for ActionListener and ActionEvent import javax.swing.*; // Needed for JFrame and JButton import java.awt.Color; import java.awt.Graphics; public class ColorToggleGui extends JFrame implements ActionListener { // This stores all buttons JButton[][] buttons; //Stores colors Color[] colors; public ColorToggleGui

JFrame losing its structure and looks on resizing after button click

北城以北 提交于 2019-12-13 07:11:09
问题 I have the following code to run a simple number guessing program on the click of a button: public class test3 implements ActionListener { public void create() { Dimension s=new Dimension(400,400); JFrame l=new JFrame(); l.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); l.setSize(s); l.setResizable(true); Dimension s1=new Dimension(400,200); JPanel me=new JPanel(); JPanel ne=new JPanel(); JLabel kingsman=new JLabel ("GUESS THE KING'S NUMBER!"); kingsman.setFont(new Font("Serif", Font.BOLD, 45

What is the cause and resolution of java.lang.ExceptionInInitializerError error when trying to open a JFrame in another Thread?

守給你的承諾、 提交于 2019-12-13 06:48:09
问题 I'm trying to creating a test class to open a JFrame. In order to stop the window from closing the moment the main thread finishes I added the code to open up the window in another thread. Every time I run the application I get the following exception: Exception in thread "Test Thread" java.lang.ExceptionInInitializerError at java.lang.Runtime.addShutdownHook(Runtime.java:192) at java.util.logging.LogManager.(LogManager.java:237) at java.util.logging.LogManager$1.run(LogManager.java:177) at

Why does my JButton appear the full size of the JFrame?

青春壹個敷衍的年華 提交于 2019-12-13 06:27:16
问题 I am a newbie, I have a question. I am trying to use Eclipse to write a Java windows application, in which I will have a main window, which will contain several things, like a dashboard sort of thing, and it will have buttons, for example to add a record to a database, and this button when pressed, will open a new relevant window on top. I tried to start, I wrote this code in Java, and for some reason, the button is in the size of the frame...full screen ! How do I fix it ? Can you suggest me

Netbeans & Java - using getResource() - returning null

本小妞迷上赌 提交于 2019-12-13 06:08:17
问题 I am trying to load a background to my JFrame using the following code: image = ImageIO.read(getClass().getResourceAsStream(s)); where for s I have tried: /res/Background/bg_menu.gif Background/bg_menu.gif /Background/bg_menu.gif res/Background/bg_menu.gif My res folder is in the project root like so: Game -- src -- res I have done the following: Project Properties -> Sources -> Add Folder -> res The error I'm getting returned is: java.lang.IllegalArgumentException: input == null! at javax

How do I prevent my JFrame from freezing?

你离开我真会死。 提交于 2019-12-13 05:48:21
问题 So my problem is that sometimes when I press the JButtons in my JFrame, the whole frame freezes and can only be exited by terminating it through Eclipse. All of the JButtons have action listeners and I don't understand why they sometimes cause the JFrame to freeze and at other times do not . Any help is appreciated. Here is my code: //objects static JFrame frame = new JFrame("Flash cards revision"); static JButton beginButton = new JButton(); static JButton continueButton = new JButton(

how to change the contents of a JFrame after it has been displayed (java)

做~自己de王妃 提交于 2019-12-13 05:41:49
问题 I am designing a GUI to emulate a Nurikabe game (description here). I basically have two JPanels, and when one of buttons in the control panel (panel 2) is clicked, I want to change the buttons in the game panel (panel 1). Panel 1 has 36 buttons, either non-clickable buttons displaying numbers or clickable blank buttons, all contained in a GridLayout. Panel 2 has three buttons, new puzzle, check puzzle, and reset current puzzle. The problem I am running into is that I cannot figure out how to

JPanel Smaller than JFrame

梦想的初衷 提交于 2019-12-13 05:12:57
问题 I never actually create a JPanel , but I seem to be having issues with it inside of my JFrame . my "fball" object goes off the screen at random parts and I cannot figure out why for the life of me. I don't actually create a JPanel and use the methods to set it up, and dont know how to do that since my class that extends JPanel only creates an image. If you help me I will love you forever. (I apologize for my lacking of knowledge in java) Here is the code for my Window Class: package game

Live updating one JtextArea from another JtextArea

柔情痞子 提交于 2019-12-13 05:07:55
问题 I am attempting to write a program that will display two Jtextareas, both of which are editible. The goal is to when you edit textAreaRom (entering a roman numeral) the second area (textAreaArab) will display the Arabic Number equivalent. But the thing is I can not get this to happen in real-time. I have read about using DocumentListeners but, this is one of the first times I have ever done GUI programming and I am not to sure on how I would implement it. Anything helps. I am new to GUI stuff