Java Program II assignment 2

Now that you have your GUI operational, it is time to take the application a step further. Management would like you to write the entered data into a file. They intend to use an application to read this file, evaluate the entered data, and display results. These results will help management to make decisions on sales force direction and expansion. Each time the ENTER button is pressed, the entered sales representative’s data will be written out to a file. A new button, EVALUATE will be added that reads in the sales representative’s data file after it has been created.

Save Time On Research and Writing
Hire a Pro to Write You a 100% Plagiarism-Free Paper.
Get My Paper

Design Requirements:

You must use pseudocode to design your algorithm for the ENTER button functionality.These design artifacts (pseudocode) will be inserted into a design document to be reviewed by your classmates and submitted with the final application for the final task.

Application Requirements:

Expand your Swing application to write the entered data out to a text file. Instead of displaying the data in the jTextArea when ENTER is pressed, change this functionality so that the data is written to a file. Name the output file salesrep.txt. Each time the ENTER button is pressed, the data will be written to the file. Write the data in the following format to a text file, using white spaces as the delimiter. Include the categories (SUPPLIES, BOOKS, PAPER) in your file to label the dollar amount sold for each category. The sales district entered should be converted to upper case (NORTH, SOUTH, EAST, WEST). Independent line separators should be used in the output file. Code for the ENTER button should be well commented.

Save Time On Research and Writing
Hire a Pro to Write You a 100% Plagiarism-Free Paper.
Get My Paper

Format of your file:

salesRepID firstName lastName SUPPLIES totalAmountSuppliesSold BOOKS totalAmountBooksSold PAPER totalAmountPaperSold district contactMeans

Example output file contents:

1001 Jennifer Ward SUPPLIES 2140.20 BOOKS 5200.10 PAPER 455.23 NORTH Phone1003 Athena Andrews SUPPLIES 5155.55 BOOKS 6300.50 PAPER 223.25 SOUTH Email

Each time the ENTER button is pressed, the application should append a new line to the file. When the application starts, the file should be opened for appending. This file is to keep a running history of the entered data

Discussion Board 2

William Denison

27 NOV 2014

A Java class that allows writing to files is Class FileWriter. This class is a part of java.io package and extends (inherits from) OutputStreamWriter class.

This class allows us to write character files conveniently. The reason I chose this class is because of the functionality provided by FileWriter class. It allows us to write to a new file, as well as append content to an existing file. Given a filename as a string parameter, it creates the file if it does not already exist. So, the user is not required to explicitly create a new file before writing to it using FileWriter class.

FileWriter class provides several constructors, which are as follows:

1) FileWriter(File file) – takes File object as a parameter, which corresponds to the file, the data is to be written to.

2) FileWriter(File file, boolean append) – takes two parameters: one is the File object to which data is to be written to, and second is a boolean parameter which indicates whether data is to be appended to the file

3) FileWriter(String filename) – takes a string parameter for the filename

4) FileWriter(String filename, Boolean append) – takes two parameters, one for the filename (string) and a Boolean value indicating whether data should be appended to the file or not

Pseudo code:

1. Create a string array and initialize elements of the array with given data

String[] dataArray = new String[4];

dataArray[0] = “1001 Jennifer Ward SUPPLIES 2140.20 BOOKS 5200.10 PAPER 455.23 NORTH Phone”;

dataArray[1] = “1003 Athena Andrews SUPPLIES 5155.55 BOOKS 6300.50 PAPER 223.25 SOUTH Email”;

dataArray[2] = “1005 Andy Smith SUPPLIES 6155.55 BOOKS 300.50 PAPER 55.55 SOUTH Email”;

dataArray[3] = “1006 Robert Stearns SUPPLIES 7255.55 BOOKS 8300.50 PAPER 77.77 SOUTH Phone”;

2. Create a File object and pass the filename

File file = new File(“data.txt”);

3. Check if file exits by that name, if it does not create a new file as follows:

file.createNewFile();

4. Create FileWriter object by passing the File object created above

5. In a for loop write each element of the array to the file:

for(int i=0; i{

writer.write(dataArray[i]); //write the line to file

writer.write(“\n”); //write a newline to the file

}

6. Close the writer.

7. Catch any exceptions if thrown

RealCode:

import java.io.*;

class FileWritingExample

{

public static void main(String args[]){

String[] dataArray = new String[4];

dataArray[0] = “1001 Jennifer Ward SUPPLIES 2140.20 BOOKS 5200.10 PAPER 455.23 NORTH Phone”;

dataArray[1] = “1003 Athena Andrews SUPPLIES 5155.55 BOOKS 6300.50 PAPER 223.25 SOUTH Email”;

dataArray[2] = “1005 Andy Smith SUPPLIES 6155.55 BOOKS 300.50 PAPER 55.55 SOUTH Email”;

dataArray[3] = “1006 Robert Stearns SUPPLIES 7255.55 BOOKS 8300.50 PAPER 77.77 SOUTH Phone”;

try{

File file = new File(“data.txt”);

//check if file already exists

if(!file.exists()){

file.createNewFile(); //create a new file if it does not exist

}

//create FileWriter object using File object created above

FileWriter writer = new FileWriter(file);

//write content to file

for(int i=0; i

writer.write(dataArray[i]); //write the line to file

writer.write(“\n”); //write a newline to the file

}

writer.flush();

writer.close(); //close the writer stream

}catch(IOException ioe){

//display the exception stacktrace

System.out.println(“Error while writing to the file”);

ioe.printStackTrace();

}

}

}

ProjectGUI/nbproject/private/private.properties
compile.on.save=true
user.properties.file=/home/an/.netbeans/7.1.1/build.properties

ProjectGUI/src/projectgui/GUI.form

ProjectGUI/src/projectgui/GUI.java
ProjectGUI/src/projectgui/GUI.java
/*

 * GUI.java

 *

 */

package
 projectgui
;

import
 java
.
awt
.
Color
;

import
 javax
.
swing
.
JOptionPane
;

/**

 *

 * 
@author
 Asma Niaz

 */

public
 
class
 GUI 
extends
 javax
.
swing
.
JFrame
 
{

    
/**

     * Creates new form SingleNeutronRun

     */

    
public
 GUI
()
 
{

        initComponents
();

    
}

    
/**

     * This method is called from within the constructor to initialize the form.

     * WARNING: Do NOT modify this code. The content of this method is always

     * regenerated by the Form Editor.

     */

    @
SuppressWarnings
(
“unchecked”
)

    
// //GEN-BEGIN:initComponents

    
private
 
void
 initComponents
()
 
{

        operationsButtonGroup 
=
 
new
 javax
.
swing
.
ButtonGroup
();

        buttonGroup1 
=
 
new
 javax
.
swing
.
ButtonGroup
();

        districtPanel 
=
 
new
 javax
.
swing
.
JPanel
();

        northRadioButton 
=
 
new
 javax
.
swing
.
JRadioButton
();

        eastRadioButton 
=
 
new
 javax
.
swing
.
JRadioButton
();

        southRadioButton 
=
 
new
 javax
.
swing
.
JRadioButton
();

        westRadioButton 
=
 
new
 javax
.
swing
.
JRadioButton
();

        inputPanel 
=
 
new
 javax
.
swing
.
JPanel
();

        jTextField2 
=
 
new
 javax
.
swing
.
JTextField
();

        jTextField3 
=
 
new
 javax
.
swing
.
JTextField
();

        jTextField1 
=
 
new
 javax
.
swing
.
JTextField
();

        jLabel1 
=
 
new
 javax
.
swing
.
JLabel
();

        jLabel2 
=
 
new
 javax
.
swing
.
JLabel
();

        jLabel3 
=
 
new
 javax
.
swing
.
JLabel
();

        inputPanel1 
=
 
new
 javax
.
swing
.
JPanel
();

        jTextField4 
=
 
new
 javax
.
swing
.
JTextField
();

        jTextField5 
=
 
new
 javax
.
swing
.
JTextField
();

        jTextField6 
=
 
new
 javax
.
swing
.
JTextField
();

        jLabel5 
=
 
new
 javax
.
swing
.
JLabel
();

        jLabel6 
=
 
new
 javax
.
swing
.
JLabel
();

        jLabel4 
=
 
new
 javax
.
swing
.
JLabel
();

        runButton 
=
 
new
 javax
.
swing
.
JButton
();

        exitButton 
=
 
new
 javax
.
swing
.
JButton
();

        
DataPanel
 
=
 
new
 javax
.
swing
.
JPanel
();

        jScrollPane1 
=
 
new
 javax
.
swing
.
JScrollPane
();

        dataTextArea 
=
 
new
 javax
.
swing
.
JTextArea
();

        districtPanel1 
=
 
new
 javax
.
swing
.
JPanel
();

        phoneCheckBox 
=
 
new
 javax
.
swing
.
JCheckBox
();

        emailCheckBox 
=
 
new
 javax
.
swing
.
JCheckBox
();

        visitCheckBox 
=
 
new
 javax
.
swing
.
JCheckBox
();

        setDefaultCloseOperation
(
javax
.
swing
.
WindowConstants
.
EXIT_ON_CLOSE
);

        setTitle
(
“Single Neuron Perceptron”
);

        districtPanel
.
setBorder
(
javax
.
swing
.
BorderFactory
.
createTitledBorder
(
“Select District”
));

        buttonGroup1
.
add
(
northRadioButton
);

        northRadioButton
.
setSelected
(
true
);

        northRadioButton
.
setText
(
“North”
);

        buttonGroup1
.
add
(
eastRadioButton
);

        eastRadioButton
.
setText
(
“East”
);

        buttonGroup1
.
add
(
southRadioButton
);

        southRadioButton
.
setText
(
“South”
);

        buttonGroup1
.
add
(
westRadioButton
);

        westRadioButton
.
setText
(
“West”
);

        javax
.
swing
.
GroupLayout
 districtPanelLayout 
=
 
new
 javax
.
swing
.
GroupLayout
(
districtPanel
);

        districtPanel
.
setLayout
(
districtPanelLayout
);

        districtPanelLayout
.
setHorizontalGroup
(

            districtPanelLayout
.
createParallelGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
LEADING
)

            
.
addGroup
(
districtPanelLayout
.
createSequentialGroup
()

                
.
addContainerGap
()

                
.
addGroup
(
districtPanelLayout
.
createParallelGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
LEADING
)

                    
.
addComponent
(
northRadioButton
)

                    
.
addComponent
(
eastRadioButton
)

                    
.
addComponent
(
southRadioButton
)

                    
.
addComponent
(
westRadioButton
))

                
.
addContainerGap
(
69
,
 
Short
.
MAX_VALUE
))

        
);

        districtPanelLayout
.
setVerticalGroup
(

            districtPanelLayout
.
createParallelGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
LEADING
)

            
.
addGroup
(
districtPanelLayout
.
createSequentialGroup
()

                
.
addComponent
(
northRadioButton
)

                
.
addPreferredGap
(
javax
.
swing
.
LayoutStyle
.
ComponentPlacement
.
RELATED
)

                
.
addComponent
(
southRadioButton
)

                
.
addPreferredGap
(
javax
.
swing
.
LayoutStyle
.
ComponentPlacement
.
RELATED
)

                
.
addComponent
(
eastRadioButton
)

                
.
addPreferredGap
(
javax
.
swing
.
LayoutStyle
.
ComponentPlacement
.
RELATED
)

                
.
addComponent
(
westRadioButton
))

        
);

        northRadioButton
.
getAccessibleContext
().
setAccessibleName
(
“northRadioButton”
);

        inputPanel
.
setBorder
(
javax
.
swing
.
BorderFactory
.
createTitledBorder
(
“Enter Values”
));

        jTextField2
.
addFocusListener
(
new
 java
.
awt
.
event
.
FocusAdapter
()
 
{

            
public
 
void
 focusLost
(
java
.
awt
.
event
.
FocusEvent
 evt
)
 
{

                jTextField2FocusLost
(
evt
);

            
}

        
});

        jTextField3
.
addFocusListener
(
new
 java
.
awt
.
event
.
FocusAdapter
()
 
{

            
public
 
void
 focusLost
(
java
.
awt
.
event
.
FocusEvent
 evt
)
 
{

                jTextField3FocusLost
(
evt
);

            
}

        
});

        jTextField1
.
addFocusListener
(
new
 java
.
awt
.
event
.
FocusAdapter
()
 
{

            
public
 
void
 focusLost
(
java
.
awt
.
event
.
FocusEvent
 evt
)
 
{

                jTextField1FocusLost
(
evt
);

            
}

        
});

        jLabel1
.
setText
(
“Sales Rep ID”
);

        jLabel2
.
setText
(
“Sales Rep First Name”
);

        jLabel3
.
setText
(
“Sales Rep Last Name”
);

        inputPanel1
.
setBorder
(
javax
.
swing
.
BorderFactory
.
createTitledBorder
(
“Amounts Sold”
));

        jTextField4
.
addFocusListener
(
new
 java
.
awt
.
event
.
FocusAdapter
()
 
{

            
public
 
void
 focusLost
(
java
.
awt
.
event
.
FocusEvent
 evt
)
 
{

                jTextField4FocusLost
(
evt
);

            
}

        
});

        jTextField5
.
addFocusListener
(
new
 java
.
awt
.
event
.
FocusAdapter
()
 
{

            
public
 
void
 focusLost
(
java
.
awt
.
event
.
FocusEvent
 evt
)
 
{

                jTextField5FocusLost
(
evt
);

            
}

        
});

        jTextField6
.
addFocusListener
(
new
 java
.
awt
.
event
.
FocusAdapter
()
 
{

            
public
 
void
 focusLost
(
java
.
awt
.
event
.
FocusEvent
 evt
)
 
{

                jTextField6FocusLost
(
evt
);

            
}

        
});

        jLabel5
.
setText
(
“Books”
);

        jLabel6
.
setText
(
“Paper”
);

        jLabel4
.
setText
(
“Office Supplies”
);

        javax
.
swing
.
GroupLayout
 inputPanel1Layout 
=
 
new
 javax
.
swing
.
GroupLayout
(
inputPanel1
);

        inputPanel1
.
setLayout
(
inputPanel1Layout
);

        inputPanel1Layout
.
setHorizontalGroup
(

            inputPanel1Layout
.
createParallelGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
LEADING
)

            
.
addGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
TRAILING
,
 inputPanel1Layout
.
createSequentialGroup
()

                
.
addContainerGap
(
javax
.
swing
.
GroupLayout
.
DEFAULT_SIZE
,
 
Short
.
MAX_VALUE
)

                
.
addGroup
(
inputPanel1Layout
.
createParallelGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
LEADING
)

                    
.
addComponent
(
jLabel4
)

                    
.
addComponent
(
jLabel6
)

                    
.
addComponent
(
jLabel5
))

                
.
addPreferredGap
(
javax
.
swing
.
LayoutStyle
.
ComponentPlacement
.
RELATED
)

                
.
addGroup
(
inputPanel1Layout
.
createParallelGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
LEADING
,
 
false
)

                    
.
addComponent
(
jTextField5
,
 javax
.
swing
.
GroupLayout
.
Alignment
.
TRAILING
,
 javax
.
swing
.
GroupLayout
.
DEFAULT_SIZE
,
 
133
,
 
Short
.
MAX_VALUE
)

                    
.
addComponent
(
jTextField4
,
 javax
.
swing
.
GroupLayout
.
Alignment
.
TRAILING
)

                    
.
addComponent
(
jTextField6
))

                
.
addContainerGap
())

        
);

        inputPanel1Layout
.
setVerticalGroup
(

            inputPanel1Layout
.
createParallelGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
LEADING
)

            
.
addGroup
(
inputPanel1Layout
.
createSequentialGroup
()

                
.
addGroup
(
inputPanel1Layout
.
createParallelGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
LEADING
)

                    
.
addComponent
(
jLabel4
)

                    
.
addGroup
(
inputPanel1Layout
.
createSequentialGroup
()

                        
.
addGap
(
4
,
 
4
,
 
4
)

                        
.
addComponent
(
jTextField4
,
 javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
,
 javax
.
swing
.
GroupLayout
.
DEFAULT_SIZE
,
 javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
)))

                
.
addPreferredGap
(
javax
.
swing
.
LayoutStyle
.
ComponentPlacement
.
RELATED
)

                
.
addGroup
(
inputPanel1Layout
.
createParallelGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
LEADING
)

                    
.
addComponent
(
jTextField5
,
 javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
,
 javax
.
swing
.
GroupLayout
.
DEFAULT_SIZE
,
 javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
)

                    
.
addComponent
(
jLabel5
))

                
.
addPreferredGap
(
javax
.
swing
.
LayoutStyle
.
ComponentPlacement
.
RELATED
)

                
.
addGroup
(
inputPanel1Layout
.
createParallelGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
LEADING
)

                    
.
addComponent
(
jTextField6
,
 javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
,
 javax
.
swing
.
GroupLayout
.
DEFAULT_SIZE
,
 javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
)

                    
.
addComponent
(
jLabel6
)))

        
);

        javax
.
swing
.
GroupLayout
 inputPanelLayout 
=
 
new
 javax
.
swing
.
GroupLayout
(
inputPanel
);

        inputPanel
.
setLayout
(
inputPanelLayout
);

        inputPanelLayout
.
setHorizontalGroup
(

            inputPanelLayout
.
createParallelGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
LEADING
)

            
.
addGroup
(
inputPanelLayout
.
createSequentialGroup
()

                
.
addContainerGap
()

                
.
addGroup
(
inputPanelLayout
.
createParallelGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
LEADING
)

                    
.
addGroup
(
inputPanelLayout
.
createSequentialGroup
()

                        
.
addGroup
(
inputPanelLayout
.
createParallelGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
LEADING
)

                            
.
addComponent
(
jLabel1
)

                            
.
addComponent
(
jLabel3
)

                            
.
addComponent
(
jLabel2
))

                        
.
addPreferredGap
(
javax
.
swing
.
LayoutStyle
.
ComponentPlacement
.
UNRELATED
)

                        
.
addGroup
(
inputPanelLayout
.
createParallelGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
LEADING
)

                            
.
addComponent
(
jTextField2
)

                            
.
addComponent
(
jTextField3
,
 javax
.
swing
.
GroupLayout
.
Alignment
.
TRAILING
)

                            
.
addComponent
(
jTextField1
)))

                    
.
addGroup
(
inputPanelLayout
.
createSequentialGroup
()

                        
.
addGap
(
0
,
 
21
,
 
Short
.
MAX_VALUE
)

                        
.
addComponent
(
inputPanel1
,
 javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
,
 javax
.
swing
.
GroupLayout
.
DEFAULT_SIZE
,
 javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
)))

                
.
addContainerGap
())

        
);

        inputPanelLayout
.
setVerticalGroup
(

            inputPanelLayout
.
createParallelGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
LEADING
)

            
.
addGroup
(
inputPanelLayout
.
createSequentialGroup
()

                
.
addGroup
(
inputPanelLayout
.
createParallelGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
BASELINE
)

                    
.
addComponent
(
jTextField1
,
 javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
,
 javax
.
swing
.
GroupLayout
.
DEFAULT_SIZE
,
 javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
)

                    
.
addComponent
(
jLabel1
))

                
.
addPreferredGap
(
javax
.
swing
.
LayoutStyle
.
ComponentPlacement
.
RELATED
)

                
.
addGroup
(
inputPanelLayout
.
createParallelGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
LEADING
)

                    
.
addComponent
(
jTextField2
,
 javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
,
 javax
.
swing
.
GroupLayout
.
DEFAULT_SIZE
,
 javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
)

                    
.
addComponent
(
jLabel2
))

                
.
addPreferredGap
(
javax
.
swing
.
LayoutStyle
.
ComponentPlacement
.
RELATED
)

                
.
addGroup
(
inputPanelLayout
.
createParallelGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
LEADING
)

                    
.
addComponent
(
jTextField3
,
 javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
,
 javax
.
swing
.
GroupLayout
.
DEFAULT_SIZE
,
 javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
)

                    
.
addComponent
(
jLabel3
))

                
.
addGap
(
18
,
 
18
,
 
18
)

                
.
addComponent
(
inputPanel1
,
 javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
,
 javax
.
swing
.
GroupLayout
.
DEFAULT_SIZE
,
 javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
)

                
.
addContainerGap
(
javax
.
swing
.
GroupLayout
.
DEFAULT_SIZE
,
 
Short
.
MAX_VALUE
))

        
);

        runButton
.
setText
(
“ENTER”
);

        runButton
.
addActionListener
(
new
 java
.
awt
.
event
.
ActionListener
()
 
{

            
public
 
void
 actionPerformed
(
java
.
awt
.
event
.
ActionEvent
 evt
)
 
{

                runButtonActionPerformed
(
evt
);

            
}

        
});

        exitButton
.
setText
(
“QUIT”
);

        exitButton
.
addActionListener
(
new
 java
.
awt
.
event
.
ActionListener
()
 
{

            
public
 
void
 actionPerformed
(
java
.
awt
.
event
.
ActionEvent
 evt
)
 
{

                exitButtonActionPerformed
(
evt
);

            
}

        
});

        
DataPanel
.
setBorder
(
javax
.
swing
.
BorderFactory
.
createTitledBorder
(
“Sales Representative Data”
));

        dataTextArea
.
setColumns
(
20
);

        dataTextArea
.
setRows
(
5
);

        jScrollPane1
.
setViewportView
(
dataTextArea
);

        javax
.
swing
.
GroupLayout
 
DataPanelLayout
 
=
 
new
 javax
.
swing
.
GroupLayout
(
DataPanel
);

        
DataPanel
.
setLayout
(
DataPanelLayout
);

        
DataPanelLayout
.
setHorizontalGroup
(

            
DataPanelLayout
.
createParallelGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
LEADING
)

            
.
addGroup
(
DataPanelLayout
.
createSequentialGroup
()

                
.
addContainerGap
()

                
.
addComponent
(
jScrollPane1
,
 javax
.
swing
.
GroupLayout
.
DEFAULT_SIZE
,
 
276
,
 
Short
.
MAX_VALUE
)

                
.
addContainerGap
())

        
);

        
DataPanelLayout
.
setVerticalGroup
(

            
DataPanelLayout
.
createParallelGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
LEADING
)

            
.
addGroup
(
DataPanelLayout
.
createSequentialGroup
()

                
.
addComponent
(
jScrollPane1
,
 javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
,
 
160
,
 javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
)

                
.
addGap
(
0
,
 
0
,
 
Short
.
MAX_VALUE
))

        
);

        districtPanel1
.
setBorder
(
javax
.
swing
.
BorderFactory
.
createTitledBorder
(
“Select Contact Means”
));

        phoneCheckBox
.
setText
(
“Phone”
);

        emailCheckBox
.
setText
(
“Email”
);

        visitCheckBox
.
setText
(
“Visit”
);

        javax
.
swing
.
GroupLayout
 districtPanel1Layout 
=
 
new
 javax
.
swing
.
GroupLayout
(
districtPanel1
);

        districtPanel1
.
setLayout
(
districtPanel1Layout
);

        districtPanel1Layout
.
setHorizontalGroup
(

            districtPanel1Layout
.
createParallelGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
LEADING
)

            
.
addGroup
(
districtPanel1Layout
.
createSequentialGroup
()

                
.
addGroup
(
districtPanel1Layout
.
createParallelGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
LEADING
)

                    
.
addComponent
(
phoneCheckBox
)

                    
.
addComponent
(
emailCheckBox
)

                    
.
addComponent
(
visitCheckBox
))

                
.
addGap
(
0
,
 
0
,
 
Short
.
MAX_VALUE
))

        
);

        districtPanel1Layout
.
setVerticalGroup
(

            districtPanel1Layout
.
createParallelGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
LEADING
)

            
.
addGroup
(
districtPanel1Layout
.
createSequentialGroup
()

                
.
addComponent
(
phoneCheckBox
)

                
.
addPreferredGap
(
javax
.
swing
.
LayoutStyle
.
ComponentPlacement
.
RELATED
)

                
.
addComponent
(
emailCheckBox
)

                
.
addPreferredGap
(
javax
.
swing
.
LayoutStyle
.
ComponentPlacement
.
RELATED
)

                
.
addComponent
(
visitCheckBox
)

                
.
addGap
(
0
,
 
5
,
 
Short
.
MAX_VALUE
))

        
);

        javax
.
swing
.
GroupLayout
 layout 
=
 
new
 javax
.
swing
.
GroupLayout
(
getContentPane
());

        getContentPane
().
setLayout
(
layout
);

        layout
.
setHorizontalGroup
(

            layout
.
createParallelGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
LEADING
)

            
.
addGroup
(
layout
.
createSequentialGroup
()

                
.
addContainerGap
()

                
.
addGroup
(
layout
.
createParallelGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
LEADING
)

                    
.
addGroup
(
layout
.
createSequentialGroup
()

                        
.
addComponent
(
DataPanel
,
 javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
,
 javax
.
swing
.
GroupLayout
.
DEFAULT_SIZE
,
 javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
)

                        
.
addPreferredGap
(
javax
.
swing
.
LayoutStyle
.
ComponentPlacement
.
RELATED
,
 javax
.
swing
.
GroupLayout
.
DEFAULT_SIZE
,
 
Short
.
MAX_VALUE
)

                        
.
addGroup
(
layout
.
createParallelGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
LEADING
,
 
false
)

                            
.
addComponent
(
runButton
,
 javax
.
swing
.
GroupLayout
.
DEFAULT_SIZE
,
 
189
,
 
Short
.
MAX_VALUE
)

                            
.
addComponent
(
exitButton
,
 javax
.
swing
.
GroupLayout
.
DEFAULT_SIZE
,
 javax
.
swing
.
GroupLayout
.
DEFAULT_SIZE
,
 
Short
.
MAX_VALUE
)))

                    
.
addGroup
(
layout
.
createSequentialGroup
()

                        
.
addGroup
(
layout
.
createParallelGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
LEADING
,
 
false
)

                            
.
addComponent
(
districtPanel1
,
 javax
.
swing
.
GroupLayout
.
DEFAULT_SIZE
,
 javax
.
swing
.
GroupLayout
.
DEFAULT_SIZE
,
 
Short
.
MAX_VALUE
)

                            
.
addComponent
(
districtPanel
,
 javax
.
swing
.
GroupLayout
.
DEFAULT_SIZE
,
 javax
.
swing
.
GroupLayout
.
DEFAULT_SIZE
,
 
Short
.
MAX_VALUE
))

                        
.
addGap
(
27
,
 
27
,
 
27
)

                        
.
addComponent
(
inputPanel
,
 javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
,
 javax
.
swing
.
GroupLayout
.
DEFAULT_SIZE
,
 javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
)

                        
.
addGap
(
0
,
 
0
,
 
Short
.
MAX_VALUE
)))

                
.
addContainerGap
())

        
);

        layout
.
setVerticalGroup
(

            layout
.
createParallelGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
LEADING
)

            
.
addGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
TRAILING
,
 layout
.
createSequentialGroup
()

                
.
addContainerGap
(
javax
.
swing
.
GroupLayout
.
DEFAULT_SIZE
,
 
Short
.
MAX_VALUE
)

                
.
addGroup
(
layout
.
createParallelGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
LEADING
,
 
false
)

                    
.
addComponent
(
inputPanel
,
 javax
.
swing
.
GroupLayout
.
Alignment
.
TRAILING
,
 javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
,
 
268
,
 javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
)

                    
.
addGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
TRAILING
,
 layout
.
createSequentialGroup
()

                        
.
addComponent
(
districtPanel
,
 javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
,
 javax
.
swing
.
GroupLayout
.
DEFAULT_SIZE
,
 javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
)

                        
.
addPreferredGap
(
javax
.
swing
.
LayoutStyle
.
ComponentPlacement
.
RELATED
,
 javax
.
swing
.
GroupLayout
.
DEFAULT_SIZE
,
 
Short
.
MAX_VALUE
)

                        
.
addComponent
(
districtPanel1
,
 javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
,
 javax
.
swing
.
GroupLayout
.
DEFAULT_SIZE
,
 javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
)))

                
.
addGap
(
18
,
 
18
,
 
18
)

                
.
addGroup
(
layout
.
createParallelGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
LEADING
)

                    
.
addGroup
(
layout
.
createSequentialGroup
()

                        
.
addComponent
(
DataPanel
,
 javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
,
 javax
.
swing
.
GroupLayout
.
DEFAULT_SIZE
,
 javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
)

                        
.
addContainerGap
())

                    
.
addGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
TRAILING
,
 layout
.
createSequentialGroup
()

                        
.
addGap
(
0
,
 
0
,
 
Short
.
MAX_VALUE
)

                        
.
addComponent
(
runButton
)

                        
.
addPreferredGap
(
javax
.
swing
.
LayoutStyle
.
ComponentPlacement
.
UNRELATED
)

                        
.
addComponent
(
exitButton
)

                        
.
addGap
(
71
,
 
71
,
 
71
))))

        
);

        
DataPanel
.
getAccessibleContext
().
setAccessibleName
(
“”
);

        pack
();

    
}
// //GEN-END:initComponents

    
private
 
void
 runButtonActionPerformed
(
java
.
awt
.
event
.
ActionEvent
 evt
)
 
{
//GEN-FIRST:event_runButtonActionPerformed

        
// TODO add your handling code here:

        
String
 district 
=
 
“”
;

        
String
 meansOfContact 
=
 
“”
;

        
//check if any required field is empty

        
if
 
(
jTextField1
.
getText
().
isEmpty
()
 
||
 jTextField2
.
getText
().
isEmpty
()
 
||
 jTextField3
.
getText
().
isEmpty
()
 
||
 jTextField4
.
getText
().
isEmpty
())
 
{

            
//mark the required empty field with a red label and asterisk and ask for input

            
if
 
(
jTextField1
.
getText
().
isEmpty
())
 
{

                jLabel1
.
setText
(
“* Sales representative ”
);

                jLabel1
.
setForeground
(
Color
.
red
);

            
}

            
if
 
(
jTextField2
.
getText
().
isEmpty
())
 
{

                jLabel2
.
setText
(
“* Sales representative First Name”
);

                jLabel2
.
setForeground
(
Color
.
red
);

            
}

            
if
 
(
jTextField3
.
getText
().
isEmpty
())
 
{

                jLabel3
.
setText
(
“* Sales Rep Last Name”
);

                jLabel3
.
setForeground
(
Color
.
red
);

            
}

            
if
 
(
jTextField4
.
getText
().
isEmpty
())
 
{

                jLabel4
.
setText
(
“* Office Supplies”
);

                jLabel4
.
setForeground
(
Color
.
red
);

            
}

            
if
 
(
jTextField5
.
getText
().
isEmpty
())
 
{

                jLabel5
.
setText
(
“* Books”
);

                jLabel5
.
setForeground
(
Color
.
red
);

            
}

            
if
 
(
jTextField6
.
getText
().
isEmpty
())
 
{

                jLabel6
.
setText
(
“* Papers”
);

                jLabel6
.
setForeground
(
Color
.
red
);

            
}

            
JOptionPane
.
showMessageDialog
(
inputPanel
,
 
“Please Enter the Required Input”
);

        
}
 
else
 
//complete input was entered

        
{

            
try
 
{

                
//check input datatypes

                
if
 
(
Integer
.
parseInt
(
jTextField4
.
getText
())
 
>=
 
0
 
&&
 
Integer
.
parseInt
(
jTextField5
.
getText
())
 
>=
 
0
 
&&
 
Integer
.
parseInt
(
jTextField6
.
getText
())
 
>=
 
0
)
 
{

                    
//set the district according to selection

                    
if
 
(
northRadioButton
.
isSelected
())
 
{

                        district 
=
 
“North”
;

                    
}
 
else
 
if
 
(
southRadioButton
.
isSelected
())
 
{

                        district 
=
 
“South”
;

                    
}
 
else
 
if
 
(
eastRadioButton
.
isSelected
())
 
{

                        district 
=
 
“East”
;

                    
}
 
else
 
if
 
(
westRadioButton
.
isSelected
())
 
{

                        district 
=
 
“West”
;

                    
}

                    
//set all selected means of contact

                    
if
 
(
phoneCheckBox
.
isSelected
())
 
{

                        meansOfContact 
=
 meansOfContact 
+
” Phone ”
;

                    
}

                    
if
 
(
emailCheckBox
.
isSelected
())
 
{

                        meansOfContact 
=
 meansOfContact 
+
” Email ”
;

                    
}

                    
if
 
(
visitCheckBox
.
isSelected
())
 
{

                        meansOfContact 
=
 meansOfContact 
+
” Visit ”
;

                    
}

                    
//echo data

                    dataTextArea
.
setText
(
“ID: ”
 
+
 jTextField1
.
getText
()
 
+
 
“\nFirst Name: ”
 
+
 jTextField2
.
getText
()
 
+
 
“\nLast Name: ”
 
+
 jTextField3
.
getText
()
 
+
 
“\nDistrict: ”
 
+
 district 
+
 
“\nOffice Supplies Sold: ”
 
+
 jTextField4
.
getText
()
 
+
 
“\nBooks Sold: ”
 
+
 jTextField5
.
getText
()
 
+
 
“\nPapers Sold: ”
 
+
 jTextField6
.
getText
()
 
+
 
“\nMeans Of Contact: ”
 
+
 meansOfContact
);

                
}
 
else
 
{

                    
//one or more input data types are wrong

                    
JOptionPane
.
showMessageDialog
(
inputPanel
,
 
“all the Sold Amounts should be integer values”
);

                
}

            
}
 
catch
 
(
Exception
 e
)
 
{

                
JOptionPane
.
showMessageDialog
(
inputPanel
,
 
“Input Error: ”
 
+
 e
.
getMessage
()
 
+
 
“\nInput Should be integer”
);

            
}

        
}

    
}
//GEN-LAST:event_runButtonActionPerformed

    
private
 
void
 exitButtonActionPerformed
(
java
.
awt
.
event
.
ActionEvent
 evt
)
 
{
//GEN-FIRST:event_exitButtonActionPerformed

        
// TODO add your handling code here:

        
System
.
exit
(
1
);

    
}
//GEN-LAST:event_exitButtonActionPerformed

    
private
 
void
 jTextField1FocusLost
(
java
.
awt
.
event
.
FocusEvent
 evt
)
 
{
//GEN-FIRST:event_jTextField1FocusLost

        
// TODO add your handling code here:

        
if
 
(
jLabel1
.
getForeground
()
 
==
 
Color
.
red
)
 
{

            jLabel1
.
setText
(
“Sales representative ID”
);

            jLabel1
.
setForeground
(
Color
.
black
);

        
}

    
}
//GEN-LAST:event_jTextField1FocusLost

    
private
 
void
 jTextField2FocusLost
(
java
.
awt
.
event
.
FocusEvent
 evt
)
 
{
//GEN-FIRST:event_jTextField2FocusLost

        
// TODO add your handling code here:

        
if
 
(
jLabel2
.
getForeground
()
 
==
 
Color
.
red
)
 
{

            jLabel2
.
setText
(
“Sales representative ID”
);

            jLabel2
.
setForeground
(
Color
.
black
);

        
}

    
}
//GEN-LAST:event_jTextField2FocusLost

    
private
 
void
 jTextField3FocusLost
(
java
.
awt
.
event
.
FocusEvent
 evt
)
 
{
//GEN-FIRST:event_jTextField3FocusLost

        
// TODO add your handling code here:

        
if
 
(
jLabel3
.
getForeground
()
 
==
 
Color
.
red
)
 
{

            jLabel3
.
setText
(
“Sales representative ID”
);

            jLabel3
.
setForeground
(
Color
.
black
);

        
}

    
}
//GEN-LAST:event_jTextField3FocusLost

    
private
 
void
 jTextField4FocusLost
(
java
.
awt
.
event
.
FocusEvent
 evt
)
 
{
//GEN-FIRST:event_jTextField4FocusLost

        
// TODO add your handling code here:

        
if
 
(
jLabel4
.
getForeground
()
 
==
 
Color
.
red
)
 
{

            jLabel4
.
setText
(
“Office Supplies”
);

            jLabel4
.
setForeground
(
Color
.
black
);

        
}

    
}
//GEN-LAST:event_jTextField4FocusLost

    
private
 
void
 jTextField5FocusLost
(
java
.
awt
.
event
.
FocusEvent
 evt
)
 
{
//GEN-FIRST:event_jTextField5FocusLost

        
// TODO add your handling code here:

        
if
 
(
jLabel5
.
getForeground
()
 
==
 
Color
.
red
)
 
{

            jLabel5
.
setText
(
“Books”
);

            jLabel5
.
setForeground
(
Color
.
black
);

        
}

    
}
//GEN-LAST:event_jTextField5FocusLost

    
private
 
void
 jTextField6FocusLost
(
java
.
awt
.
event
.
FocusEvent
 evt
)
 
{
//GEN-FIRST:event_jTextField6FocusLost

        
// TODO add your handling code here:

        
if
 
(
jLabel6
.
getForeground
()
 
==
 
Color
.
red
)
 
{

            jLabel6
.
setText
(
“Papers”
);

            jLabel6
.
setForeground
(
Color
.
black
);

        
}

    
}
//GEN-LAST:event_jTextField6FocusLost

    
/**

     * 
@param
 args the command line arguments

     */

    
public
 
static
 
void
 main
(
String
 args
[])
 
{

        java
.
awt
.
EventQueue
.
invokeLater
(
new
 
Runnable
()
 
{

            
public
 
void
 run
()
 
{

                
new
 GUI
().
setVisible
(
true
);

            
}

        
});

    
}

    
// Variables declaration – do not modify//GEN-BEGIN:variables

    
private
 javax
.
swing
.
JPanel
 
DataPanel
;

    
private
 javax
.
swing
.
ButtonGroup
 buttonGroup1
;

    
private
 javax
.
swing
.
JTextArea
 dataTextArea
;

    
private
 javax
.
swing
.
JPanel
 districtPanel
;

    
private
 javax
.
swing
.
JPanel
 districtPanel1
;

    
private
 javax
.
swing
.
JRadioButton
 eastRadioButton
;

    
private
 javax
.
swing
.
JCheckBox
 emailCheckBox
;

    
private
 javax
.
swing
.
JButton
 exitButton
;

    
private
 javax
.
swing
.
JPanel
 inputPanel
;

    
private
 javax
.
swing
.
JPanel
 inputPanel1
;

    
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
.
JScrollPane
 jScrollPane1
;

    
private
 javax
.
swing
.
JTextField
 jTextField1
;

    
private
 javax
.
swing
.
JTextField
 jTextField2
;

    
private
 javax
.
swing
.
JTextField
 jTextField3
;

    
private
 javax
.
swing
.
JTextField
 jTextField4
;

    
private
 javax
.
swing
.
JTextField
 jTextField5
;

    
private
 javax
.
swing
.
JTextField
 jTextField6
;

    
private
 javax
.
swing
.
JRadioButton
 northRadioButton
;

    
private
 javax
.
swing
.
ButtonGroup
 operationsButtonGroup
;

    
private
 javax
.
swing
.
JCheckBox
 phoneCheckBox
;

    
private
 javax
.
swing
.
JButton
 runButton
;

    
private
 javax
.
swing
.
JRadioButton
 southRadioButton
;

    
private
 javax
.
swing
.
JCheckBox
 visitCheckBox
;

    
private
 javax
.
swing
.
JRadioButton
 westRadioButton
;

    
// End of variables declaration//GEN-END:variables

}

ProjectGUI/nbproject/project.xml

org.netbeans.modules.java.j2seproject

ProjectGUI

ProjectGUI/nbproject/project.properties
annotation.processing.enabled=true
annotation.processing.enabled.in.editor=false
annotation.processing.processor.options=
annotation.processing.processors.list=
annotation.processing.run.all.processors=true
annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
build.classes.dir=${build.dir}/classes
build.classes.excludes=**/*.java,**/*.form
# This directory is removed when the project is cleaned:
build.dir=build
build.generated.dir=${build.dir}/generated
build.generated.sources.dir=${build.dir}/generated-sources
# Only compile against the classpath explicitly listed here:
build.sysclasspath=ignore
build.test.classes.dir=${build.dir}/test/classes
build.test.results.dir=${build.dir}/test/results
# Uncomment to specify the preferred debugger connection transport:
#debug.transport=dt_socket
debug.classpath=\
${run.classpath}
debug.test.classpath=\
${run.test.classpath}
# This directory is removed when the project is cleaned:
dist.dir=dist
dist.jar=${dist.dir}/ProjectGUI.jar
dist.javadoc.dir=${dist.dir}/javadoc
excludes=
includes=**
jar.compress=false
javac.classpath=
# Space-separated list of extra javac options
javac.compilerargs=
javac.deprecation=false
javac.processorpath=\
${javac.classpath}
javac.source=1.7
javac.target=1.7
javac.test.classpath=\
${javac.classpath}:\
${build.classes.dir}
javac.test.processorpath=\
${javac.test.classpath}
javadoc.additionalparam=
javadoc.author=false
javadoc.encoding=${source.encoding}
javadoc.noindex=false
javadoc.nonavbar=false
javadoc.notree=false
javadoc.private=false
javadoc.splitindex=true
javadoc.use=true
javadoc.version=false
javadoc.windowtitle=
main.class=projectgui.GUI
manifest.file=manifest.mf
meta.inf.dir=${src.dir}/META-INF
mkdist.disabled=false
platform.active=default_platform
run.classpath=\
${javac.classpath}:\
${build.classes.dir}
# Space-separated list of JVM arguments used when running the project
# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value
# or test-sys-prop.name=value to set system properties for unit tests):
run.jvmargs=
run.test.classpath=\
${javac.test.classpath}:\
${build.test.classes.dir}
source.encoding=UTF-8
src.dir=src
test.src.dir=test

ProjectGUI/nbproject/genfiles.properties
build.xml.data.CRC32=40e089d7
build.xml.script.CRC32=a07e58c4
build.xml.stylesheet.CRC32=28e38971@1.50.3.46
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
nbproject/build-impl.xml.data.CRC32=40e089d7
nbproject/build-impl.xml.script.CRC32=d173dcc2
nbproject/build-impl.xml.stylesheet.CRC32=fcddb364@1.50.3.46

ProjectGUI/nbproject/build-impl.xml

Must set src.dir
Must set test.src.dir
Must set build.dir
Must set dist.dir
Must set build.classes.dir
Must set dist.javadoc.dir
Must set build.test.classes.dir
Must set build.test.results.dir
Must set build.classes.excludes
Must set dist.jar

Must set javac.includes

Must set JVM to use for profiling in profiler.info.jvm
Must set profiler agent JVM arguments in profiler.info.jvmargs.agent

Must select some files in the IDE or set javac.includes

To run this application from the command line without Ant, try:

java -cp “${run.classpath.with.dist.jar}” ${main.class}

To run this application from the command line without Ant, try:

java -jar “${dist.jar.resolved}”

Must select one file in the IDE or set run.class

Must select one file in the IDE or set run.class

Must select one file in the IDE or set debug.class

Must select one file in the IDE or set debug.class

Must set fix.includes

Must select one file in the IDE or set profile.class

Must select some files in the IDE or set javac.includes

Some tests failed; see details above.

Must select some files in the IDE or set test.includes

Some tests failed; see details above.

Must select one file in the IDE or set test.class

Must select one file in the IDE or set applet.url

Must select one file in the IDE or set applet.url

ProjectGUI/build.xml

Builds, tests, and runs the project ProjectGUI.

ProjectGUI/manifest.mf
Manifest-Version: 1.0
X-COMMENT: Main-Class will be added automatically by build

Still stressed with your coursework?
Get quality coursework help from an expert!