Make 2 JFrames work one after the other

Hello,
I have JFrame with a button and after a clicking on that it opens a new JFrame which takes inputs from user and saves them in a file;Until I finish the file writing in second frame, the user should not be able to edit anything in first frame,frame should be visible.The code for creating the frames is:
import javax.swing.JFrame;
import javax.swing.JButton;
public class FrameTest extends JFrame{
     private JButton button=new JButton("Click");
     public FrameTest() {
          button.addActionListener(new java.awt.event.ActionListener(){
               public void actionPerformed(java.awt.event.ActionEvent ae){
               new ChildFrame();     
          getContentPane().add(button);
          pack();
          setVisible(true);
     public static void main(String args[]){
          new FrameTest();
import java.awt.Event;
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JTextField;
public class ChildFrame extends JFrame {
     JButton button=new JButton("Save");
     JTextField name=new JTextField(10);
     java.io.FileOutputStream fout;
     public ChildFrame() {
          button.addActionListener(new java.awt.event.ActionListener(){
               public void actionPerformed(java.awt.event.ActionEvent ae){
                    try{
                         fout=new java.io.FileOutputStream("c:/TestFile.txt");
                         fout.write(name.getText().getBytes());
                         fout.close();
                    catch(java.io.FileNotFoundException fnf){
                    catch(java.io.IOException ioe){
          getContentPane().setLayout(new java.awt.FlowLayout());
          getContentPane().add(name);
          getContentPane().add(button);
          pack();
          setVisible(true);
}

You can add a boolean variable (initialized to false) to the child frame that holds true once the file operation is complete. Let's say we call it: FileTransferComplete=false;
fout=new java.io.FileOutputStream("c:/TestFile.txt");
fout.write(name.getText().getBytes());
fout.close();
FileTransferComplete=true;
/code]
you can add a method to the child frame to return this status
and set the main frame's setVisible property to this value likethis.setVisible(ChildFrame.isFileTransferComplete());
You'll probably have to cater for the likely scenario that a IO exception is called in which case FileTransferComplete never becomes true.

Similar Messages

  • I have a long numbers document, that I'd like to make more print friendly. It is a list of my DVD's that I just listed one after the other (1-200) when I tried to print it, it would be 18 pages, can I change it to be more like columns side by side to save

    I have a long numbers document, that I'd like to make more print friendly.
    It is a list of my DVD's that I just listed one after the other (1-200) when I tried to print it, it would be 18 pages,
    can I change it to be more like columns side by side to save paper?

    S,
    I assume that you also have Pages on your computer (or some other capable WP program). I also assume that you have eliminated any unnecessary columns, so you have a 1-column table in Numbers.
    When it comes time to print, Copy the entire Table: Click on the table name in the Sheets Pane and Command-C.
    Switch to Pages, open a blank WP template and set the number of columns to 3 or so. With the Text Insertion Cursor flashing on the first line of the first column of the blank template, Command-V. Your table should paste into the Pages document as an Inline Object and will Wrap on the page as you desire. Then Print in Pages.
    Jerry

  • Formatting on several websites is incorrect. Everything loads on the left hand side one after the other. Clearing 'Everything' from history works temporarily...

    Formatting on several websites is incorrect. Everything loads on the left hand side one after the other. Clearing 'Everything' from the search history fixes the problem temporarily, for a very short time. I've been using Firefox for years and I've only recently been getting this problem. It's been happening on both Windows 7 and 8. I'm not sure if this has anything to do with it but this problem has only arose since I upgraded to fiber power broadband, 100Mb. The link below is just one of many.

    Thanks for the advise. I already tried Safe Mode and the problem persists though...

  • Editing pictures from a file one after the other

    I am not sure pow to ask the question. I just upgraded to Photoshop 10 from 3.  Now, when I am editing a few days worth of pictures one after the other, I go to open the next file (picture) the computer takes me back to the top (first one listed) each time.  Many times I am editing over 100 pictures in the file, and now have to scroll down each time and that takes forever. I have to remember what number picture I was on.  In my earlier version, the compiter "held" the spot where I was so  it was easy to select trhe next picture to edit.  Any words of wisdom to make this work lije it did earlier?  THANKS.
    Dick [email protected]

    Hi ,
    If you are talking about the issue related to Opening File Browser of PSE Editor File menu >> Open.
    Please USE organizer.
    First import all your images of that particular folder to your catalog and then intiitalte your workflow from Organizer to edit them in the Editor.
    Organizer scolling bar will not move after editing by PSE Editor.

  • Play local videos one after the other

        Hi - I'm setting up 10 videos locally in Dreamweaver to play one after the other.  By local I mean everything is on a the computer and you just open up the HTML page in Chrome and it works.  When the HTML opens in Chrome, I got the first video to auto play and loop too.  But after video #1 ends, I need it for the 2nd video to start, then third, and so on until the 10th is over then it goes back to #1 again.
    The code I have on the local HTML page is and it works for one video is:
    <video width="720" height="406" controls autoplay loop>
      <source src="1E.mp4" type="video/mp4">
      <object data="1E.mp4" width="720" height="406">
      </object>
    </video>
    ...but I just can't figure out how to get the other 9 videos in there so they play after #1 then loop back to #1 again.
    Does anyone have any idea how to do this?  Thanks.

    Hooking up the computer to the TV is the easy part :-)
    I tried getting a windows media playlist set up and although I like that player, it seemed difficult to make a simple playlist in it.  Unless I wasn't reading the instructions correctly, I couldn't get it to work.
    I also like QT but it seems like you need to buy the QT Pro version as the basic player doesn't seem to allow for playlists (unless i'm missing something).
    If I could get either of the above to work and play these videos locally over and over I'm set.  But because I had problems with WMV and you have to pay for QT Pro that's why I'm trying to build something locally in DW.

  • Why am I getting an error when I place two OAM files one after the other in different pages?

    Why am I getting an error when I place two OAM files one after the other in different pages? They do not load or play correctly.  They are both configured to play automatically with a .125 second delay and both have a white rectangle "poster" over for a hidden effect.

    Thanks for the idea, Scott! I initially tried your idea, but my OAM files were still not loading correctly.  I tried other combinations of OAM files, and it seems to work fine.
    Back to my original OAM files: I made sure that my elements in my Edge Animate project had different names. I originally copied parts of some elements from one to another, and I think it was confusing to DPS to read it. 

  • Podcasts - getting them ALL to play (one after the other)...

    I have several podcasts on my ipod (video and audio). How can it to play them in succession (the first one ends, the 2nd postcast starts, and so on..). I have CNN news for a video podcast. I watch one day of news. It ends then stops and brings me back to the main menu of the podcast. I have to scroll down and goto the 2nd day and watch. Then repeat. I'd like to just watch them all in row, one after the other. How can I do this???
    My own   Windows XP  

    I started doing this some time ago and it worked very well. However, this last week or so when I go to Music:Playlist:Podcast and play (not select) it doesn't play now. Before it would go through one podcast after another. I may have changed a shuffle/repeat setting but the other playlists work. I recently installed iQuiz a great 'game' but there were reports of it changing settings.
    Any thoughts? David

  • Having Images load one after the other

    Hi, i am currently creating a tetris game and was wondering how exactly i would go about creating some sort of a timer that would allow me to have my images load one after the other and fall at specified interval. I appreciate any help. here is my code:
    import javax.swing.*;
    import java.awt.*;
    public class Tetris extends JPanel {
    Image image; // Declare a name for the Image object.
    Image image1;
    Image image2;
    Image image3;
    // Create a constructor method
         public Tetris(){
    super();
    // Load an image file into the Image object. This file has to be in the same
    image = Toolkit.getDefaultToolkit().getImage("Block1.png");
    image1 = Toolkit.getDefaultToolkit().getImage("Block2.png");
    image2 = Toolkit.getDefaultToolkit().getImage("Block3.png");
    image3 = Toolkit.getDefaultToolkit().getImage("Block4.png");
    // The following methods are instance methods.
    /* Create a paintComponent() method to override the one in
    JPanel.
    public void paintComponent(Graphics g){
    // Draw our Image object.
    g.drawImage(image,30,30,30,30, this);
    //g.drawImage(image1,30,30,30,30, this);
    //g.drawImage(image2,70,70,70,70, this);
    //g.drawImage(image3,80,80,80,80, this);
         public static void main(String[] args) {
         JFrame frame = new JFrame("Tetris");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(200,500);
    Tetris panel = new TetrisDemo();
    frame.setBackground(Color.WHITE);
    frame.setContentPane(panel);
    frame.setVisible(true);
    }

    Can you clarify what you mean by Images loading one after the other? For this, you might want to take a look at MediaTracker
    If by "fall", you mean having blocks which drop periodically, you should check out javax.swing.Timeer

  • Want podcasts in Playlist to play one after the other

    Friends:
    I want to have all the podcasts in my playlist play one after the other. I read in some other post about creating an on-the-go playlist using the "enter" button.
    Can someone please explain what this means and how to do it? I'm a bit lost with just that information.
    Thanks,
    Migs

    Well...repeat will make the entire list play over and over. I understood that you wanted a list of podcasts where you could start the first one and have the list play through without stopping after each one.
    Oftentimes, people will put their podcasts into a playlist and can't figure out why the first one plays and then stops, not automatically continuing on to the next podcast. The default on iTunes will set podcasts to Skip When Shuffling. So, if a user has a tendency to use the Shuffle feature, then their playlist is going to show 1 of 1, play one podcast and then stop. To avoid this, you need to select the podcasts and deselect Skip When Shuffling. (And make sure that Shuffle is turned off.)
    Does that make sense?
    Diane Wordsmith

  • How do I get very short movies to play one after the other?

    How do I get very short movies to play one after the other?
    I have some video tutorials to show me how to use software on the Mac.
    When a short 4 min. video is finished - I have to double click the next one.
    There must be a way to have continuous playing of movies back to back...
    I've looked - I am sure it's obvious...
    Help please.  Thanks!

    make them type 'Music Video', and add info on artist to group them, then play them.

  • Making PodCasts play one after the other...?

    They will repeat indivigually (sp?) but not one after the other.
    Any help would be nice!

    If you create a playlist of the podcasts that you want to listen to, then play the playlist, that might work....it does on the iPod.

  • How to Glow LEDs in Sequence (One After the Other)

    Hello Labview,
    I am coming back here after a long long time and re-touching the Labview after so long.
    So, have some really basic question.
    I have 15 LEDs, which I want to glow one after the other (First glows and dies, then second glows and dies, then third glows and dies and so on...).
    I should be able to do it with a single button.
    I know this would be a silly question but I am not able to make out since I am returning after a long time.
    Can I please request you to help me creating such a program?
    Looking forward for your positive reply.
    Regards,
    Nishant

    Nishant wrote:
    Hello Labview,
    I am coming back here after a long long time and re-touching the Labview after so long.
    So, have some really basic question.
    I have 15 LEDs, which I want to glow one after the other (First glows and dies, then second glows and dies, then third glows and dies and so on...).
    I should be able to do it with a single button.
    I know this would be a silly question but I am not able to make out since I am returning after a long time.
    Can I please request you to help me creating such a program?
    Looking forward for your positive reply.
    Regards,
    Nishant
    The fundamentals of LabVIEW hasn't changed that much in 5 years.
    It sounds like you need to re-learn what little you knew by taking the online tutorials.

  • How do you get iTunes purchased songs to automatically play one after the other

    How do you get iTunes purchased songs to play automatically one after the other without having to hit play for each song ? Also I lost all my pictures on my iPad when I installed iOS 7 upgrade. Any way to get them back? Thanks. Dr Ron.

    Hi Dr. Ron,
    By your question, I am wondering if you are playing your music from the iTunes app rather than the Music app?
    In the Music App, you can go to any of the options at the bottom and click on a song to play and it will then continue to play the songs in that category. You can also select "Shuffle" to shuffle them.
    As for your Photos, did you have them backed up anywhere?
    Cheers,
    GB

  • IPhone 5. Prior to the iPhone 5, I could listen to podcasts one after the other without doing anything. Now it will only play one podcast at a time, then I have to click on the next one. Not a great feature when driving. TIA, Sarah

    iPhone 5. Prior to the iPhone 5, I could listen to podcasts one after the other without doing anything. Now it will only play one podcast at a time, then I have to click on the next one. Not a great feature when driving. TIA, Sarah

    How do I get it to just play through all the podcasts that I've downloaded just like my 1st gen?
    Group and order your podcasts to a playlist. Then play them from the playlist.

  • Playing movie clips one after the other

    Hello, I am trying to figure out how to play several movie clips one after the other. Each clip has animation in it. When I drag the clip on the main timeline the timeline plays the frame but does not play the contents of the movie. how do I get it to play the contents of the first movie then play the contents of the second movie which is in frame 2 and so on?
    Thank you

    do you mean in the authoring environment you don't see nested movieclips play when scrubbing the timeline?  if yes, that cannot be changed.  if you used graphic symbols (instead of movieclips), you can see nested graphics play when scrubbing a parent timeline (if the parent timeline has sufficient frames).

Maybe you are looking for