CSC-112 – HW8 Draw the American Flag In JavaFX

Due: Thursday, March 28, 2019  11:59pm

Chapter 14 Homework

Write a program that draws and displays a US flag. Note this is not displayed from one big image, rather it is drawn using rectangles and an image of a  white star.


  • A good size flag should be 589px wide by 310px high.
  • There’s no point allowing the user to resize the window so make sure you set the the primary stage resizable property to false.
  • Do not show an image of the American flag!

FYI: Dimensions and proportions of the US Flag:

Extra Credit for a total of 15 out of 10 points.

Add scalability to your application.  Adjusting the window size should adjust the flag accordingly.  If you do this, set the resizable property to true.  Use property binding based on the window’s width and height to the components of the pane.  Property Binding would need to be set on all the nodes in your pane.  As perhaps a better technique would be to use the code shown for the polygon example in Chapter 14.

Here is an example of Red Stripe Scalability.

Here is an example of Red Stripe Scalability Using No Property Binding

CSC-112 – HW7 Complex Numbers Using RegEx

Due: Monday, March 18, 11:59pm

Make sure you post a GUI and email a gist before the due date. First thing Tuesday, in class, I’m going to discuss my solution to this problem.

We’ll finally put to rest Complex numbers with this HW7. HW7 will involve the actual Regular Expression (RegEx) implementation of the complex number string constructor. In HW6, many students created a GUI that looks like this, more or less:

This GUI supports entering complex numbers as strings. We will use regular expressions to perform the task of converting strings to complex numbers. The GUI will ultimately call the Complex constructor that takes a string input to produce the number.

Here’s some sample code we discussed in class that you can put into your constructor:

String regex = "^[+-]?(\\d+(\\.\\d*)?|\\.\\d+)$";
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(complexNumber);
if (matcher.find()) {
this.real = Double.parseDouble(;
this.imag = 0;

Some observations I made while building a solution:

  • Make sure you put a ^ in front of your regex’s and a $ at the end. This makes sure the entire string is matched and not just contained in the string! Note the sample above.
  • The code above checks for a string that is just a real number. You should have similar code for:
    • a string the is just an imaginary number
    • a string that is [+/-]?i ie. real part 0, imaginary part +/-1
    • a string the contains both a real part and an imaginary part
    • a string that contains a real part and an imaginary part that consists of just an i
  • If after going through all 5 checks for a valid complex number form, you didn’t do a return. Then the string passed in the constructor is gibberish, and so you should throw a RuntimeException.
  • If you plan on building a separate class that inherits from the Complex class, you’ll have to make some small changes to the Complex class:
    • remove the finals from real and imaginary properties.
    • Add simple setters for those properties.
    • the this.real and this.imag assignments in the sample code need to change to call the setters.

Please reference for additional help with HW7:

CSC-112 – Regular Expression Examples

CSC-112 – HW6 Complex Numbers Using RegEx GUI

Due: Saturday March 2, 11:59pm

We just can’t let go of Complex Numbers!

Construct a GUI that looks something like this:

This GUI is going to support entering complex numbers as strings. Remember the constructor that takes a string in HW3? HW7 will involve the actual Regular Expression (RegEx) implementation of the complex number string constructor. We will be using regular expressions to perform the task of converting strings to complex numbers. Not officially knowing what regular expression are at this point, let’s start by getting a GUI created that will support them. The GUI will ultimately call that constructor.

The textboxes will hold actual complex number strings of the form

a + bi, a, or bi

For now, when you click on the equals button, have textbox C display “Not Yet Implemented“.

Be sure to put your name on the GUI at that bottom and POST it to your site.

This is not an extra credit homework. You will build this using JavaFX! No JOptionPanes or any other old technology.

Extra Credit can be obtained if you embellish the app in some way. i.e.

  • use tooltips
  • use placeholder text
  • if you click the equals, a popup box shows that does something cool
  • Add a button that clears the GUI.
  • Whatever you think would be cool.

CSC-112 – Assumed Requirements for Homework Submissions

Even though homework assignments don’t explicitly mention basic requirements, please assume the following:

When submitting a GUI, the only GUI code that is acceptable is JavaFX. Please don’t waste your time with old junk technology. JOptionPane programs are just not good both from a technology stand point and from a user interface prospective.

I give you many examples of JavaFX interfaces. Some are located here Rational Numbers and here HW4 GUI Solution.

Power through the code to get something that will produce a functioning GUI. This is what you will be doing as developers.

When submitting a homework assignment, it is assumed that it is to be written in Java. Amazing that this needs to be stated, but apparently it needs to be.

Do not post code on your websites! Post only the GUI. Send me your project source code through a gist URL.

CSC-112 How to fix JavaFX Compiler errors

The errors I encountered in class that dealt with JavaFX, I have not seen before. They don’t occur on my office or home computers. The only difference I can think of between the lab computers and my home or office machine is the lab is running the older Windows 7.

To get rid of them, should they present themselves, is to first follow this procedure:

  1. Right click on the Project and select Properties.
  2. Click on Java Build Path
  3. Click on the Libraries Tab
  4. You should see an entry that looks like “JRE System Library”.  Double click on that.
  5. Choose “Workspace Default JRE” then click Finish
  6. Click Apply, then OK

If they still show, make the following modifications to the project properties:

Download and Use JDK 10.0.2!!!

Don’t use the latest Java 11. For whatever reason, Oracle decided to not bundle JavaFX with it.

If you really what to use Java 11, you’ll need to download and install JavaFX separately. I’ll leave you to google the instructions on how to do that.

Use JDK 10.0.2. It has JavaFX built in and is what is installed in our labs.

If you already installed Java 11, uninstall it entirely.  

Download JDK 10.0.2. Since Oracle is pushing the latest and greatest Java 11, you’ll need to jump through some hoops to get it. Here’s how:

  • Go to the JDK download page.
  • At the bottom of the page, there’s a Java Archive.  Click that.
  • Select Java SE 10
  • You may need to create an account to download it. Go ahead; it’s safe.

You’ll have a much better JavaFX experience!

Good Luck

CSC-112 – Linux Accounts and Orientation

This assignment will be considered HW1 and is due Monday, Jan 28 11:59pm.

Welcome CSC-112 Students!

Start the Linux Orientation Assignment.  You are going to need to create and maintain a small website to deliver your GUI apps to the world.  Use your winter session downtime to get this done and free up your time during the regular semester.

Email me to request an account on this cs machine.  I’ll respond with your username and an initial password so can proceed with this exercise.

Students who complete this Linux configuration assignment during the break will receive an extra 10 points.  That’s right, a big 20 out of 10 for demonstrating their enthusiasm for learning.

(There may be an issue or two as the cs server is running on a different environment than in previous semesters.  Just email me if you encounter an error and I’ll fix the problem ASAP.)

The assignment describes utilities for Windows users.  For Apple users, check out these utilities: Graphical SFTP Utilities for Apple and  What is the equivalent of PuTTY for Mac OS-X

An Extra Activity

Having to continually enter a username/password gets tiring.  To configure Putty to autologin using public/private keys follow this tutorial: .  If everything goes well, you will not have to enter a password.  Do this on computers you own as the private key is a file on your computer.  You can’t permanently save files on STCC computers.

Links and Resources for Java Courses

Liang 11th Edition Resources

Common Resources

Sign up for a GitHub Account

If you going to be a programmer, then github is a site you’ll need to use.

Go here: and create an account for yourself.  We will be using github for homework submissions.

In particular the part of github we’ll  be using is the gist function located here:

You can submit multi-file projects under just one URL! You also have a record of all your work in one convenient location.