cse 115 / 503 introduction to computer science i · cse 115 / 503 introduction to computer science...

16
‘- 1 Dr. Carl Alphonce Dr. Jesse Hartloff CSE 115 / 503 INTRODUCTION TO COMPUTER SCIENCE I

Upload: others

Post on 28-Oct-2019

9 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CSE 115 / 503 INTRODUCTION TO COMPUTER SCIENCE I · CSE 115 / 503 INTRODUCTION TO COMPUTER SCIENCE I ‘-2 Academic Integrity Zero Tolerance Even the first instance can result in

‘-

1

Dr. Carl AlphonceDr. Jesse Hartloff

CSE 115 / 503INTRODUCTION TO COMPUTER SCIENCE I

Page 2: CSE 115 / 503 INTRODUCTION TO COMPUTER SCIENCE I · CSE 115 / 503 INTRODUCTION TO COMPUTER SCIENCE I ‘-2 Academic Integrity Zero Tolerance Even the first instance can result in

‘-

2

Academic IntegrityZero Tolerance

Even the first instance can result in failing the course.

No Source Sharing

Sharing source code is NEVER allowed, nor is

getting it from the internet

You WILL get

caught

There are very effective automated tools to help uncover violations!

Things that are OK

Things that are NOT

Group discussion (aside from exams)

Group collaboration on code

Properly cited references

Public Code

Discussing concepts with classmates

Sharing answers/solutions with classmates

Slide prepared by Alan Hunt

Page 3: CSE 115 / 503 INTRODUCTION TO COMPUTER SCIENCE I · CSE 115 / 503 INTRODUCTION TO COMPUTER SCIENCE I ‘-2 Academic Integrity Zero Tolerance Even the first instance can result in

‘-

3

Academic IntegrityZero Tolerance

Even the first instance can result in failing the course.

No Source Sharing

Sharing source code is NEVER allowed, nor is

getting it from the internet

You WILL get

caught

There are very effective automated tools to help uncover violations!

Things that are OK

Things that are NOT

Group discussion (aside from exams)

Group collaboration on code

Properly cited references

Public Code

Discussing concepts with classmates

Sharing answers/solutions with classmates

Slide prepared by Alan Hunt

We are starting to run checks on existing and new submissions this

week.

Page 4: CSE 115 / 503 INTRODUCTION TO COMPUTER SCIENCE I · CSE 115 / 503 INTRODUCTION TO COMPUTER SCIENCE I ‘-2 Academic Integrity Zero Tolerance Even the first instance can result in

‘-

4

• Lecture (TopHat questions, Friday activity points)

• Recitation (Quiz points, Coding exercise points)

• You must work on the lab machines, not your own (e.g. your laptop)

Physical attendance is required to earn points in:

Page 5: CSE 115 / 503 INTRODUCTION TO COMPUTER SCIENCE I · CSE 115 / 503 INTRODUCTION TO COMPUTER SCIENCE I ‘-2 Academic Integrity Zero Tolerance Even the first instance can result in

‘-

5© Dr. Carl Alphonce

Graphical User Interface(GUI)

Page 6: CSE 115 / 503 INTRODUCTION TO COMPUTER SCIENCE I · CSE 115 / 503 INTRODUCTION TO COMPUTER SCIENCE I ‘-2 Academic Integrity Zero Tolerance Even the first instance can result in

‘-

6

Using the Java graphics classes

In these slides we will explain the basics of how to create graphical programs.

Some advanced issues will be glossed over (e.g. thread safety, graphics library design). They will be covered later in the course, or in later courses.

Page 7: CSE 115 / 503 INTRODUCTION TO COMPUTER SCIENCE I · CSE 115 / 503 INTRODUCTION TO COMPUTER SCIENCE I ‘-2 Academic Integrity Zero Tolerance Even the first instance can result in

‘-

7

Graphical elements

There are two basic types of graphical elements:

Containersable to hold graphicalobjects, such ascontainers and components

Componentsmust be put into containersable to generate events when manipulated

JFrame

JButton

Page 8: CSE 115 / 503 INTRODUCTION TO COMPUTER SCIENCE I · CSE 115 / 503 INTRODUCTION TO COMPUTER SCIENCE I ‘-2 Academic Integrity Zero Tolerance Even the first instance can result in

‘-

8

ContainersTop-level containers

some containers are called “top-level” because they do not need to be placed inside any other containers

JFrame is a top-level container, meaning it can exist independently; a JFrame draws a window, complete with a title bar, scroll-bar, resize controls, etc.

Other containers (not top-level)most containers must be placed inside some other containerjavax.swing.JPanel is an example

Page 9: CSE 115 / 503 INTRODUCTION TO COMPUTER SCIENCE I · CSE 115 / 503 INTRODUCTION TO COMPUTER SCIENCE I ‘-2 Academic Integrity Zero Tolerance Even the first instance can result in

‘-

9

javax.swing.JFrameTop-level containers have multiple panes

image credit: http://docs.oracle.com/javase/tutorial/uiswing/components/toplevel.html

Page 10: CSE 115 / 503 INTRODUCTION TO COMPUTER SCIENCE I · CSE 115 / 503 INTRODUCTION TO COMPUTER SCIENCE I ‘-2 Academic Integrity Zero Tolerance Even the first instance can result in

‘-

10

Example

Creating just a framenew javax.swing.JFrame()

Creating a frame with a titlenew javax.swing.JFrame(“My title”)

Making the frame visiblecall setVisible(true) on the frame

Making application close when window is closed:call setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE) on the frame

Page 11: CSE 115 / 503 INTRODUCTION TO COMPUTER SCIENCE I · CSE 115 / 503 INTRODUCTION TO COMPUTER SCIENCE I ‘-2 Academic Integrity Zero Tolerance Even the first instance can result in

‘-

11

TopHat question• Consider the following code:

• What is the title that will appear on the JFrame?

© Dr. Carl Alphonce

JFrame window = new JFrame("Cool");

Page 12: CSE 115 / 503 INTRODUCTION TO COMPUTER SCIENCE I · CSE 115 / 503 INTRODUCTION TO COMPUTER SCIENCE I ‘-2 Academic Integrity Zero Tolerance Even the first instance can result in

‘-

12

Components• JLabel

Can display text or an image or both.A non-reactive component.

• JButton

Can display text or an image or both.A reactive component.

© Dr. Carl Alphonce

Page 13: CSE 115 / 503 INTRODUCTION TO COMPUTER SCIENCE I · CSE 115 / 503 INTRODUCTION TO COMPUTER SCIENCE I ‘-2 Academic Integrity Zero Tolerance Even the first instance can result in

‘-

13

Adding components to a JFrame

We will add components to the content pane.

With javax.swing.JFrame, two ways:call getContentPane() on frame to get frame’s content pane, then call add(…) on content pane to add a componentcall add(…) directly on the JFrame object

Second approach is just a convenience method, does the same thing the first approach.

Page 14: CSE 115 / 503 INTRODUCTION TO COMPUTER SCIENCE I · CSE 115 / 503 INTRODUCTION TO COMPUTER SCIENCE I ‘-2 Academic Integrity Zero Tolerance Even the first instance can result in

‘-

14

Examples

JFrame window = new JFrame("Cool");JLabel label = new JLabel("Info");window.add(label);

JFrame window = new JFrame("Cool");JLabel label = new JLabel("Info");window.getContentPane().add(label);

Page 15: CSE 115 / 503 INTRODUCTION TO COMPUTER SCIENCE I · CSE 115 / 503 INTRODUCTION TO COMPUTER SCIENCE I ‘-2 Academic Integrity Zero Tolerance Even the first instance can result in

‘-

15

TopHat question• Consider the following code:

• Which of the following are valid ways to add the JLabel label to the JFrame window?

© Dr. Carl Alphonce

JFrame window = new JFrame("Cool");JLabel label = new JLabel("Info");

window.add(label); // ANSWER 17

Both answers 17 and 68 // ANSWER 45

label.add(window); // ANSWER 23

window.getContentPane().add(label); // ANSWER 68

contentPane.getJFrame().add(label); // ANSWER 90

Both answers 17 and 23 // ANSWER 90

Page 16: CSE 115 / 503 INTRODUCTION TO COMPUTER SCIENCE I · CSE 115 / 503 INTRODUCTION TO COMPUTER SCIENCE I ‘-2 Academic Integrity Zero Tolerance Even the first instance can result in

‘-

16

• Monday• memory and object diagrams• variables, references, and objects

• Wednesday• Containers and Components• JFrame, JLabel

Friday activity