Results 1 to 2 of 2

Thread: JAVA beginner: create a screen where i can write messages

  1. #1
    Join Date
    Jun 2011
    Posts
    1

    JAVA beginner: create a screen where i can write messages

    Hi i am doing an assignment and came across a problem. basically i need to create a screen where i can write messages and save them to individual text files. i managed to create the screen but the messages are either being appended to the same text file or not being written at all, the code is here

    try
    {
    for (int nextNumber = 0; nextNumber <99; nextNumber++ )
    {
    String directoryPath = "c:\\DATAX\\";
    String filename = directoryPath + "\\msg" + nextNumber + ".txt";
    File newFile1 = new File (filename);
    try
    {
    if(!newFile1.exists())
    {
    newFile1.createNewFile();
    break ;
    }
    }
    catch (IOException e){
    }
    BufferedWriter out = new BufferedWriter(new FileWriter (filename));
    //BufferedWriter out = new BufferedWriter(new FileWriter(filename,true));
    messageWindow.write(out);
    out.flush();
    out.close();
    }
    }
    catch (IOException e1)
    {
    e1.printStackTrace();
    }
    finally
    {
    JOptionPane.showMessageDialog(null, "Your Message has been successfully saved");
    }

    i need to always save the written message to a new text file. can someone help me pls?

    thanks

  2. #2
    Join Date
    Jan 2006
    Posts
    605

    Re: JAVA beginner: create a screen where i can write messages

    Check the below code of the program example:

    Code:
    import javax.swing.*;
    import java.awt.event.*;
    
    public class ShowDialogBox{
      JFrame frame;
      public static void main(String[] args){
      ShowDialogBox db = new ShowDialogBox();
      }
    
      public ShowDialogBox(){
      frame = new JFrame("Show Message Dialog");
      JButton button = new JButton("Click Me");
      button.addActionListener(new MyAction());
      frame.add(button);
      frame.setSize(400, 400);
      frame.setVisible(true);
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      }
    
      public class MyAction implements ActionListener{
      public void actionPerformed(ActionEvent e){
      JOptionPane.showMessageDialog(frame,"techarena.in");
      }
      }
    }

Similar Threads

  1. Need help to write this program in java?
    By frkadeel in forum Software Development
    Replies: 1
    Last Post: 01-12-2010, 03:58 PM
  2. How to create a Splash Screen in Java?
    By DANIEL 602 in forum Software Development
    Replies: 4
    Last Post: 16-02-2010, 03:35 AM
  3. Write Once And Run Anywhere Nature In Java
    By D_chapple in forum Software Development
    Replies: 5
    Last Post: 10-02-2010, 06:42 PM
  4. How to create read write lock in java
    By AlienKing in forum Software Development
    Replies: 3
    Last Post: 05-05-2009, 08:18 PM
  5. Beginner in JAVA need some help!
    By VivekT in forum Software Development
    Replies: 1
    Last Post: 02-03-2009, 05:45 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,750,540,200.85214 seconds with 16 queries