New User Special Price Expires in

Let's log you in.

Sign in with Facebook


Don't have a StudySoup account? Create one here!


Create a StudySoup account

Be part of our community, it's free to join!

Sign up with Facebook


Create your account
By creating an account you agree to StudySoup's terms and conditions and privacy policy

Already have a StudySoup account? Login here

CSC 122 Lecture 4 and 5

by: AnnMarie

CSC 122 Lecture 4 and 5 CSC 122


GPA 3.028

Preview These Notes for FREE

Get a free preview of these Notes, just enter your email below.

Unlock Preview
Unlock Preview

Preview these materials now for free

Why put in your email? Get access to more of this material and other relevant free materials for your school

View Preview

About this Document

These notes cover the information discussed during March 30 and April 1
Intermed Computer Programming
Class Notes
25 ?




Popular in Intermed Computer Programming

Popular in ComputerScienence

This 6 page Class Notes was uploaded by AnnMarie on Friday April 1, 2016. The Class Notes belongs to CSC 122 at Louisiana Tech University taught by MULMI, SANGAM in Spring 2016. Since its upload, it has received 98 views. For similar materials see Intermed Computer Programming in ComputerScienence at Louisiana Tech University.

Similar to CSC 122 at LA Tech

Popular in ComputerScienence


Reviews for CSC 122 Lecture 4 and 5


Report this Material


What is Karma?


Karma is the currency of StudySoup.

You can buy or earn more Karma at anytime and redeem it for class notes, study guides, flashcards, and more!

Date Created: 04/01/16
March 30: CSC 122 Lecture 4 Program Assignment: The following will be the data for 20 students: major, name, age, credits;major, name, age, credits;major, name, age, credits;major, name, age, credits;major, name, age, credits;major, name, age, credits;major, name, age, credits;major, name, age, credits;major, name, age, credits;major, name, age, credits;major, name, age, credits;major, name, age, credits;major, name, age, credits;major, name, age, credits;major, name, age, credits;major, name, age, credits;major, name, age, credits;major, name, age, credits;major, name, age, credits;major, name, age, credits; You will want to store the student into an object and then store it into anArrayList. Then you will use an iterator to print the list of students in theArrayList. Do interfaces create a new type? Yes. Can interfaces have methods? Yes, they can have methods but the method must be public. What is refactoring? Refactoring is taking existing code and cleaning it up to make it cohesive and faster. How would you pass multiple parameter values to a method that only has one parameter declared in the method header? If you have the following method: public int getDays(int m){ } you will need to pass an array to the parameter if you want to have more than one parameter value passed to the method. You can also use variable arguments (…) at the end on int. When invoke the method with multiple values, m will be like an array which its values can be accessed just like an array. The following shows how to invoke the method and how to access the values in m. getDays(1,2,3,4,5,6,7,8,9,10); System.out.println(m[0]); What does args mean in the public main method? Args is arguments which you can pass with the command line when you compile and run the java program with the command line. What is Enumerated types? Enums represent constant value. Before we used Final and uppercase naming to declare constant values. Enums are type safe – keeps the types safe from being incompatible. Always use enums when you are using type constants. You can create an enum by the following: enum Days{ SUN,MON, TUE, WED, THUR, FRI, SAT; } enum is the Java keyword to declare a type safe constant. SUN through SAT are constants. By using enums you can save namespacing, organize your constants better, and prevent type missuse. To assign a value to the constants in enums you do the following: enum Days{ SUN(1), MON(2), TUE(3), WED(4), THUR(5), FRI(6), SAT(6) } Enums can implement interfaces. Private int days; private Days(int days){ this.days=days; } public int getDays(){ return days; } System.out.println(Days.SUN.getDdays()); With enums you can use switch case where you could not use it on objects. Enums inherit from Enum instead of OBJECT. Enums do support polymophism but you can not implement it. What do you have to do create a value argument? ... April 1: CSC 122 Lecture 5 What is GUI? GUI is short for Graphical User Interface, in Java, it allows the user to interact with the program with button, pictures, etc. instead of interacting with a program by invoking commands. What are the elements in GUI? You have a window, title, menue bar, exit button, scroll bar, buttons, etc within a frame. You have a panel, layout, components, and event handlers. With GUI, you need to keep it simple and easy to use. What is a panel? Apanel is a subframe. The idea of panel is to group similar (like) components together to organize the fame. You will have to create label, button, TextArea(multiple line), TextField (single line), ScrollBar, and MenuBar, else they will not appear within the GUI. Are there different types of layouts? There are many layouts that can be implemented within Java. The following are some that are discussed in class. Flowlayout – components will appear left to right in a row until the row is full and then it will go to the next line. Gridlayout – the layout is in a grid layout which components are added by grid. Borderlayout – is like a map with North, East, South, West, and Center. You can have multiple layouts within the same frame. How do you create a GUI in Java? In Java, you will use two classes –AWT and Swing – to create GUI. These are already installed on your computer.AWT contains many classes that can be used to create user interfaces and for painting graphics and images. See JavaAWTAPI. When using AWT, you may encounter issues with other operating systems and thus you would want to use Swing. When you want to create a GUI, you will want to have a solid idea of what layout, components, etc that you want to create. In class, we designed the layout to look like the illustration to the right. The following source code shows how to create simple GUI application that allows the user to increase the text field by 1 each time the button is clicked on. Illustration 1: GUI Design import java.awt.*; import java.awt.event.*; public class SimpleClicker extends Frame implements ActionListener{ public SimpleClicker(){ setTitle("Simple Clicker!"); setSize(600,600); setLayout(new GridLayout(2,1)); final TextField num = new TextField("0"); add(num); Button clicker = new Button("Click Me!!"); add(clicker); clicker.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ String initText = num.getText(); int incrementedValue = Integer.parseInt(initText) + 1; num.setText(incrementedValue + ""); } }); setVisible(true); } @Override public void actionPerformed(ActionEvent e){ } public static void main(String[] args){ new SimpleClicker(); } } The class header states that the SimpleClicker class extends Frame which means that the SimpleClicker class inherits the methods and variables of the Frame class. The class also implements the abstract class of ActionListener which allows an action to be performed when the button is clicked on. The first thing that we did was import the java.awt.* class to be able to use the Frame class, Button class, and the TextField class. Timport java.awt.event.* allows use to use theActionListener class. The first thing we see after importing and the class header is the class constructor which has some new method calls that we have not seen before. The setTitle allows you to put a title at the top of your frame. The setSize allows you set the size of the frame in pixels. The setLayout allows you to set the layout of the frame. The TextField num creates a text field which you need to call add afterward to have it added to the frame. Button clicker allows you to create a button, which you need to pass a string as a parameter. The next thing we have is the action listener which adds one to the current number in the textfield each time the button is clicked. .addActionListener(new ActionListener(){}) is the method call that creates a the action listener. However,public void actionPerformed(ActionEvent e) tells the action listener what to do when the the button is clicked on. The Integer.parseInt allows a string that has integers to be converted into integers. The last thing within class body is the setVisible(true) which displays the GUI. The actionPerformed method is overriden because we are implementing it and when we implement interfaces we have to override methods. The main method is used to create the SimpleClicker by invoking its class.


Buy Material

Are you sure you want to buy this material for

25 Karma

Buy Material

BOOM! Enjoy Your Free Notes!

We've added these Notes to your profile, click here to view them now.


You're already Subscribed!

Looks like you've already subscribed to StudySoup, you won't need to purchase another subscription to get this material. To access this material simply click 'View Full Document'

Why people love StudySoup

Steve Martinelli UC Los Angeles

"There's no way I would have passed my Organic Chemistry class this semester without the notes and study guides I got from StudySoup."

Allison Fischer University of Alabama

"I signed up to be an Elite Notetaker with 2 of my sorority sisters this semester. We just posted our notes weekly and were each making over $600 per month. I LOVE StudySoup!"

Bentley McCaw University of Florida

"I was shooting for a perfect 4.0 GPA this semester. Having StudySoup as a study aid was critical to helping me achieve my goal...and I nailed it!"

Parker Thompson 500 Startups

"It's a great way for students to improve their educational experience and it seemed like a product that everybody wants, so all the people participating are winning."

Become an Elite Notetaker and start selling your notes online!

Refund Policy


All subscriptions to StudySoup are paid in full at the time of subscribing. To change your credit card information or to cancel your subscription, go to "Edit Settings". All credit card information will be available there. If you should decide to cancel your subscription, it will continue to be valid until the next payment period, as all payments for the current period were made in advance. For special circumstances, please email


StudySoup has more than 1 million course-specific study resources to help students study smarter. If you’re having trouble finding what you’re looking for, our customer support team can help you find what you need! Feel free to contact them here:

Recurring Subscriptions: If you have canceled your recurring subscription on the day of renewal and have not downloaded any documents, you may request a refund by submitting an email to

Satisfaction Guarantee: If you’re not satisfied with your subscription, you can contact us for further help. Contact must be made within 3 business days of your subscription purchase and your refund request will be subject for review.

Please Note: Refunds can never be provided more than 30 days after the initial purchase date regardless of your activity on the site.