jframe

After calling setVisible(false) my JFrame contents are gone when calling set Visible(true)

怎甘沉沦 提交于 2019-12-02 08:24:00
问题 I'm designing a drawing program (in Java) in which text should be drawn. Since I'm doing this with kinect I'd like to use an onscreenKeyboard which I've already found. This keyboard is basically a JFrame witch JComponents in it, I dont't want to go too much in detail ... public MainFrame() { super("Draw"); setLayout(new BorderLayout()); setVisible(true); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setLocationRelativeTo(null); //so basically some standard stuff makeGUI(); this.keyboard =

JFrame not opening when a button is clicked

孤人 提交于 2019-12-02 08:18:28
I have two JFrame . public class Main extends JFrame public class ColourOption extends JPanel implements ActionListener which is then set up in a JFrame. I wanted to open the second JFrame when i click on button of first JFrame .setVisible() is not working. I also tried revalidate() , as well as invalidate() , validate() in the second JFrame. What could be the reason for it to not work? You will have to instantiate the 2nd class which has the 2nd Frame(to be shown)..and then if you call the setVisible(true) .. then it must show .. what you doing .. could you provide your button's event handler

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

倾然丶 夕夏残阳落幕 提交于 2019-12-02 08:16: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

Java GridBagConstraints gridx and gridy not working?

落爺英雄遲暮 提交于 2019-12-02 08:11:03
问题 I am trying to use the gridx and gridy constraints to position my button. But they do not work! If I change the gridx and gridy variables, nothing happens. If I change the fill to GridBagConstraints to NONE , it still does not work. Am I missing something here? import java.awt.*; import javax.swing.*; public class Window extends JFrame{ private static final long serialVersionUID = 1L; JFrame frame = new JFrame("GUI"); JTextField username = new JTextField(20); public void CreateWindow(){

JFrame - mouse click using JComponent and MouseListener

我怕爱的太早我们不能终老 提交于 2019-12-02 08:00:33
问题 Having 2 classes - public class MainClass { public static void main(String[] args) { JFrame frame = new JFrame(); .... Component mouseClick = new MyComponent() ; frame.setVisible(true); } public class MyComponent extends JComponent implements MouseListener { @Override public void mouseClicked(MouseEvent arg0) { System.out.println("here was a click ! "); } ... } I trying to set on the frame a listener for mouse click , but when I run it and then press mouse click nothing happens . How to make

Overriding the paint() method

断了今生、忘了曾经 提交于 2019-12-02 07:58:40
I've got a beginner question here that I was hoping someone with some Java experience could help me with. Currently taking an intro to OOP course focused on Java. My instructor is currently covering awt and swing, specifically the need to override the paint method so that graphics are redrawn when a window is resized, etc. I like to do as much outside reading as possible, and my concern is that the examples that my professor gives involve things that I've read are not best practices. To get to the point... I understand that it's necessary to override the paint method, but I don't know the best

Java - Move undecorated program on dual monitors

こ雲淡風輕ζ 提交于 2019-12-02 07:55:26
I made an undecorated Java program. I work on a dual monitor. But when i try to move the program on the second monitor, it doesn't works.. Here is a screenshot explanation So i have 2 Classes: Class Main.java : package undecorated; import java.awt.CardLayout; import java.awt.Container; import java.awt.Dimension; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.sql.SQLException; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel;

Cannot refer to non variable inside Action listener (Jframe)

 ̄綄美尐妖づ 提交于 2019-12-02 07:54:34
The following program's goal is to ask the user to input a resistor value, then of which the program will output the corresponding colors for each digit. This thus not include all the digits. However, that program is done, I've made an attempt to incorporate JFrame as an extra thing, except I am hung up on how to print the corresponding colors in the action listener. This line calls the specific methods, for the 3 digits then proceeds to print the colors, except how do I incorporate that and the rest of my code into my JFrame, and or ActionListener. The line System.out.println(array3[i]);/ I

Forcing JFrame to not resize after setResizable(false). Command wont work

江枫思渺然 提交于 2019-12-02 07:47:54
I have a simple Atari breakout program, and long story short, one of my powerups is to allow the user to resize the window for a few seconds, then make the window non-resizable again.Everything works fine, and the window goes from being not-resizable, to being resizable for a few seconds. What's supposed to happen, is after the few seconds are up, the window should stop accepting input for resizing the window (IE: should not be resizable). The only problem, is that whenever it's supposed to be set to non-resizable, if you keep your cursor dragging on the window to resize it, it keeps resizing.

Images In JFrame are overwriting each other not displaying both images over eachother [duplicate]

你说的曾经没有我的故事 提交于 2019-12-02 07:46:06
This question already has an answer here: Why does the first panel added to a frame disappear? 2 answers public class Board extends JFrame { public void bd() { JFrame frame=new JFrame(); JLabel background1 = new JLabel(new ImageIcon("background.png")); JLabel knight=new JLabel(new ImageIcon("knight.jpg")); frame.add(background1); frame.add(knight); frame.pack(); frame.setResizable(false); frame.setVisible(true); } } I've been having some trouble with my code when i add the knight image the background image will disappear and only the knight image appears. How would i make the images overlap or