Feb 24

I Don’t Like To ovalDraw, rectDraw, or Any Other Draw! [CODESAMPLE THAT ALMOST WORKS]


Week 2 of Java was not as easy as last week. When I took Java last time I did not have to do any things with GUI. Yesterday, I had to write a program that drew a circle given a user entered radius. I totally get the logic of getting a number from the user and the math of drawing the circle. The piece of code that I couldn’t get was this:

Container pane = theGui.getContentPane();
CircleGuiProf circleGui = new CircleGuiProf(Color.yellow, radius);
pane.add(circleGui, BorderLayout.CENTER);

While I was sitting there watching it not work, I could feel my blood pressure rising and my face getting red.  I will not forget that again. I have never enjoyed art/drawing/coloring and I have been terrible at it since I was a little kid. I am not excited about that carrying over in to programming. It is definitely something I need to work on.

I enjoying writing code and I didn’t want to end the day on a coding downer (plus it would haunt all night). So when I got home, I started in on the homework. This is the problem:

Part 1: Write a program that picks a random number between 1 and 10, and allows the user to guess.

It should tell them if their guess was correct or not, and exit when they get the right answer.

Part 2: If the user guesses incorrectly tell them if they need to go higher, or lower.

My professor said that we didn’t have to use pop-ups if we didn’t want to but after my fist-fight with graphics in class, I wanted to make sure I got the idea of JOptionPane. It took me some time but this is the code I came up with :

It works well, except for when the OK button is pressed with no data in the input box the program blows up. I assumed that would return a null value and I have dealt with that but it still doesn’t work. All you smart programming people reading this please feel free to tell me what I’m doing wrong in the comments.

I had fun coding this thing and it relieved some of my frustration. Now I am off to fix my OK button issue.


About Frank Domizio

Frank Domizio is the proud husband of his best friend and partner, Hope and the father of two beautiful children. He has been a Philadelphia Police Officer since 1997. He is currently working at the FBI's Philadelphia Regional Computer Forensics Lab as a Forensic Examiner. Prior being detailed to the FBI, Frank was the Social and Digital Media Manager in the PPD's Office of Media Relations and Public Affairs. Frank holds a degree in Computing and Security Technology from Drexel University and is pursuing a Master of Science in Cybersecurity Engineering from Villanova University. He has also had the opportunity to lecture at Drexel, Temple and Saint Joseph's Universities on the topics of social and new media marketing. Follow him at or @FJDomizio. ***********************************DISCLAIMER*********************************** The opinions expressed on FrankDomizio.com do not reflect the opinions of any rational human being on Earth. That list includes my mother, the City of Philadelphia, any current or future Pope, the Philadelphia Police Department, or any former President (excluding Bill Clinton because he probably agrees with me).
This entry was posted in Coding and tagged , , . Bookmark the permalink.

One Response to I Don’t Like To ovalDraw, rectDraw, or Any Other Draw! [CODESAMPLE THAT ALMOST WORKS]

  1. Pingback: Lions and Java and Authorship, OH MY! [NO LIONS] | Social – Tech – Me

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>