HW7 – Drawing Using Arrow Keys

Due: Friday April 10. 11:59pm

There is some background reading in revel available on Key and Mouse Event Handling. Please do those quick answer assignments to prepare for the following project.

Basic Problem (10 out of 10):

In the revel system, you will find problem 15.9 (Draw lines using the arrow keys) Write a program that displays line segments using the arrow keys, The line starts from (100, 100) in the pane and draws toward east, north, west, or south when the right-arrow key, up-arrow key, left-arrow key, or down-arrow key is pressed. Each keystroke will move the line 10 pixels. An example is shown below:

Take a look at these videos to aid in this assignment: Key Event Processing

Extra Credit (15 out of 10):

This drawing problem has a lot to be desired. Add three buttons, “Clear:, “Pen Up”, and “Pen Down”. The “Clear” button will erase the drawing. The “Pen Down” will actually perform the function of drawing the line segments. The “Pen Up” will not draw anything on the panel but will allow you to move the cursor to some other location on the panel. I envision the cursor being a small circle that is hollow when Pen Up is activated, and filled when “Pen Down” is active.

The pane’s getChildren() returns an ObservableList<Node> object that allows adding components to the pane. You might want to investigate the remove method to remove just the last Node or Shape from the panel. The last Node is the cursor circle that needs to be removed, modified and then added to the pane to display it. The Line Segments won’t be touched.

Extra Credit (20 out of 10):

Add mouse support to the app. A drawing program really should have mouse support. I’ll leave it you to read the mouse handling code you need.

HW6 Traffic Lights

Due: Monday April 6. 11:59pm

Write a JavaFX application that simulates a traffic light. The program allows the user to select one of three lights: red, yellow, or green. When the Red button is pressed, the red light is turned on; when the yellow button is clicked, then the yellow light turns on, etc. Only one light can be on at a time.

The red light is on when the program starts.

Place the 3 buttons centered at the bottom of the application. Again use normal buttons and nothing else.

Here’s what the traffic light should look like:

Refer to the code given in Updatable Polygon Event Processing as a guide.

Like always send me a gist of optimized, formatted code.

Updatable Polygon Event Processing

Consider this problem:

Add to the GUI textboxes that display the number of sides displayed, the pixel area of the displayed polygon, the area of the circle that surrounds and touches the vertices of the polygon, and the difference between the polygon area and the circle area.

The code for this problem is given here:

https://gist.github.com/bytecodeman/c015be72d6b400c3a8f9b7c11acfc5c0

Use this code as a model for the Traffic Light HW6 for chapter 15.

Random Thoughts and Announcements

If you are sick of the ads displayed on the website, install an ad blocker in your Chrome or Firefox browser. You should have one installed already. Never use IE.

I’m not going to send out many more emails. You know you need to check the website for updates.

A question was asked about the short answer problems and their point values. I do get an indication of the work you do in answering the simple questions. Keep doing those quick answer problems.

The programming problems form most of your grade and are graded the same as before this catastrophe.

As far as the 1’s and 0’s assignment is concerned, there are two ways to approach the problem. 1) use TextField controls and fill them with the text of a 1 or a 0. or 2) Use a Text Node inside a StackPane to center it. You will probably have issues with sizing; don’t worry too much about that. Looking at my solution will clear things up. In the meantime, use the .setPrefSize() method to set a Node’s size.

Look at my Chinese Flag solution for guidance as to the proper way to structure your code.

 

Assignments are now pushed up. Coding Assignment Available

Now that I got a better idea of how revel works, I needed to push up the due dates of the assignments in Chapter 14.

The last assignment due on April 1 is an actual program! It is Problem 14.7 (Display random 0 or 1) Use the same technique to submit homework. Send me a gist of code that has multiple classes and/or methods.

Please use this invite link: https://console.pearson.com/enrollment/r3ep8a and register for the new online course.

You will need an access code for registration. Email me at silvestri@stcc.edu and I will send you your personal access code.

Read through the material, watch the videos found in the text, answer the questions you see placed throughout the text. That is the format of the new course.

Register for the NEW Online Java 2 Course!

Pearson Publishing stepped up and made their online offering of the Liang Java textbook available to our class.

Please use this invite link: https://console.pearson.com/enrollment/r3ep8a and register for the new online course.

You will need an access code for registration. Email me at silvestri@stcc.edu and I will send you your personal access code.

You will find one homework assignment there. Read through the material, watch the videos found in the text, answer the questions you see placed throughout the text. That is the format of the new course.

The first homework assignment is due Friday, March 27. I’ll be working on posting more homework soon. Since these are short quick answer homework sets and not projects, due dates may be every other day.

Good Luck!

Future of CSC-112

Hopefully my issues have been resolved. But I come back to a world that is totally changed. A world that is not conducive to my classic teaching style of lecture/testing.

This new world might not even allow us to meet in a classroom again!

So I’m in the process of working with the textbook publishers to get CSC-112 students access to the online version of the material. The online version isn’t as project based as what I’ve used in my classes. It’s more a series of short answer homework problem sets that offer some small interactive programming assignments. There may not even be tests! Not sure till I dive into the software.

Many people will probably like the new format; some will not. However, COVID-19 is going to force us all to change the way we learn material.

I will let you know about the codes and how to access this new homework approach.

Try to enjoy the Spring Break.

HW4 Draw the Chinese Flag In JavaFX (With Solution)

Due: Friday, March 13, 2019  11:59pm

SOLUTION

Chapter 14 Homework

Write a program that draws and displays a Chinese flag. Note this is not displayed from one big image, rather it is drawn using shapes and an image of a  Chinese Star.

Specifications:

  • A good size flag should be 600px wide by 400px 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 just show an image of the Chinese flag!
  • 10 out 0f 10, if you manually layout stars.
  • 12 out of 10, if you use a loop to layout the 4 small stars.
  • Maximum points given if you use multiple classes and/or methods.  Do not put all code in the start method.

FYI: Dimensions and proportions of the US Flag: https://en.wikipedia.org/wiki/Flag_of_China

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

Oh, for 20 out of 10 points . . .

If you do the resizable flag, what will happen is the flag distorts when you resize the stage!  We can’t have that.

Investigate what needs to be done to keep the flag always proportional as you resize the stage.

Regular Expression Examples

Java Supplemental Instruction (SI)

The college has a new program called Supplemental Instruction (SI). Through this program, you will have the opportunity to meet weekly with our SI Leader, who will provide weekly review sessions for all interested students. The Leader is a current student who has recently taken the course and done well. They will be in class with you every day, hearing what you hear, and reading what you read. During each review session, you will have a chance to get together with your classmates to compare notes, discuss concepts that might be confusing, review material for tests and quizzes, and ask any questions that you might have.

Sessions will begin the week of January 27th, and run through the end of the semester. You can attend as many review sessions as you like; each one will be different because you will have new material to discuss. SI sessions are informal – bring any notes you have, your textbook, or a classmate! By coming to these sessions, you will be able to develop a better understanding of the course content as well as more effective ways of learning.

If you are unable to attend the group session, but would like to meet with the SI Leader, you can set up an individual time to meet with them. You can let them know you would like to make an appointment with them when you see them in class, or feel free to send them a note through their college email.

I am thrilled that we have this new opportunity for you, and I am hopeful that you take advantage of this program.

Our SI leader is Abdul Muhaymen Khalil and his email address is adkhalil0001@student.stcc.edu .

How To Get JavaFX Working On JDK 11

JDK Release 11 is the long term standardized production release of Java. Java 12, 13 are feature releases that are built on Java 11 and released so developers can experiment with the new features in their code. These new features will eventually make it into an official production release in the future.

Consider JDK 13 an enhanced JDK 11 and use the techniques described in the video to get JavaFX working in a JDK 13 environment.

JDK 13 with JavaFX 11 USB Portable Environment

  • Download this 473MB zip file
  • Unzip the contents onto a freshly formatted USB drive.
  • Make sure the root of the USB has these 3 directories: eclipse, Java, workspace, and 1 file called js.cmd.
  • When you want to start coding in this environment, click the js.cmd file. It will launch eclipse.
  • Projects get stored in the workspace directory.
  • Be sure to exit eclipse and wait for the shell window to close. Then eject the USB drive, or you will lose your work!

JavaFX11 is installed on this image. It’s use in a project will be discussed in the CSC-112 Intermediate Java course.

Download and Use JDK 10.0.2!!!

Probably best not to use the latest Java 13. 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!


If you encounter errors in your JavaFX GUI that indicate classes are not being found, do this to fix the problem (only works with JDK 10.0.2):

  1. Right click on the project and choose Properties
  2. Click Java Build Path, then double click JRE System Library. An Edit Library popup box should appear.
  3. Choose Workspace default JRE, then click Finish
  4. Click Apply, then OK and you should be good to go.

JDK 10 USB Portable Environment

  • Download this 612MB zip file
  • Unzip the contents onto a freshly formatted USB drive.
  • Make sure the root of the USB has these 3 directories: eclipse, Java, workspace, and 1 file called js.cmd.
  • When you want to start coding in this environment, click the js.cmd file. It will launch eclipse.
  • Projects get stored in the workspace directory.
  • Be sure to exit eclipse and wait for the shell window to close. Then eject the USB drive, or you will lose your work!

Why JDK 10? It’s the last version of the JDK that has JavaFX built in. JavaFX is a technology that allows building GUI code. We will use that technology in the CSC-112 Intermediate Java course.

That’s not to say the newer JDKs can’t compile JavaFX. It’s that JavaFX is a separate download and is a chore to incorporate in the JDK.

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: https://github.com/ 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:

https://gist.github.com/

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

Use the TEMPLATE!!!

A few things apparently need to be explicitly stated as far as homework is concerned.

In case things are not mentioned in the homework, the following criteria ALWAYS apply:

  • Code must use the template.
  • Code needs to be written using the JDK 8 or better.
  • Code needs to contain the global header information mentioned in the syllabus.  All source code files must have the global header.
  • Code must be formatted properly using Eclipse’s formatting capabilities.
  • Code must use methods and classes to separate the logic.
  • Always email me gists of your source code.

Links and Resources for Java Courses

Liang 11th Edition Resources

Common Resources