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

Week 14 Notes

by: Taylor Kahl

Week 14 Notes CSC 2310

Taylor Kahl
GPA 4.21

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

From chapter 6, GUI: GUI components, layout managers & mouse events.
Princliples of Computer Programming
Kebina Manandhar
Class Notes
25 ?




Popular in Princliples of Computer Programming

Popular in ComputerScienence

This 6 page Class Notes was uploaded by Taylor Kahl on Friday April 22, 2016. The Class Notes belongs to CSC 2310 at Georgia State University taught by Kebina Manandhar in Winter 2016. Since its upload, it has received 8 views. For similar materials see Princliples of Computer Programming in ComputerScienence at Georgia State University.

Similar to CSC 2310 at GSU


Reviews for Week 14 Notes


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/22/16
Continuing chapter 6, GUI Other GUI Components:  Text field – allows user to enter typed input o from the JTextField class o JTextField constructor takes an int parameter for size of the field, based on the # of characters it will fit  Example: field = new JTextField(5); o access the text in the text field field with this method:  field.getText() o text fields call the actionPerformed method from the EventListener class when the user presses the enter key  adding an action listener to field:  field.addActionListener(new FieldListener());  the FieldListener class has to implement ActionListener  the actionPerformed method retrieves the String value of the text in field with field.getText(); o If your String is a number, you can convert the String to an Integer with this method:  Integer.parseInt(StringName);  Check box – a button that can be toggled on or off, which sets or unsets a boolean condition o from the JCheckBox class o the JCheckBox constructor takes a String which labels the check box  Example: JCheckBox box = new JCheckBox(“Checkbox 1”); o multiple check boxes may be used together – they are independent o when a check box changes state, it generates an item event o the ItemListener interface contains 1 method:  itemStateChanged(ItemEvent event) o item listeners listen to the state (checked or unchecked) of check boxes o to find whether a checkbox is selected use this method:  checkboxName.isSelected()  Font class – font objects are defined by name, style (plain, bold or italic) & size o Example setting the font of a label: label.setFont(“Helvetica, Font.PLAIN, 36); where Helvetica is the font name, the font style is plain, and the font size is 36 o styles are represented by integers  text being bold & italic is represented by the integer sum of bold and italic  Radio buttons – used together to create a set of mutually exclusive options (you can only select one) o from the JRadioButton class o unlike check boxes (which are independent), only 1 button may be selected at a time o when another button is pushed, the one that was currently on is toggled off o Creating a new radio button: JRadioButton button1=new JRadioButton(“Option 1”); o to put radio buttons together in the same group, make a button group, then add each button to it:  ButtonGroup group = new ButtonGroup();  group.add(button1);  group.add(button2); o clicking radio buttons produces action events  uses the actionPerformed() method from the ActionListener class o actionPerformed() retrieves the source of the event (which button generated the event)  retrieving the source: Object source=event.getSource();  Sliders – allow user to specify a numeric value within a bounded range o can be horizontal or vertical w/ optional tick marks or labels o from the JSlider class o creating a new JSlider takes 4 parameters:  Example: slider1=new JSlider(JSlider.HORIZONTAL, 0, 250, 10); where horizontal is the orientation, 0 is the minimum slider value, 250 is the maximum & 10 is the initial value o set major tick marks with:  slider1.setMajorTickMarks(int # btw tick marks) o set minor tick marks with  slider1.setMinorTickMarks(int # btw ticks) o to display the tick marks, this method must be called:  slider1.setPaintTicks(true) o to label the tick marks by number, this method must be called:  slider1.setPaintLabels(true); o sliders produce change events, indicating that their value has changed  listeners use the stateChanged() method from the ChangeListener interface  Combo box – allows the user to select one of several options from a drop- down menu o from the JComboBox class o by default, combo boxes are uneditable – the value can only be changed by selecting an option from the dropdown menu  editable combo boxes can be changed by selecting an option from the dropdown menu OR by typing a value in the combo box area o creating a new combo box:  Example: JComboBox combo1=new JComboBox(); o 2 ways to add options to the combo box:  create an array of Strings; pass it to the JComboBox constructor  JComboBox combo1=new JComboBox(ArrayName);  use the addItem method to add items to a combo box that already exists  combo1.addItem(StringName); o combo boxes can contain text or ImgaeIcon objects as options  Timer – manages an activity over time o from the Timer class o has no visual representation on screen o generates an action event at regular intervals o Methods from the Timer class: Timer (int delay, ActionListener listener) Constructor. Creates a timer which generates an action event at regular intervals, specified by the delay (in milliseconds). The event will be handled by the specified action listener void addActionListener(ActionListener Adds action listener to the timer listener) boolean isRunning() returns true if timer is running void setDelay(int delay) sets the timer’s delay void start() starts the timer, causing it to generate action events void stop() stops the timer, causing it to stop generating action events  Tabbed pane – a container that allows users to choose which of several panes is currently visible by clicking on its tab o from the JTabbedPane class o creating a tabbed pane:  Example: JTabbedPane pane=new JTabbedPane(); o Adding a new tab to a tabbed pane:  pane.addTab(“Tab 1”, new JPanel); Layout Managers:  Layout manager – an object that manages every container & determines how the container’s components are arranged visually o determines size & position of every component o manages the size & position when a container is resized or a component is added  Every container has a default layout manager but can be changed o Setting a new layout manager: o containerName.setLayout(new LayoutType());  Flow layout – puts as many components as possible on a row from left to right at their preferred size; moves to the next row as needed o the default layout for JPanels o components are aligned to the center of the container  Border layout – has 5 areas where components can be added: North (top), South (bottom), East (right), West (left), Center o each area may only contain 1 component  unless you add a container such as a JPanel to an area, in which case you can add multiple components to that container o the 4 outer areas are as large as needed to accommodate their components o if no component is added to one of the outer areas, that area does not appear o the center area expands to fill any available space o adding components to a box layout:  add(componentName, BorderLayout.AREA_NAME);  Grid layout – arranges components in a rectangular grid of equally sized cells o one component per cell o creating a new grid layout:  new GridLayout(# of rows, # of columns) o components are added from left to right, top to bottom o size of cells changes to match overall container’s size  Box layout – organizes components in 1 row or in 1 column o setting a box layout:  setLayout (new BoxLayout(this, BoxLayout.Y_AXIS)); //or X-AXIS o creating space between components:  rigid areas – have a fixed area between components which stays constant no matter what the size of the container  add(Box.createRigidArea(new Dimension(xSize, ySize);  vertical glue – where excess space in the container should be organized  add(Box.createVerticalGlue()); //or HorizontalGlue  Containment hierarchies – the way components are grouped into containers, & containers are grouped into other containers o usually 1 primary or top-level container, like a frame or applet  which usually contains other containers, like panels  panels may contain other panels to organize their components o each container can have its own distinct layout manager  design of the containment hierarchy & the layout manager of each container determines the final appearance of a GUI Mouse Events:  Events generated by the user interacting with the mouse  Mouse events – generated by pressing or releasing the mouse button: o mouse pressed – button is pushed down o mouse released – button is released o mouse clicked – button is pushed down & released in the same location o mouse entered – mouse pointer is moved onto a component o mouse exited – mouse pointer is moved off of a component o the listener for mouse events implements the MouseListener interface  which contains void methods for mousePressed, mouseReleased, mousePressed, mouseEntered & mouseExited  when implementing an interface, you have to define all of these methods  but if you’re not using some of them, you can define them as empty methods  Example: public void mouseReleased(MouseEvent event) {}  Mouse motion events – generated by moving the mouse: o mouse moved – the mouse is moved o mouse dragged – mouse is moved while the mouse button is pressed down o the listener for mouse motion events should implement the MouseMotionListener interface, which contains void methods for mouseMoved & mouseDragged  Java coordinate system – origin is in the upper-left corner of a panel o x-coordinates increase to the right o y-coordinates increase downward


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."

Anthony Lee UC Santa Barbara

"I bought an awesome study guide, which helped me get an A in my Math 34B class this quarter!"

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.