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.
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.
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 ProjectGUI/src/projectgui/GUI.form ProjectGUI/src/projectgui/GUI.java * GUI.java * */ package import import /** * * */ public * Creates new form SingleNeutronRun */ 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. */ @ operationsButtonGroup buttonGroup1 districtPanel northRadioButton eastRadioButton southRadioButton westRadioButton inputPanel jTextField2 jTextField3 jTextField1 jLabel1 jLabel2 jLabel3 inputPanel1 jTextField4 jTextField5 jTextField6 jLabel5 jLabel6 jLabel4 runButton exitButton jScrollPane1 dataTextArea districtPanel1 phoneCheckBox emailCheckBox visitCheckBox setDefaultCloseOperation setTitle districtPanel buttonGroup1 northRadioButton northRadioButton buttonGroup1 eastRadioButton buttonGroup1 southRadioButton buttonGroup1 westRadioButton javax districtPanel districtPanelLayout districtPanelLayout districtPanelLayout districtPanelLayout northRadioButton inputPanel jTextField2 jTextField2FocusLost jTextField3 jTextField3FocusLost jTextField1 jTextField1FocusLost jLabel1 jLabel2 jLabel3 inputPanel1 jTextField4 jTextField4FocusLost jTextField5 jTextField5FocusLost jTextField6 jTextField6FocusLost jLabel5 jLabel6 jLabel4 javax inputPanel1 inputPanel1Layout inputPanel1Layout inputPanel1Layout inputPanel1Layout javax inputPanel inputPanelLayout inputPanelLayout inputPanelLayout inputPanelLayout runButton runButton runButtonActionPerformed exitButton exitButton exitButtonActionPerformed dataTextArea dataTextArea jScrollPane1 javax districtPanel1 phoneCheckBox emailCheckBox visitCheckBox javax districtPanel1 districtPanel1Layout districtPanel1Layout districtPanel1Layout districtPanel1Layout javax getContentPane layout layout layout layout pack jLabel1 jLabel1 jLabel2 jLabel2 jLabel3 jLabel3 jLabel4 jLabel4 jLabel5 jLabel5 jLabel6 jLabel6 district district district district meansOfContact meansOfContact meansOfContact dataTextArea jLabel1 jLabel1 jLabel2 jLabel2 jLabel3 jLabel3 jLabel4 jLabel4 jLabel5 jLabel5 jLabel6 jLabel6 * */ java } ProjectGUI/nbproject/project.xml org.netbeans.modules.java.j2seproject ProjectGUI ProjectGUI/nbproject/project.properties ProjectGUI/nbproject/genfiles.properties ProjectGUI/nbproject/build-impl.xml Must set src.dir Must set javac.includes Must set JVM to use for profiling in profiler.info.jvm 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
compile.on.save=true
user.properties.file=/home/an/.netbeans/7.1.1/build.properties
ProjectGUI/src/projectgui/GUI.java
/*
projectgui
;
java
.
awt
.
Color
;
javax
.
swing
.
JOptionPane
;
@author
Asma Niaz
class
GUI
extends
javax
.
swing
.
JFrame
{
/**
public
GUI
()
{
();
}
/**
SuppressWarnings
(
“unchecked”
)
//
private
void
initComponents
()
{
=
new
javax
.
swing
.
ButtonGroup
();
=
new
javax
.
swing
.
ButtonGroup
();
=
new
javax
.
swing
.
JPanel
();
=
new
javax
.
swing
.
JRadioButton
();
=
new
javax
.
swing
.
JRadioButton
();
=
new
javax
.
swing
.
JRadioButton
();
=
new
javax
.
swing
.
JRadioButton
();
=
new
javax
.
swing
.
JPanel
();
=
new
javax
.
swing
.
JTextField
();
=
new
javax
.
swing
.
JTextField
();
=
new
javax
.
swing
.
JTextField
();
=
new
javax
.
swing
.
JLabel
();
=
new
javax
.
swing
.
JLabel
();
=
new
javax
.
swing
.
JLabel
();
=
new
javax
.
swing
.
JPanel
();
=
new
javax
.
swing
.
JTextField
();
=
new
javax
.
swing
.
JTextField
();
=
new
javax
.
swing
.
JTextField
();
=
new
javax
.
swing
.
JLabel
();
=
new
javax
.
swing
.
JLabel
();
=
new
javax
.
swing
.
JLabel
();
=
new
javax
.
swing
.
JButton
();
=
new
javax
.
swing
.
JButton
();
DataPanel
=
new
javax
.
swing
.
JPanel
();
=
new
javax
.
swing
.
JScrollPane
();
=
new
javax
.
swing
.
JTextArea
();
=
new
javax
.
swing
.
JPanel
();
=
new
javax
.
swing
.
JCheckBox
();
=
new
javax
.
swing
.
JCheckBox
();
=
new
javax
.
swing
.
JCheckBox
();
(
javax
.
swing
.
WindowConstants
.
EXIT_ON_CLOSE
);
(
“Single Neuron Perceptron”
);
.
setBorder
(
javax
.
swing
.
BorderFactory
.
createTitledBorder
(
“Select District”
));
.
add
(
northRadioButton
);
.
setSelected
(
true
);
.
setText
(
“North”
);
.
add
(
eastRadioButton
);
.
setText
(
“East”
);
.
add
(
southRadioButton
);
.
setText
(
“South”
);
.
add
(
westRadioButton
);
.
setText
(
“West”
);
.
swing
.
GroupLayout
districtPanelLayout
=
new
javax
.
swing
.
GroupLayout
(
districtPanel
);
.
setLayout
(
districtPanelLayout
);
.
setHorizontalGroup
(
.
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
))
);
.
setVerticalGroup
(
.
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
))
);
.
getAccessibleContext
().
setAccessibleName
(
“northRadioButton”
);
.
setBorder
(
javax
.
swing
.
BorderFactory
.
createTitledBorder
(
“Enter Values”
));
.
addFocusListener
(
new
java
.
awt
.
event
.
FocusAdapter
()
{
public
void
focusLost
(
java
.
awt
.
event
.
FocusEvent
evt
)
{
(
evt
);
}
});
.
addFocusListener
(
new
java
.
awt
.
event
.
FocusAdapter
()
{
public
void
focusLost
(
java
.
awt
.
event
.
FocusEvent
evt
)
{
(
evt
);
}
});
.
addFocusListener
(
new
java
.
awt
.
event
.
FocusAdapter
()
{
public
void
focusLost
(
java
.
awt
.
event
.
FocusEvent
evt
)
{
(
evt
);
}
});
.
setText
(
“Sales Rep ID”
);
.
setText
(
“Sales Rep First Name”
);
.
setText
(
“Sales Rep Last Name”
);
.
setBorder
(
javax
.
swing
.
BorderFactory
.
createTitledBorder
(
“Amounts Sold”
));
.
addFocusListener
(
new
java
.
awt
.
event
.
FocusAdapter
()
{
public
void
focusLost
(
java
.
awt
.
event
.
FocusEvent
evt
)
{
(
evt
);
}
});
.
addFocusListener
(
new
java
.
awt
.
event
.
FocusAdapter
()
{
public
void
focusLost
(
java
.
awt
.
event
.
FocusEvent
evt
)
{
(
evt
);
}
});
.
addFocusListener
(
new
java
.
awt
.
event
.
FocusAdapter
()
{
public
void
focusLost
(
java
.
awt
.
event
.
FocusEvent
evt
)
{
(
evt
);
}
});
.
setText
(
“Books”
);
.
setText
(
“Paper”
);
.
setText
(
“Office Supplies”
);
.
swing
.
GroupLayout
inputPanel1Layout
=
new
javax
.
swing
.
GroupLayout
(
inputPanel1
);
.
setLayout
(
inputPanel1Layout
);
.
setHorizontalGroup
(
.
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
())
);
.
setVerticalGroup
(
.
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
)))
);
.
swing
.
GroupLayout
inputPanelLayout
=
new
javax
.
swing
.
GroupLayout
(
inputPanel
);
.
setLayout
(
inputPanelLayout
);
.
setHorizontalGroup
(
.
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
())
);
.
setVerticalGroup
(
.
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
))
);
.
setText
(
“ENTER”
);
.
addActionListener
(
new
java
.
awt
.
event
.
ActionListener
()
{
public
void
actionPerformed
(
java
.
awt
.
event
.
ActionEvent
evt
)
{
(
evt
);
}
});
.
setText
(
“QUIT”
);
.
addActionListener
(
new
java
.
awt
.
event
.
ActionListener
()
{
public
void
actionPerformed
(
java
.
awt
.
event
.
ActionEvent
evt
)
{
(
evt
);
}
});
DataPanel
.
setBorder
(
javax
.
swing
.
BorderFactory
.
createTitledBorder
(
“Sales Representative Data”
));
.
setColumns
(
20
);
.
setRows
(
5
);
.
setViewportView
(
dataTextArea
);
.
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
))
);
.
setBorder
(
javax
.
swing
.
BorderFactory
.
createTitledBorder
(
“Select Contact Means”
));
.
setText
(
“Phone”
);
.
setText
(
“Email”
);
.
setText
(
“Visit”
);
.
swing
.
GroupLayout
districtPanel1Layout
=
new
javax
.
swing
.
GroupLayout
(
districtPanel1
);
.
setLayout
(
districtPanel1Layout
);
.
setHorizontalGroup
(
.
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
))
);
.
setVerticalGroup
(
.
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
))
);
.
swing
.
GroupLayout
layout
=
new
javax
.
swing
.
GroupLayout
(
getContentPane
());
().
setLayout
(
layout
);
.
setHorizontalGroup
(
.
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
())
);
.
setVerticalGroup
(
.
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
(
“”
);
();
}
// //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
())
{
.
setText
(
“* Sales representative ”
);
.
setForeground
(
Color
.
red
);
}
if
(
jTextField2
.
getText
().
isEmpty
())
{
.
setText
(
“* Sales representative First Name”
);
.
setForeground
(
Color
.
red
);
}
if
(
jTextField3
.
getText
().
isEmpty
())
{
.
setText
(
“* Sales Rep Last Name”
);
.
setForeground
(
Color
.
red
);
}
if
(
jTextField4
.
getText
().
isEmpty
())
{
.
setText
(
“* Office Supplies”
);
.
setForeground
(
Color
.
red
);
}
if
(
jTextField5
.
getText
().
isEmpty
())
{
.
setText
(
“* Books”
);
.
setForeground
(
Color
.
red
);
}
if
(
jTextField6
.
getText
().
isEmpty
())
{
.
setText
(
“* Papers”
);
.
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
())
{
=
“North”
;
}
else
if
(
southRadioButton
.
isSelected
())
{
=
“South”
;
}
else
if
(
eastRadioButton
.
isSelected
())
{
=
“East”
;
}
else
if
(
westRadioButton
.
isSelected
())
{
=
“West”
;
}
//set all selected means of contact
if
(
phoneCheckBox
.
isSelected
())
{
=
meansOfContact
+
” Phone ”
;
}
if
(
emailCheckBox
.
isSelected
())
{
=
meansOfContact
+
” Email ”
;
}
if
(
visitCheckBox
.
isSelected
())
{
=
meansOfContact
+
” Visit ”
;
}
//echo data
.
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
)
{
.
setText
(
“Sales representative ID”
);
.
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
)
{
.
setText
(
“Sales representative ID”
);
.
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
)
{
.
setText
(
“Sales representative ID”
);
.
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
)
{
.
setText
(
“Office Supplies”
);
.
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
)
{
.
setText
(
“Books”
);
.
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
)
{
.
setText
(
“Papers”
);
.
setForeground
(
Color
.
black
);
}
}
//GEN-LAST:event_jTextField6FocusLost
/**
@param
args the command line arguments
public
static
void
main
(
String
args
[])
{
.
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
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
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
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 profiler agent JVM arguments in profiler.info.jvmargs.agent
Manifest-Version: 1.0
X-COMMENT: Main-Class will be added automatically by build