Writing and reading data from a form

I am trying to write a save and load feature for an application using mostly Jtextboxes and things. Basically I have a form that the user enters data into. I want to be able to save this data and load this data. I am relatively new to working on a GUI and I'm not quite sure if my knowledge of I/O applies to this. This is my stab at it but if I am completely off I would not be surprised. I don't want to print it to the command line but this was all I could think of right now. Any help would be greatly appreciated.     
private void SavePrefs() {
          File SavePrefs;
          // get filename:
          fc.setDialogTitle("Select Filename For Site Data");
          int result = fc.showOpenDialog(f);
          if (result == JOptionPane.OK_OPTION) {
               SavePrefs = fc.getSelectedFile();
               // default file extension ".CMM"
               if (!SavePrefs.getName().endsWith(".CMM")) {
                    // filename does not meet requirmeents:
                    System.out.println("NO CMIMS in filename");
                    SavePrefs = new File(SavePrefs.getAbsolutePath() + ".CMM");
               // continue with save code:
               System.out.println("File Selected:" + SavePrefs.toString());
               //Creates a .cmm file with a code in it containing the data from the first site tab.
               FileOutputStream out; // declare a file output object
PrintStream p; // declare a print stream object
               try
// Create a new file output stream
out = new FileOutputStream(SavePrefs.toString());
// Connect print stream to the output stream
p = new PrintStream( out );
p.print(_SitePropPanel);
p.close();
catch (Exception e)
System.err.println ("Error writing to file");
               JOptionPane.showMessageDialog(null,
                         "File is saved.");
          // not OK selected (cancel or.?)
     private void LoadPrefs() {
          File loadPrefs;
          // get filename:
          fc.setDialogTitle("Select Filename For Site Data");
          int result = fc.showOpenDialog(f);
          if (result == JOptionPane.OK_OPTION) {
               loadPrefs = fc.getSelectedFile();
               // default file extension ".CMM"
               if (!loadPrefs.getName().endsWith(".CMM")) {
                    // filename does not meet requirements:
                    System.out.println("NO CMIMS in filename");
               // continue with save code:
               System.out.println("File Selected:" + loadPrefs.toString());
               try
     // Open the file that is the first
     // command line parameter
     FileInputStream fstream = new
                              FileInputStream(loadPrefs.toString());
     // Convert our input stream to a
     // DataInputStream
                         DataInputStream in =
     new DataInputStream(fstream);
     // Continue to read lines while
     // there are still some left to read
     while (in.available() !=0)
     // Print file line to screen
                              System.out.println (in.readLine());
                         in.close();
     catch (Exception e)
                         System.err.println("File input error");
          JOptionPane.showMessageDialog(null, "Feature is not yet implemented.");
     }

Oh and the GUI is a window with menus where the save feature resides, but the data is in tabbed panels. That is where the _SitePropPanel comes in. I know I want it to write the input from the panel and not the panel. What would would I use for that? I tried getInputContext().                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

Similar Messages

  • Help with writing and retrieving data from a table field with type "LCHR"

    Hi Experts,
    I need help with writing and reading data from a database table field which has a type of "LCHR". I have given an example of the original code but don't know what to change it to in order to fix it and still read in the original data that's stored in the LCHR field.
    Basically we have two Function modules, one that saves list data to a database table and one that reads in this data. Both Function modules have an identicle table which has an array of fields from type INT4, CHAR, and type P. The INT4 field is the first one.
    Incidentally this worked in the 4.7 non-unicode system but is now dumping in the new ECC6 Unicode system.
    Thanks in advance,
    C
    SAVING THE LIST DATA TO DB
    DATA: L_WA(800).
    LOOP AT T_TAB into L_WA.
    ZDBTAB-DATALEN = STRLEN( L_WA ).
    MOVE: L_WA to ZDBTAB-RAWDATA.
    ZDBTAB-LINENUM = SY-TABIX.
    INSERT ZDBTAB.
    READING THE DATA FROM DB
    DATA: BEGIN OF T_DATA,
                 SEQNR type ZDBTAB-LINENUM,
                 DATA type ZDBTAB-RAWDATA,
               END OF T_TAB.
    Select the data.
    SELECT linenum rawdata from ZDBTAB into table T_DATA
         WHERE repid = w_repname
         AND rundate = w_rundate
         ORDER BY linenum.
    Populate calling Internal Table.
    LOOP AT T-DATA.
    APPEND T_DATA to T_TAB.
    ENDLOOP.

    Hi Anuj,
    The unicode flag is active.
    When I run our report and then to try and save the list data a dump is happening at the following point
    LOOP AT T_TAB into L_WA.
    As I say, T_TAB consists of different fields and field types whereas L_WA is CHAR 800. The dump mentions UC_OBJECTS_NOT_CONVERTIBLE
    When I try to load a saved list the dump is happening at the following point
    APPEND T_DATA-RAWDATA to T_TAB.
    T_DATA-RAWDATA is type LCHR and T_TAB consists of different fields and field types.
    In both examples the dumps mention UC_OBJECTS_NOT_CONVERTIBLE
    Regards
    C

  • Best way to control and read data from multiple instruments?

    Hello,
    I'm building an application to test power supplies involving multiple pieces of equipment over a couple of different comm busses. The application will also send control instructions to some of the instruments, and read data from some of the instruments. The reading and control profiles will not run on the same schedule (variable length control steps, configurable read interval).
    I was thinking of using a queued statemachine (producer/consumer) for the control profile and another to read the data, but I got concerned that there would be collisions between sending control commands and read commands to the same machine. Is there a suggested design pattern for implementing something like this?
    Timing of the commands isn't critical down to the milisecond, but I need to collect reasonably accurate timestamps when the data is read. The same is true for the control commands.
    Here are the instruments I'm going to use, if the are control, read, or both, and the communication method
    Instrument Funtions Comm Method
    Power Supply Read data Communicates to PMBus Adapter
    PMBus to USB Adapter Read data USB (Non-Visa)
    Switch control relays USB (VISA)
    Power Dist. Unit read data/control outlets SNMP (Ethernet)
    Electronic Load read data/control load GPIB (VISA)
    Thermal Chamber read data/control temp Ethernet (VISA)
    Thanks,
    Simon

    Hello, there is a template in LV called "Continuous measurement and Logging".
    It can give you some idea how to properly decouple the "GUI Event handler" top loop (where your Event structure is) from the DAQ and other loops.
    You do not need to totally replicate the above example, but you can find there nice tricks which can help you at certain points.
    The second loop from the top is the "UI message loop". It handles the commands coming from the top loop, and regarding to the local state machine and other possible conditions and states, it can command the other loops below.
    During normal run, the different instrument loops just do the data reading, but if you send a control command from the top loop to a certain instrument loop (use a separate Queue for every instrument loops), that loop will Dequeue the control command, execute it, and goes back to data reading mode (in data reading mode the loop Dequeu itself with a "data read" command automatically). In this way the control and data read modes happen in serial not in parallel which you want to avoid (but I think some instrument drivers can even handle parallel access, it will not happen in really parallel...).
    In every instrument loop when you read a value, attach a TimeStamp to it, and send this timestamp/value couple to the DataLogging loop via a Queue. You can use a cluster including 3 items: Source(instrument)/timestamp/value. All the instrument loops can use the same "Data logging" Queue. In the Datalogging while loop, after Dequeue-ing, you can Unbundle the cluster and save the timestamp and data-value into the required channel (different channel for every instrument) of a TDMS file.
    (Important: NEVER use 2 Event structures in the same top level "main" VI!)

  • Writing and Retrieving data from an Excel spreadsheet

    Hi all
    I am working on some battery chargers and need to record the data from my DAQ to an Excel Spreadsheet. How do i do that?
    I don't wanna purchase the Office toolkit from Labview!
    Please Help!
    RJ

    Hi smercurio_fc
    Hi Smercurio_fc,
    Thanks for the reply. I really appreciate your help.
    However, I would like to point out that after making numerous searches, I could not get any VI or thread working for my case. Most of the files complain regarding any of their missing sub-VI(s).
    I myself don't understand the problem. I have even re-installed the application to shoot any of the possible installation errors. I m not a spammer.
    I'll try to do what you have suggested in the former part of your reply.
    Regards,
    RJ

  • Uploading Excel File and Reading Data from that File

    <b>Hi
    Can anyone Please tell me how to upload an Excel File in to the Web Dynpro Application and After that i want to read the data from that uploaded excel file in the Web Dynpro Application to the Web Dynpro table.
    Plz help me to solve this.......
    Regards
    Chandran</b>

    Hi,
    Upload Excel file using File Upload UI
    1)Add jxl jar folder in the lib folder of ur project.
    2)Go to properties of ur project and add jar to ur project.
    3)Using the File upload ui ,browse and upload the file.
    4)Write the read file in to ur server location using fileoutput stream.
    5)then using code u can read the excelfile from the server location itself.
    Here is the code:
         IWDAttributeInfo attInfo =wdContext.getNodeInfo().getAttribute("upload");
    /** get the name of excel file and storing it in the server with the same name and extention****/
    binaryType=IWDModifiableBinaryTypeattInfo.getModifiableSimpleType();
    fileuploaded = binaryType.getFileName();
    byte b[] = wdContext.currentContextElement().getUpload();
    File filename =new File("
    <Server name>
    <folde name>
    " + fileuploaded);
    try {
    FileOutputStream out = new FileOutputStream(filename);
    out.write(b);
    out.close();
    } catch (FileNotFoundException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    /**Readind from the server**/
    int iRows = 0;
    try {     Workbook wb = null;
         Sheet sheet = null;
         wb = Workbook.getWorkbook(filename);
         sheet = wb.getSheet(0);
         int iColumns = sheet.getColumns();
          iRows = sheet.getRows();
         int i = 0;
        //get Cell contents by (COLUMN, ROW);
        for (int r = 0; r < iRows; r++) {
       for (int c = 0; c < iColumns; c++) {
         Cell cell = sheet.getCell(c, r);
         characterarray<i> = cell.getContents();
    //wdComponentAPI.getMessageManager().reportSuccess("Row"r characterarray<i>);
    i++;
    wb.close();
    Declare Globally
    //@@begin others
    String fileuploaded;
    IWDModifiableBinaryType binaryType;
    String characterarray[] = new String[1000];
    //@@end
    Also look at this blog too  /people/perumal.kanthan/blog/2005/03/21/reading-excel-data-from-java-using-hssf-api
    Thanks and Regards,
    Arun

  • Best way to browse and read data from a lot of files?

    Hi All,
    I am trying to read tags from music files. Currently I'm listing all the files and then reading through the tags, as below:
    List<File> result = new ArrayList<File>();
    FilenameFilter mp3filter = new FilenameFilter() {
         public boolean accept(File dir, String name) {
              return name.endsWith(".mp3");
    FilenameFilter wmafilter = new FilenameFilter() {
         public boolean accept(File dir, String name) {
              return name.endsWith(".wma");
    FileFilter dirFilter = new FileFilter() {
         public boolean accept(File file) {
              return file.isDirectory();
    File[] dirList = aStartingDir.listFiles(dirFilter);
    File[] mp3files = aStartingDir.listFiles(mp3filter);
    File[] wmafiles = aStartingDir.listFiles(wmafilter);
    List<File> filesDirs = Arrays.asList(dirList);
    List<File> filesMp3 = Arrays.asList(mp3files);
    List<File> filesWma = Arrays.asList(wmafiles);
    for (File file : filesMp3) {
         result.add(file);
    for (File file : filesWma) {
         result.add(file);
    for (File file : filesDirs) {
         List<File> deeperList = getFileListing(file);
         result.addAll(deeperList);
    }and then read the files in a for loop through the list.
    Is there a better way to do the same?

    Well, you could optimize that just a little bit by only calling listFiles once with a filter that would accept directories, wmas, and mp3s all in one go. Then you could iterate through the results and separate them into the three categories after you had the complete recursive directory listing. That may be faster. But your OS will likely cache the results of the directory listing, thus minimizing the effort of your current approach. But honestly, no... you need the headers from every file, so you'll need to find each file and then check the headers.
    If you want, you can cache the results somewhere for future reference. Are you concerned about performance or some such?

  • Help required in writing And Reading Xml From Database

    Hi
    i m new to java.
    i m facing problem while writing Xml file from Mysql Database in java i m using the WebRowSet
    and also for Reading WebRowSet
    after reading the Xml i have to save this in Database
    (required source code)
    is there any one to help me in this way
    regards
    aamir

    shadab_think_globally wrote:
    {noformat}*hi everybody,
    please send me a ajax with jsp application
    suppose i enter a word in text area ajax will populate/suggest all string from database ,who started
    from that entering character(s).like a google string search.
    please send full source code
    *{noformat}how about you do it yourself?

  • How to open and read data from text file in PL/SQL

    We have a project ,need to open a file containing entries of data
    ,then process those data records one by one to update the
    database.This operation shoulbe be done in the database
    enviroment. Is there any hint about the file operation in
    PL/SQL? How to open the file and get one record ,maybe one line,
    and parse and get the data field ?
    thanks
    defang

    There was also a question on this over at AskTom
    (asktom.oracle.com) about a week ago complete with sample code.
    The pointer to the sample code is here:
    <A HREF="http://asktom.oracle.com/pls/ask/f?
    p=4950:8:::::F4950_P8_DISPLAYID:464420312302
    TARGET=_blank>http://asktom.oracle.com/pls/ask/f?
    p=4950:8:::::F4950_P8_DISPLAYID:464420312302</A>
    Admittedly it's about Win95, but the principles should apply.
    Yours faithfully, Graham Reeds.
    [email protected] | http://omnieng.co.uk/

  • Using forms6i and reading data from MS SQL server 7

    Hi!
    I have been given a new task to connect to Microsoft SQL SERVER 7 with Oracle 6/6i development with ODBC and extract specific data.
    I am realy stuck with this I hope some one will help me with this as soon as possible.
    thanka

    I did a similar thing with developer 2000 (Form 4.5) and SQL server6.5.
    There are lots of things involved and there will be issues that need to be resolved in you application but you can take one thing at a time and you should be able to do it.
    -First make sure that your SQL server is up and running.
    -Then make a client machine that connects to SQL server.
    -On the client install your Form6 or 6i.
    -Install ODBC manager on your Client Machine.
    -Get the Oracle ODBC driver for SQL server.
    -There is a document available with developer 2000 for open data source. It should be with your Form6/6i documentation. It has got a section for connection with SQL server.
    Start with this and where ever you get stuck ask away question on the forum.
    Hope this help

  • Mac pro 13'' harddisk makes noises when writing and reading data, but Techtool scanning result shows no bad blocks in the disk, that is normal?

    I bought my Mac pro 13 inch, i7 processor and 750G storage 20th November 2012. But I found when copy into or out the Mac, the harddisk makes noises, like bitting something. I thought there are bad blocks in the disk, but the result of Techtool scanning is no bad blocks in disk, and giving a passed conclusion.
    I went the apple store for testing, and the repairmen told me there are two choices available for me:1) replace the harddisk 2) back to the store i bought machine from for a new one. i think that the machine only bought few days, it had better not be disassembled, so i went back for a new one. unfortunately, the new one makes more noises than my old one. i don't know why like apple named brands notebooks have such problems.  did you undergo this experience ?

    All of the HDDs, be they in my MBPs or enclosures are barely audible.  I would say the you deserve no less.  I suggest that you do not leave until you are satisfied with a near silent HDD.
    Why you got two in a row is a puzzle, but then some people beat the odds and win the lottery.  In your case the results are not exactly positive.  All HDDs eventually fail, and some fail sooner than others.  At least you should start with a quiet one.
    Good luck.
    Ciao.

  • How to read data from a CLUSTER STRUCTURE not cluster table.

    Hi,
    how to read data from a CLUSTER STRUCTURE not cluster table.
    regards,
    Usha.

    Hello,
    A structre doesnt contain data.. so u cannot read from it. U need to find out table of that structure and read data from it.
    Regards,
    Mansi.

  • We want to read data from weigh bridge and display in oracle forms & store

    Sir/Madam,
    in our organisation we had one requirement. i.e is reading data from weigh bridge using serial port, displying that data in oracle forms and when ever user click save button we store that into my oracle database. we are using oracle 8i and forms 6i and windows OS environment. we don't know reading data from serial port and placing that into form items. please help me as early as possible if there is any property available in d2k regarding this requirement .
    thank you,
    vishnu

    There's no property in Forms that makes you read serial ports, but as far as I know you need to know the API of the machine which you want to read data from (it should come with machine's manual) and then it will be easy to store it in forms item.
    Tony

  • Reading data From XML file and setting into ViewObject to Pouplate ADF UI

    Hi,
    I have following requirement.
    I would like to read data from XML file and populate the data in ViewObject so that the data can be displayed in the ADF UI.
    Also when user modifies the data in the ADF UI, it should be modified back into to ViewObject.
    Here is an example - XML file contains Book Title and Author. I would like to read Book Title and Author from XML file and set it into ViewObject Attribute and then display Book title and Author in ADF UI page. Also when user modifies Book title and Author, I would like to store it back in View Object.
    Please help me with this requirement and let me know if any solution exist in ADF, for populating the ADF UI screen fields with external XML file data.
    Thanks

    Read chapter 42 http://download.oracle.com/docs/cd/E16162_01/web.1112/e16182/bcadvvo.htm of the fusion developer guide
    Section 42.7, "Reading and Writing XML"
    Section 42.8, "Using Programmatic View Objects for Alternative Data Sources"
    Timo

  • I am writing datas into a FIFO ,i am reading datas from fifo .but when i am writing datas like a a(0),a(1),a(2 like that.when i am reading dating datas a(0)comes to a(3 ) rd place .what is the reason ?

    I am writing datas into a FIFO in FPGA Target side  ,i am reading datas from fifo in windows host side  .but when i am writing datas like a a(0),a(1),a(2 like that.when i am reading dating datas a(0)comes to a(3 ) rd place, a(1) comes to a a(0) .what is the reason ?

    Please use a shorter title in your subject line and not post the entire question in therre.  (See the subject line I created.)   There is also no such word as "datas".  Data is already plural.
    Please read http://stackoverflow.com/help/how-to-ask.  Your question is hard to read because you aren't using proper punctuation and capitalization of your sentences.  It looks like one run-on sentence.
    Beyond that, it is impossible to help you solve our problem with just your question.  Please provide some more information.  Perhaps even attach code we can look at.  Show us what the data you are sending is supposed to look like, and what it actually looks like.

  • Adobe offline form with capablity to read data from a local data base.

    Hi ,
            We have customer requirement for a offline Adobe form which will be used by Sales rep, this form when saved to the local hard disk is required to read data from another local data base available in the laptop  and prefill a few fields in the form . 
    Is this requirement technically feasible using Adobe forms?
    Thanks
    Srikanth S

    Well may be it's possible because if you go to the Data View in ALD and create a new Data Connection --> OLEDB database --> Build --> It gives you various options for connecting to different DBs but frankly speaking I have never tried it.
    Check the ALD help for more information on the topic.
    Using LiveCycle Designer > Working with Data Sources > Connecting to a data source > To create a data connection to an OLE database
    Chintan

Maybe you are looking for