Can't anyone answer this simple question?

Guys,I want to know whether a GUI which is made using Swing can write files to disk,or ,in another way--does Swing support writing files to disk?(This is becoz applets do not support this feature)
Thannks in advance,
Avichal167

One thing to note...
Because the previous example is simple, I handled all the File IO operations in the same class as the GUI ...
You can how ever have the File IO done in a different class and tie it in to your GUI class...
Example... GUISample.java
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class GUISample extends JFrame implements ActionListener{
        private JTextArea jtxArea;
        private JButton jbtn;
        private String[] bText = {"Read","Write"};
        private boolean bState = true;
        private FileHandler handler;
     public GUISample(){
             super("GUI Sample");
          setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          setLayout(new BorderLayout());
          jtxArea = new JTextArea(15,20);
          jtxArea.setEditable(true);
          jbtn = new JButton(bText[0]);
          jbtn.addActionListener(this);
          getContentPane().add(jtxArea,BorderLayout.CENTER);
          getContentPane().add(jbtn,BorderLayout.SOUTH);
          pack();
          setVisible(true);
          handler = new FileHandler(); // instantiates FileHandler
     /* both method from FileHandler return Strings to be displayed in the JTextArea */
     public void readAndDisplay(){
          jtxArea.setText(handler.readTheFile()); // calls method from FileHandler
     public void writeToFile(){
          jtxArea.setText(handler.writeTheFile(jtxArea.getText())); // calls method from FileHandler
     public void actionPerformed(ActionEvent ae){
            if ((ae.getSource() == jbtn)&&(bState)){
                  bState = false;
                  jbtn.setText(bText[1]);
                  readAndDisplay();
             else{
                       bState = true;
                       jbtn.setText(bText[0]);
                       writeToFile();
     public static void main(String[] args){
             GUISample gspl = new GUISample();
}Example... FileHandler.java
import java.io.*;
public class FileHandler {
private String theData;
public String readTheFile(){ // reads and returns data or message
         try{
             File afile = new File("test.txt");
                 FileInputStream fis = new FileInputStream(afile);
                  try{
                       byte[] strBuff = new byte[(int)afile.length()];
                       fis.read(strBuff);
                       try{
                            theData = new String(strBuff);
                            fis.close();
                       }catch(NullPointerException npe){theData = "Null Pointer Exception";}
                   }catch (IOException ioe){theData = "IO Exception";}
           }catch (FileNotFoundException fnfe){ theData = "File Not Found";}
     return theData;
     public String writeTheFile(String data){ // writes and returns a message
         try{
             File afile = new File("test.txt");
                 FileOutputStream fos = new FileOutputStream(afile);
               try{
                       try{
                       fos.write(data.getBytes());
                       fos.close();
                       theData = "File Saved";
                }catch(NullPointerException npe){theData = "Null Pointer Exception";}
                   }catch (IOException ioe){theData = "IO Exception";}
           }catch (FileNotFoundException fnfe){theData = "File Not Found";}
           return theData;
}and of course you can use the same Test.txt file...
As you can see from this example, I have one class create and handle the GUI and the second class handles all the File IO operations...
So to better answer your first question, Swing and AWT and Applets can be used to create GUIs... and as far as File IO, all three can have code or be couples with a class that does File IO operations...
The only restriction is with Applets where by default the SecurityMananger does not allow File IO operations...
Notice the word "default", this means Applets are capable of doing File IO, if you do some extra coding and policy work... ( my terminology may be off on this)
But as stated earlier, I am not well versed enough in Applets to give you assistance in creating a Signed Applet that can... soon I will, just not at this time...
- MaxxDmg...
- ' He who never sleeps... '

Similar Messages

  • Can ne 1 answer this interesting question!!! ?

    Hi,
    I have the name of the method in a String format. I want this information to get evaluated as a method/function. How can I do that?
    For example, I have a string named "setName" and another string "str". I want this information to get evaluated as :- setName(str), ie. string 'setName' should get interpreted as a method name 'setName( )'. 'setName(String str)' is a method in the same class.
    Thanks!
    -Vaibhav.

    Hi...
    import java.lang.reflect.*;
    public class Test {
         public Test (String setName, String str) {
              try {
                   Method m = this.getClass ().getMethod (setName, new Class [] {str.getClass ()});
                   m.invoke (this, new Object [] {str});
              catch (Exception e) {}
         public static void main (String [] args) {
              Test t = new Test ("setName", "Rick");
              System.out.println (t.getName ());
         public void setName (String name) {
              _name = name;
         public String getName () {
              return _name;
         String _name = "Boab";
    [\code]                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Someone PLEASE answer this simple question

    what are the technical specs on the line input for the audigy 2 zs? high/low impedance? voltage level? anything please, creative has no really DETAILED specs on their products.
    thanks
    L_E

    Reasonably sure it's high impedance, designed for 2v peak-peak (ie. -v peak to +v peak), with the playback volume control an analog attenuator which affects recording, and the recording volume control digital with a x2 multiplier (i.e. 0dB is approx at 50% position).
    One thing this means is that a "too-hot" signal can be attenuated to match the 2Vp-p ADC range to prevent digital clipping of it.
    Yes, CL has a reluctance to say more than necessary about internal details.
    -Dave
    [email protected]

  • I'm confused answer this simple question please...

    I have askew at least 10 people on here "when you get BT Infinity will they install a phone line for free?" And everyone has said yes is this true? Because I signed up today and they said a extension is free but and phone line isn't or is she wrong?

    If you have no BT line whatsoever a phone line would be installed free with an 18 month contract. If you have an existing BT line then BT would put infinity on that line.
    You could have BT set up a free new line for infinity and keep your existing line as well. But that would be strange as it would mean your paying for line rental twice.
    So best to ask BT to put infinity on your existing line. They won't provide an extension, but they can provide a long Ethernet cable if you want the hub in another room

  • Please answer this simple question: it plays an important role

    How to write query to retreive the latest record by using PN-BEGDA , PN-ENDDA, SYDATUM,.
    I know using RP-PROVIDE.......other method using query i require
    it is urgent

    Hi Ramana,
                     Try this one this will give the latest record in terms of time ok. sy-uzeit : display the current time ok..
    data: time like sy-uzeit.
    time = sy-uzeit + 80.
    Here 80 is SECONDS OK..
    select * from PAnnnn where begda = time.
    Reward points if helpful
    Kiran Kumar.G.A

  • Can anyone answer this question about unlimited data?

    I currently have a phone with ATT... a Samsung. Contract has been up for several months.
    I have the unlimited data plan for $30 a month.
    When I buy the new iPhone will I be able to just transfer my $30 a month unlimited data plan from my old Samsung phone to my new iPhone's new 2-year contract? Or, will I have to switch to the new data plan thing (with no more unlimited data)?
    Can anyone answer this? Been looking online for an answer and got zilch. Thanks.

    Why are you asking this in a user-to-user iPhone forum? The ONLY source for a definitive answer about the brand new, not yet implemented AT&T data plans is AT&T. You need to contact them. Any "answer" you get here is purely guesswork.

  • What  are the advantages over sql in pl/sql...can you please answer this?

    Hi,
    what are the main differences between sql and pl/sql...why v are using pl/sql rather then sql...can you please answer this question?

    SQL is used to access the database. PL/SQL is a programming language where SQL is seamlessly integrated. In order to access the database in PL/SQL, you have to use SQL.
    Think of it as two pieces of software, two "engines". If you want to interact with the database, then performance wise it's best to use only one engine (SQL only), instead of two (PL/SQL and SQL). If a PL/SQL program executes a SQL statement, it does a "context switch", i.e. saving its state in PL/SQL before giving control to the SQL engine and vice versa. This is quite fast, but do a lot of them and it is slow, so beware of programming SQL statements inside loops.
    Another way to put it: SQL is a fourth generation language (4GL) where you tell what you want, not how. The software, the optimizer, will decide for you how to process the statement. PL/SQL is a third generation language (3GL), or at least the PL-part is, where you describe how things should be processed. Leading to more code and more control. With every Oracle release, SQL becomes more powerful and the optimizer gets better, so using SQL is increasingly important.
    For complex processing, using PL/SQL is still necessary. But use it with care.
    Hope this helps.
    Regards,
    Rob.

  • Hello! my problem at jump of paid games I can't remember answers to confidential questions. you can cancel or step by step describe what to do? thanks

    hello! my problem at jump of paid games I can't remember answers to confidential questions. you can cancel or step by
    step describe what to do? thanks

    The Best Alternatives for Security Questions and Rescue Mail
        a. Send Apple an email request at: Apple - Support - iTunes Store - Contact Us.
        b. Call Apple Support in your country: Customer Service: Contacting Apple for
            support and service.
        c. Rescue email address and how to reset Apple ID security questions

  • Can't remember answers to security questions.How do I reset the security questions?

    Can't remember answers to security questions.How do I reset the security questions?

    1)  Apple ID: All about Apple ID security questions
    If necessary...
    2)  See Here... ask to speak with the Account Security Team...
    Apple ID: Contacting Apple for help with Apple ID account security
    3)  Or Email Here  >  Apple  Support  iTunes Store  Contact

  • I forgot to answer account security, so how can I find answers or change questions and new answers

    I forgot to answer account security, so how can I find answers or change questions and new answers
    Can you help me ,please???

    From a Kappy  post
    The Three Best Alternatives for Security Questions and Rescue Mail
       1. Use Apple's Express Lane.
    Go to https://expresslane.apple.com ; click 'See all products and services' at the
    bottom of the page. In the next page click 'More Products and Services, then
    'Apple ID'. In the next page select 'Other Apple ID Topics' then 'Forgotten Apple
    ID security questions' and click 'Continue'. Please be patient waiting for the return
    phone call. It will come in time depending on how heavily the servers are being hit.
    2.  Call Apple Support in your country: Customer Service: Contact Apple support.
    3.  Rescue email address and how to reset Apple ID security questions.
    A substitute for using the security questions is to use 2-step verification:
    Two-step verification FAQ Get answers to frequently asked questions about two-step verification for Apple ID.

  • I can't remember answers from security questions... Please help me....apple support don't answer.(((

    I can't remember answers from security questions... Please help me....apple support don't answer.(((

    1. See my User Tip for some help: Some Solutions for Resetting
        Forgotten Security Questions: Apple Support Communities.
    2. Here are two different but direct methods:
        a. Send Apple an email request at: Apple - Support - iTunes Store - Contact Us.
        b. Call Apple Support in your country: Customer Service: Contacting Apple for
            support and service.
    3. For other queries about Apple ID see Frequently asked questions about Apple ID.
    4. Rescue email address and how to reset Apple ID security questions
    5. For online assistance use Apple - Support - Express Lane

  • Can any body answer this-Want to set the cursor position in textfield.

    i want my cusor position in textfield at the initial position which will come by default.
    but when i'm using the textfields in an inner class i'm getting the cursor position at the end of the text in text filed.pls can any body answer this.
    thanks in advance.
    if want run this example.
    import java.awt.*;
    import java.awt.event.*;
    class Testing extends JFrame implements ActionListener
         Container cnt;
         JButton jd;
         JTextField jt1;
         JTextField jt2;
         Testing()
              cnt = getContentPane();
              cnt.setLayout(new FlowLayout());
              jd = new JButton("OK");
              //jd.setBounds(50,50,100,30);
              cnt.add(jd);
              jd.addActionListener(this);
         public void actionPerformed(ActionEvent ae)
              Object but = ae.getSource();
              System.out.println("in action 00000");
              if(but.equals(jd))
                   System.out.println("in action ");
                   call();
                   return;
         void call()
              System.out.println("in action 1111111111");
              Inner inn = new Inner();
              inn.jdlg.show();
         public static void main(String s[])
              JFrame jf = new Testing();
              jf.setSize(200,200);
              jf.show();
         class Inner
              JDialog jdlg;
              //JTextField jt1;
              //JTextField jt2;
              Container cnt;
              Inner()
                   jdlg = new JDialog();
                   JLabel jla = new JLabel("Label");
                   jt1 = new JTextField();
                   jt2 = new JTextField(5);
                   cnt = jdlg.getContentPane();
                   cnt.setLayout(new FlowLayout());
                   cnt.add(jt1);
                   cnt.add(jt2);
                   jt1.setText("aaaaaaaa");
                   jt2.setText("bbbbbbbb");
                   System.out.println("the text "+jt1.getText());
                   jdlg.setSize(200,200);

    JTextFiled.setCaretPosition(0);

  • Reconnect question? Can anyone answer this?

    Can anyone answer a this question about using Reconnect:
    I have over 400 pictures that didn't restore out of a 202GB Full Backup. The catalog contains over 5 years of pictures. The Full Backup file is on K: external drive. If I use the reconnect and it reconnects those pictures to that K: external backup file, then do I always have to keep that external drive plugged in while I use that catalog that reconnected those pictures to the external drive?
    If the answer is yes, then is it possible to make a copy of that Full Backup and put it on the C: drive so I can disconnect that external drive and keep it in a safe place? I have plenty of room on the C: drive since I upgraded to a 2TB main drive.
    If it is possible to make a copy of that Full Backup and move it to the C: drive can you please tell me the proper procedure. Thank you!

    Why are you asking this in a user-to-user iPhone forum? The ONLY source for a definitive answer about the brand new, not yet implemented AT&T data plans is AT&T. You need to contact them. Any "answer" you get here is purely guesswork.

  • Need a simple answer for simple question???

    simple question... what is the best way to export my fce movie and burn it on idvd for the best quality for genaral use ... sd..4x3 ratio tv.. lots of ken burn effects on photos... lots of sd video... ???
    not so simple answer... i have read manuals.. apple discussions.. etc etc my eyes are blurry.. i have been exporting out of fce to qk time movie, then import to idvd and burn..
    i get lots of wavy or jitter when doing kens burn effects on photos.. i have been told that 1 field must be missing.. and its better to take the qk time movie convert it again making sure hi quality is checked(movie properties 720 x 480) and self contained movie, then import to imovie ver 5.02 which has better codecs then to idvd ... an apple store tech said..
    then another apple store tech said...dv pro or dv stream or interlaced or on and on and on
    its not 16x9, or for the web or anything but simply burn it and give it to my grandma to play in a standard dvd player.. best quality.. period.. i know it won't any better than my source video but the wavy photos bother me..
    help

    The Apple store tech told you garbage. The quality will be the same. It's using the same QuickTime engine. There may be a difference because going through iMovie will go through a file conversion and the picture might be softened a little, which will mitigated this flicker you see.
    The wavy photos can be a lot of things, most likely due to the nature of the images themselves and the movements you've done on them. What often works on still images is to apply a one pixel vertical motion blur in an application like Photoshop or Elements. This helps to reduce interlace flicker on motion when the material is brought into a video editing application.

  • Please answer the simple question about publishing Web Services!

    I have implemented my first web service GetDate, using JDeveloper.
    Could anybody tell me please how can I place now this web service on the web, on my web page?

    Dear Shay, thank you a lot!
    But it seems to me that you didn't understand my question or may be I have explained it not in the best way.
    I have done every step from this tutorial, I have deployed me web service to OC4J Server, and it works.
    What I need now, is to make this service available on my home page, which doesn't have Oracle Application Server, so that every person on the internet (even if he also doesn't have this application server installed on his computer) can use it.
    Is it possible to do so or not?

Maybe you are looking for