Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5939437
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:49:41+00:00 2026-05-22T15:49:41+00:00

I have been using the Learning Java 2nd Edtion book to try make my

  • 0

I have been using the “Learning Java 2nd Edtion” book to try make my java application write my input to a text file called properties. I have manipulated the text book example into my own code but still having problems trying to get it to work. I think i may need to hook it up to my submit button but this wasnt mentioned within the chapter.

Basically im trying to store the information in the text file and then use that text file within another location to read all of the property details.

Here is my code for the AddProperty Page so far any advice would be greatly appreciated.
At the moment iv hit the wall.

/**
 *
 * @author Graeme
 */
package Login;

import java.io.*;

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.border.EmptyBorder;

public class AddProperty
{
public void AddProperty()
{

    JFrame frame = new JFrame("AddPropertyFrame");
    frame.setVisible(true);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    // having to set sizes of components is rare, and often a sign    
    // of problems with layouts.
    //frame.setSize(800,600);
    JPanel panel = new JPanel(new FlowLayout(FlowLayout.CENTER, 20,20));
    // make it big like the original
    panel.setBorder(new EmptyBorder(100,20,100,20));
    frame.add(panel);
    //panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));

    JLabel HouseNumber = new JLabel("House Number/Name");
    panel.add(HouseNumber);
    JTextField HouseNumber1 = new JTextField(10);
    panel.add(HouseNumber1);

    JLabel HousePrice = new JLabel("House Price");
    panel.add(HousePrice);
    JTextField HousePrice1 = new JTextField(10);
    panel.add(HousePrice1);

    JLabel HouseType = new JLabel("House Type");
    panel.add(HouseType);
    JTextField HouseType1 = new JTextField(10);
    panel.add(HouseType1);

    JLabel Location = new JLabel("Location");
    panel.add(Location);
    JTextField Location1 = new JTextField(10);
    panel.add(Location1);

    JButton submit = new JButton("Submit");
    panel.add(submit);
    submit.addActionListener(new Action());

    // tell the GUI to assume its natural (minimum) size.
    frame.pack();
}

static class Action implements ActionListener{

    @Override
    public void actionPerformed (ActionEvent e)
    {
        // this should probably be a modal JDialog or JOptionPane.
       JOptionPane.showMessageDialog(null, "You have successfully submitted a property.");
    }

    static class propertyList 
    {
        public static void main (String args[]) throws Exception {
            File properties = new File(args[0]);

            if (!properties.exists() || !properties.canRead() ) {
                System.out.println("Cant read " + properties);
                return;
            }
            if (properties.isDirectory()){
                String [] properties1 = properties.list();
                for (int i=0; i< properties1.length; i++)
                    System.out.println();
            }
            else
                try {
                    FileReader fr = new FileReader (properties);
                    BufferedReader in = new BufferedReader (fr);
                    String line;
                    while ((line = in.readLine())!= null)
                    System.out.println(line);
                }
            catch (FileNotFoundException e){
                System.out.println("Not Able To Find File");
            }
        }
    }
}

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T15:49:42+00:00Added an answer on May 22, 2026 at 3:49 pm

    in your Action performed you are not stating anything, for example in your action performed you could add.

       public void actionPerformed(ActionEvent e)
                {
    
                  houseNumber2 = houseNumber1.getText();
                  housePrice2 = housePrice1.getText();
                  town1 = town.getText();
                  comboBoxType2 = comboBoxType1.getSelectedItem();
    
    
                inputData = housenumber2 + "," + housePrice2 + "," + town1 + "," + comboBoxType2;
                 FileName.Filewritermethod(inputData);
                 frame.setVisible(false);
    
                }
           });
    

    This would strings to take the values of your JTexFields and pass them onto a textfile provided you have a FileWriter Class

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been learning prolog.. I'm using a editor named prol1.1.1 I need to
I have only started learning Java. My task is to create a file server
I have been using Grails for last 3 weeks (learning and working). I have
I have been using Silverlight for quite a bit and am learning Windows Phone
I am learning OpenXML. I have been looking for hours trying to find how
I am currently porting my Android app to a desktop app using Java (Swing,
I'm learning JavaBeans and it's application I'm creating my first ever Bean, I use
I wonder if someone can help me... I've been developing VB.Net for years and
Ok... so here's my actual status: Been a PHP Scripter for way too long,
I need to maintain & improve an existing website and I am drowning in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.