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

  • SEARCH
  • Home
  • 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 9011183
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T02:39:45+00:00 2026-06-16T02:39:45+00:00

I am going to write a library aplication program. I work with netbeans. i

  • 0

I am going to write a library aplication program.

I work with netbeans.

i have an interface like this:

package Library;

 public interface UserInformation {

 public void setFName(String fn);
 public String getFName();
 public void setLName(String ln);
 public String getLName();
 public void setRegNum(int reg_num);
 public int getRegNum();
 public void setDate(int reg_date);
 public int getDate();
}

and my NewUserDialog implements this interface:

private String FirstName="";
private String LastName="";
private int Registration_Number=0;
private int Date=0;
private String fileadress="AllUserRecords.txt";

public NewUserDialog(java.awt.Frame parent, boolean modal) {
    super(parent, modal);
    initComponents();

}
// // <editor-fold defaultstate="collapsed" desc="Generated Code">

private void initComponents() {

    jLabel1 = new javax.swing.JLabel();
    jLabel2 = new javax.swing.JLabel();
    jLabel3 = new javax.swing.JLabel();
    jLabel4 = new javax.swing.JLabel();
    jTextField1 = new javax.swing.JTextField();
    jTextField2 = new javax.swing.JTextField();
    jTextField3 = new javax.swing.JTextField();
    jButton1 = new javax.swing.JButton();
    jButton2 = new javax.swing.JButton();
    jLabel5 = new javax.swing.JLabel();
    jLabel6 = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

    jLabel1.setFont(new java.awt.Font("Tunga", 1, 14)); // NOI18N
    jLabel1.setText("Add New User (Registration)");

    jLabel2.setText("First Name:");

    jLabel3.setText("Last Name:");

    jLabel4.setText("Date:");

    jTextField2.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jTextField2ActionPerformed(evt);
        }
    });

jButton1.setText("Create");
    jButton1.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jButton1ActionPerformed(evt);
        }
    });

    jButton2.setText("Back");

    jLabel5.setText("Registration Number is:");

    jLabel6.setText("            ");

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(layout.createSequentialGroup()
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(54, 54, 54)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jLabel2)
                        .addComponent(jLabel4)
                        .addComponent(jLabel3)
                        .addComponent(jLabel5))
                    .addGap(98, 98, 98)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jLabel6)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jTextField3)
                            .addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 81, Short.MAX_VALUE)
                            .addComponent(jButton2, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jTextField2))
                        .addComponent(jLabel1)))
                .addGroup(layout.createSequentialGroup()
                    .addGap(68, 68, 68)
                    .addComponent(jButton1)))
            .addContainerGap(141, Short.MAX_VALUE))
    );
    layout.setVerticalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(layout.createSequentialGroup()
            .addContainerGap()
            .addComponent(jLabel1)
            .addGap(26, 26, 26)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jLabel2)
                .addGroup(layout.createSequentialGroup()
                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(28, 28, 28)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel3))
                    .addGap(34, 34, 34)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel4))))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 50, Short.MAX_VALUE)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jLabel5)
                .addComponent(jLabel6))
            .addGap(27, 27, 27)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jButton1)
                .addComponent(jButton2))
            .addGap(116, 116, 116))
    );

    pack();
}// </editor-fold>                        

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
    try{
    setFName(jTextField1.getText());
    if(havedigit(FirstName)==true) throw new Exception();
    WriteToFile(getFName());
    setLName(jTextField2.getText());
    if(havedigit(LastName)==true) throw new Exception();
    WriteToFile(getLName());
    setDate(Integer.parseInt(jTextField3.getText()));
    WriteToFile(String.valueOf(getDate()));
    Random rnd1=new Random();
    Registration_Number=rnd1.nextInt(100);
    setRegNum(Registration_Number);
    WriteToFile(String.valueOf(getRegNum()));
    jLabel6.setText(String.valueOf(getRegNum()));
    }
    catch(Exception e){
        jLabel6.setText("Error!");
    }
}                                        

public boolean havedigit(String in){
    for(int i=0;i<in.length();i++){
        if(Character.isDigit(in.charAt(i)))  return true;
    }
    return false;
}

public void WriteToFile(String content){
    try{
        File f=new File("C:\\userrecords.txt");
        if(!f.exists()){
            f.createNewFile();
        }
        else{
            FileWriter fw=new FileWriter(f.getAbsoluteFile(), true);
            BufferedWriter bw=new BufferedWriter(fw);
            bw.write(content);
            bw.newLine();
            bw.close();
            System.out.println("Done");
        }
    }
    catch(Exception e){
        e.printStackTrace();
    }

}

public static void main(String args[]) {
    java.awt.EventQueue.invokeLater(new Runnable() {
        public void run() {
            NewUserDialog dialog = new NewUserDialog(new javax.swing.JFrame(), true);
            dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                public void windowClosing(java.awt.event.WindowEvent e) {
                    System.exit(0);
                }
            });
            dialog.setVisible(true);
        }
    });
}

// Variables declaration - do not modify                     
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JTextField jTextField1;
private javax.swing.JTextField jTextField2;
private javax.swing.JTextField jTextField3;
// End of variables declaration                   

public void setFName(String fn) {
    FirstName.equals(fn);
}

public String getFName() {
    return FirstName;
}

public void setLName(String ln) {
    LastName.equals(ln);
}

public String getLName() {
    return FirstName;
}

public void setRegNum(int reg_num) {
    Registration_Number=reg_num;
}

public int getRegNum() {
    return Registration_Number;
}

public void setDate(int reg_date) {
    Date=reg_date;
}

 public int getDate() {
   return Date;
}
}

my purpose is that when we file the jtextfile fields and clicked the button, this data should save into a .txt file .
but both Fname and Lname did not save to file, just the “Date” file save to file.
and i want that Fname and Lname and Data must store regular in text file.

thanks!

  • 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-06-16T02:39:46+00:00Added an answer on June 16, 2026 at 2:39 am

    Your setter methods, setFName(...) and setLName(...) don’t do any setting at all. Instead all they do is perform an unnecessary and inexplicable test of equality and then discard the result:

    public void setLName(String ln) {
        LastName.equals(ln); // ???????
    }
    

    How about instead creating true setter methods that set the object held by a reference variable:

    public void setLName(String ln) {
        lastName = ln; // note variable names should begin w/ a lowercase letter
    }
    

    If you don’t set these fields, then you can’t expect the information from the getter methods to be useful when writing to file.

    Also you have a weak catch block that does not inform you of the contents of the stack trace, information that may help you figure out what is wrong.

    Also, what purpose is there for your GUI to implement a non-GUI interface that seems better suited for a model class, not a view (GUI) class? I would favor composition here instead of inheritance.

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

Sidebar

Related Questions

We're going to have to write a C library and this library has to
Lets say we have a native library that works with data like this: double
Im new on this project and am going to write, what i thought was
I'm going to write simple c++ application, server-client, client-client. I would like to develop
I have to write a library which contains a function that takes two strings
In the past I wrote a C# library to work with OpenOffice and this
I am going to write a restful API, my requirement is to call methods
I am going to write an app for google services, but I stuck at
I'm going to write a CMS, but right now I'm writing down all my
We are going to write an entire new application for a reservation system. 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.