jframe

How do I make Java wait for a method to finish before continuing?

只谈情不闲聊 提交于 2019-12-02 03:45:46
So my problem is that I need these methods to run one after another but I cannot work out how to make the methods wait before being run. Any help is appreciated. Thank you. Here is my code: public void startMoving() throws InterruptedException { moveEnemy("right",3); wait(); moveEnemy("down",3); wait(); moveEnemy("right",2); wait(); moveEnemy("up",1); wait(); moveEnemy("right",2); wait(); moveEnemy("up",2); wait(); moveEnemy("right",2); wait(); moveEnemy("down",4); wait(); moveEnemy("left",1); wait(); moveEnemy("down",2); wait(); moveEnemy("right",3); wait(); moveEnemy("up",2); wait();

Serializing a JFrame and sending via network

寵の児 提交于 2019-12-02 03:28:07
What I'm trying to do is to send a JFrame through sockets. The problem is after I send the form and press the button to view it I get the below exception. package ds3; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.net.ServerSocket; import java.net.Socket; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.JFrame; public class SerializationApp extends JFrame { private DataForm dataForm = new DataForm(); private int serverPort = 15000; private ServerSocket serverSocket; public SerializationApp() { try

How can save some Objects, directly after the User has closed the Applications JFrame, but before the Program exits?

倾然丶 夕夏残阳落幕 提交于 2019-12-02 03:27:38
问题 Good day! I'm developping a small Java Application with NetBeans IDE that extends JFrame. I implemented several ways to close the App, for example pressing Ctrl-Q and pressing the X of the JFrame. But before the actual closing I'd like the program to execute some additional code for me, to save some objects the application needs to reuse the next time it starts up. What is the best way to change the entire programs closing behavior? I'm thinking about overriding/replacing the

Downloading file/files in Java. Multithreading, this works?

时间秒杀一切 提交于 2019-12-02 03:18:16
First, everyone needs to know i'm relatively new to Java coding. To be more precise i'm completely new to Object Oriented Programming. To the question. I am trying to create a download class that updates a progress bar it was given to show its progress. And possibly anything else I decide to give it in the future to update. The issue currently is that, in my head, this shouldn't work. I can do anything i want on the "main" method and the GUI is still responsive and quick. In my experience in past programming, this is not possible unless i thread the GUI. Why is this? Since it works, is this ok

How to show/hide an image attached to a Jlabel after a Jbutton is clicked?

时光怂恿深爱的人放手 提交于 2019-12-02 02:43:18
问题 I'm new to programming world, and I need some help. I will try to be as clear as possible. This is my current situation: I'm programming a simple game. On a Jframe, I've added a Jlabel on which I attached an image. I've also added a Jbutton on the Jframe. I would like that when I click on the Jbutton, the image appears and on the next click the image hides. How could I do it? Thanks in advance and excuse me for the possible english mistakes. EDIT Following some instructions given by people, I

How to show/hide an image attached to a Jlabel after a Jbutton is clicked?

馋奶兔 提交于 2019-12-02 01:29:38
I'm new to programming world, and I need some help. I will try to be as clear as possible. This is my current situation: I'm programming a simple game. On a Jframe, I've added a Jlabel on which I attached an image. I've also added a Jbutton on the Jframe. I would like that when I click on the Jbutton, the image appears and on the next click the image hides. How could I do it? Thanks in advance and excuse me for the possible english mistakes. EDIT Following some instructions given by people, I've reached this point: button.addActionListener(new Actionbox()); final class Actionbox implements

Mechanisms of setText() in JTextArea?

谁说我不能喝 提交于 2019-12-02 01:03:20
I try to show some text in my JTextArea in runtime. But when I use a loop of setText to show text in order, it only show the text of the last loop Here is my code: private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { for (int i=0;i<10;i++) jTextArea1.setText("Example "+i); } I want it to show "Example 1", "Example 2",..,"Example 9" . But it only show one time " Example 9 " Anyone can explain it for me?? setText does just that, it "sets the text" of field to the value your provide, removing all previous content. What you want is JTextArea#append If you're using Java 8, another

How to resize frame dynamically with Timer?

萝らか妹 提交于 2019-12-02 00:41:59
I'm trying to resize a window dynamically using a Timer object, but not succeeding... I set the preferred size of the panel in the constructor, which sets the size of the window nicely, though only once. The preferred size changes after the program is initialized, but the window size stays the same. Why? Because the constructor is initialized only once and therefore isn't affected by the size change? If so, how could I get around this to resize the window in real-time? I know this won't solve the problem in the exercise given in the beginning comments, so please ignore that :-) /* * Exercise

Switching between JPanels

折月煮酒 提交于 2019-12-02 00:40:36
问题 I'm trying to make a game. There's several different screens in the game such as a main menu, and the actual game screen. Each of these is a separate jpanel extension. I have added each of them to my JFrame which is a class called Game. In my game class I have the following methods public void addPanel( JPanel p ) { panels.add( p ); // An array of all the different panels I need this.getContentPane().add( p ); } public void switchToPanel( JPanel p ) { for ( JPanel somePanel : panels ) {

How to make a modal JFrame? [duplicate]

旧城冷巷雨未停 提交于 2019-12-02 00:25:24
Possible Duplicate: How to make a JFrame Modal in Swing java I have 2 JFrames one is the main JFrame and the other one is a sub JFrame, and I'm trying to make the main JFrame inaccessible to user interactions when I display the sub JFrame. How to make a modal JFrame? Don't. Use a modal JDialog -- that's precisely what they're for. You understand of course that a JDialog can hold a complex GUI, as complex as any held by a JFrame. We often run into posts like these by folks who use a GUI-builder such as NetBeans to help them create their GUI's, and since the second window's code was created by