In the lab--or at home--here is a roadmap for starting HW1. Understand: we are mostly trying, right now, to learn Eclipse.
We'll pick up some ideas about Java, too, but that's a secondary focus
for today.
Get HW1Snippets from below. Leave this open, or copy to a
Notepad file.
Whenever you are ready to leave the
lab, close Eclipse and send yourself and your partner email with your
Java file attached. Or copy to a USB memory thing, or burn a CD. But email is
simplest.
- Start Eclipse. Name a workspace; for us, it can't be the
default. In the lab, it has to be a file in
C:\temp.
The name doesn't much matter, except make it meaningful--to you.
- Create a
New/Project. Name it
Homework1
- Right click on that and create a new package. Name it
hw1
- Right click on that and
Import/File system and navigate
to wherever you can get
HW1StarterV3.java.
That will be a folder name, not a file name. Click OK.
- You will be given a list of all the files in that
folder. Select
HW1StarterV3.java and click
Finish.
- The file will show up in your Package Explorer View.
Double click to open it. (Ignore warning messages.)
- Select
HW1StarterV3
in the class definition. Right click Refactor/Rename
and rename to
HW1.
Click Finish. This
also updates all references to that name--including the file name. Note the
change in the Package Explorer View. Ignore a warning about a main method.
- Save and
Run/Run as/Java Application – to make sure you
are starting with something that works. That is, test some good and bad data.
Can be very quick.
- Change date and name(s).
- Find
private
void initialize() {
this.setSize(350, 150);
change the
150 to
250.
- Copy Snippet 1 to the end of the private String declarations at
the beginning of the program. Fix indentation if necessary. Save and run.
(That's right after the declaration
private String
lastNameAsEntered = new String();.)
- Find the line
private
private JTextField lastNameEntry = null; and insert Snippet 2.
- Find
private
javax.swing.JPanel getJContentPane() { and at the end of the list
of
jContentPane.add lines add Snippet 3. Fix indentation if necessary.
Save and run. Ah, but there are errors! OK, so you can’t run it yet.
- At the end of the program, just before the closing
},
copy in Snippet 4. Save and try to run. That eliminated one error. (Be
prepared to explain what the error meant and why this fixed it.)
- So that you can test the insert of the last snippet,
"comment out" the last line of Snippet 3 that you added earlier; that's
jContentPane.add(getZIPAsEntered(), null);. Pressing
Control + / anywhere in a line toggles between making it a comment
and not. (Remember to uncomment it later, after you have fixed the textfield
for the ZIP code.)
- Find the line
private
javax.swing.JTextField getLastNameEntry() {
- Copy that entire method
to the end of the program, just before the closing
}.
Save. Lots of errors! Can you explain them?
- In the code you just copied select (double click)
getLastNameEntry
- Change that to
getZIPEntry
- In the next line, select
lastNameEntry
- Change that to
ZIPEntry
- Change the other five instance to
lastNameEntry to
ZIPEntry (Don't forget the last one, in the
return
statement.)
- Change the three instances of
lastNameAsEntered to
ZIPAsEntered
- Change the error message
- Save and run.
- Celebrate or scream, as appropriate.
This is probably at least enough for an hour in the lab. We
don't try to win it all in one day.
When you are ready to stop for the day, close Eclipse. If
running on a lab machine, copy your workspace to a floppy or CD. I’ll show you
how to burn a CD if that isn’t obvious.
If you can run this, you are ready to start programming the
error checking of the ZIP code, and, if that’s OK, printing the output. Note
that you are not required to check that it is numeric. We'll do that in HW2.
Snippet 1
private String ZIPAsEntered = new String();
Snippet 2
private javax.swing.JLabel ZIPLabel = null;
private javax.swing.JTextField ZIPEntry = null;
Snippet 3
jContentPane.add(getZIPLabel(), null);
jContentPane.add(getZIPEntry(), null);
Snippet 4
private javax.swing.JLabel getZIPLabel() {
if(ZIPLabel == null) {
ZIPLabel = new javax.swing.JLabel();
ZIPLabel.setText("ZIP code *");
ZIPLabel.setPreferredSize(new java.awt.Dimension(100,20));
}
return ZIPLabel;
}
Back to the top of the 221
page
Back to Dan McCracken's Home Page