Homework 3

For this homework the goal is to make a program with a gui that can take in user input of a string and display that string in the gui.
And, the submission system seems to work, so try to use that instead of emailing your homework.

Here is an example of the gui:

The gui should have:

The main goal of this program is that when something is put in the text field and the "Enter" button on the screen is clicked, that text should show up in the text area. I added the time to it, but you don't have to.

There are examples in the book, and here are some more links to tutorials which can help show how to use and make guis:


Here is an outline of how to make the program:

  1. You are going to have to import libraries that you will be using. Something like:
    import javax.swing.*; - This is for the JFrame, JTextArea, ...
    import java.awt.*; - This is for the ContentPane part.
    import java.awt.event.*; - This is for the ActionListener part.

  2. Create a class. You can give it any name you want.

  3. In this class, and outside of any function, declare variables (and don't initialize) for: So, if you were declaring a JFrame, you might say: JFrame frame;
    This means that every instance of your class will have a variable of type JFrame called frame.

  4. Make the class have a function where you set up the frame. Something like:
    "public void setUpFrame()" would work.

  5. In setUpFrame():

  6. In your class' main function ("public static void main(String[] args){ ... your code ...}"), make a new instance of your class. Something like: MyClass mycls = new MyClass(); if your class' name was "MyClass".

  7. Use this object to call the setUpFrame() function. (Like mycls.setUpFrame();)

  8. To make the button take text from the text field and put it in the text area:


This is only an outline of how to make the program. If you have a different way, feel free to try it. I added the time to each message, but you don't have to. That is just an example of what can be done.

Also, the submission system should be working for this homework (at least I hope so). Here is how that system should work. If it still doesn't work, you can email your homework instead.