jframe

Java how and when exactly is the paint() method called?

我怕爱的太早我们不能终老 提交于 2020-01-07 06:17:57
问题 I have been told many times that the paint() method will be called as and when required when I extend my class to JFrame but for eg. in the code the paint method is not being called and I don't see any rectangle drawn. I even tried to call paint method inside the constructor (which I created) and then creating an obejct for the class in main but I got a NullPointerException import java.awt.Graphics; import javax.swing.JFrame; public class MyFirstDrawing extends JFrame { /** * */ private

JComponents are not showing up on JPanel

谁说我不能喝 提交于 2020-01-07 03:00:52
问题 My JComponents aren't showing up on my JPanel for some reason. Here's my code: MAIN CLASS import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics; import java.awt.Graphics2D; import javax.swing.JFrame; import javax.swing.JPanel; // Main Class - executes the game public class Main extends JFrame { public static int WIDTH = 800, HEIGHT = 800; private JPanel jp; private Dimension d; private Snake s; private Food f; public Main() { setTitle("Snake"); setSize(WIDTH, HEIGHT);

Pass JButton to Utility class. Acceptable?

馋奶兔 提交于 2020-01-06 20:01:24
问题 I have a JFrame that does things. I have a JButton hidden from view in that JFrame. In a SwingWorker i have a utility Class such as checkNDownloadFile of which I pass a JButton to it. So it can make it visible/usable when the process completes. My question is, is this acceptable. I dont know of any other method to do this effect. (Keep in mind the checkNDownloadFile class is all static. Its only needed/ran once.) Sudo Code -----------------------------------------------------------------

Netbeans template AboutBox Java

主宰稳场 提交于 2020-01-06 20:00:01
问题 I used this code previously in netbeans 6.9.1 but it does not seem to work in 7.1.1, it underlines .getApplication() with the hint "cannot find symbol". How can I make this work again? JFrame mainFrame = TestProject.getApplication().getMainFrame(); AboutBox newAboutBox = new AboutBox(); newAboutBox.setLocationRelativeTo(mainFrame); TestProject.getApplication().show(newAboutBox); Here is a similar question, but the solution does not work. 回答1: Have you checked the static method getApplication(

Java Action Listeners in a different class not working

时间秒杀一切 提交于 2020-01-06 19:45:33
问题 I've been working with JFrame recently and had a simple login, register and popup frames work when I had them in a single class. I wanted to make it nicer and not all packed inside one class so I made a class for the frames, buttons, panels, variables and the main class. My problem is that The frames themselves are working fine and loading up and displaying, but the ActionListeners on the buttons aren't working at all. Nothing changes when I hit a button etc. I'm fairly new to Java and very

Java - How to force buttons to bottom of panel after others have been removed?

这一生的挚爱 提交于 2020-01-06 19:41:26
问题 I'm making a very simple game in Java where when you press a button on your keyboard, the corresponding button is removed, however I want the buttons to all be pushed to the bottom accordingly when one is removed. I'm not sure where I should do this in the code or what method to use. Is there a way to sort of pack the frame so that everything is anchored to the bottom? Here is a picture of the program when it is ran: And when I press the 3rd button, I want the blocks above it to fall down on

Determine height of screen in Java

孤人 提交于 2020-01-06 19:31:07
问题 I have my JFrame in full screen mode using the following: setExtendedState(JFrame.MAXIMIZED_BOTH); setUndecorated(true); And I want to know the height. Note that Toolkit.getDefaultToolkit().getScreenSize() does not work because I'm on a Mac and the real height should exclude the height of the Mac bar thing at the top of the screen. And in the case of Windows, for example, the height should exclude the start bar. Hence, I want to know the true height of the window space I have. 回答1: I use this

How to show result in JFrame Form if data source is a XML file?

99封情书 提交于 2020-01-06 17:28:32
问题 Here is the codes: I write XML file to a comment under this post. Developer: public class Developer { private String id; private String name; private String surname; private int age; public Developer(String id, String name, String surname, int age) { this.id = id; this.name = name; this.surname = surname; this.age = age; } public String getId() { return id; } public String getName() { return name; } public String getSurname() { return surname; } public int getAge() { return age; } } The

How to show result in JFrame Form if data source is a XML file?

一世执手 提交于 2020-01-06 17:28:07
问题 Here is the codes: I write XML file to a comment under this post. Developer: public class Developer { private String id; private String name; private String surname; private int age; public Developer(String id, String name, String surname, int age) { this.id = id; this.name = name; this.surname = surname; this.age = age; } public String getId() { return id; } public String getName() { return name; } public String getSurname() { return surname; } public int getAge() { return age; } } The

Why is my JFrame just a black window?

冷暖自知 提交于 2020-01-06 14:41:07
问题 My code is this, when I run it I just get a black window and I have no idea why. Thanks for any feedback. Its supposed to print out a picture, and eventually make it move. package assignment04; import java.awt.BorderLayout; import java.awt.Dimension; import javax.swing.JFrame; import javax.swing.JPanel; public class GoLDriver { public static void main(String[] args) { GoLModel model= new GoLModel(); JFrame frame = new JFrame(); JPanel panel= new JPanel(); panel.setLayout(new BorderLayout());