ICS3U1 - Object Oriented Programming

studied byStudied by 5 people
0.0(0)
learn
LearnA personalized and smart learning plan
exam
Practice TestTake a test on your terms and definitions
spaced repetition
Spaced RepetitionScientifically backed study method
heart puzzle
Matching GameHow quick can you match all your cards?
flashcards
FlashcardsStudy terms and definitions

1 / 38

encourage image

There's no tags or description

Looks like no one added any tags here yet for you.

39 Terms

1

What is JOptionPane

A class enabling programmers to use dialog boxes to recieve user input

New cards
2

4 Key Components of a JOptionPane

Parent Component: Determines the position of the dialog box (set to null to center it)

Message: The object you want ot apepar in the dialog box

Title: The string you want to appear

Message Type: Icon that you want to be displayed

Syntax:

  • JOptionPane.showInputDialog(null, “Message”, “Title”, Message Type);

<p><strong>Parent Component: </strong>Determines the position of the dialog box (set to null to center it)</p><p><strong>Message: </strong>The object you want ot apepar in the dialog box</p><p><strong>Title: </strong>The string you want to appear</p><p><strong>Message Type: </strong>Icon that you want to be displayed</p><p></p><p><strong>Syntax:</strong></p><ul><li><p>JOptionPane.showInputDialog(null, “Message”, “Title”, Message Type);</p></li></ul>
New cards
3

5 Different types of Messages

  1. Error_Message

  2. Information_Message

  3. Warning_Message

  4. Question_Message

  5. Plain_Message

New cards
4

What is polymorphism?

Fuck you nigger Richard

<p>Fuck you nigger Richard</p>
New cards
5

Difference between scanner and JOptionPane

JOptionPane only takes in STRING values while Scanner can read all datatypes

New cards
6

Difference between showMessageDialog() and showInputDialog()

showMessageDialog() - Does not return or input anything

showInputDialog() - Can read user input

New cards
7

In a showConfirmDialog() what values would be returned based on the button you pressed?

It is very similar to an array, as the first button from the left will be assigned the value 0, the following would be 1 and so on.

<p>It is very similar to an array, as the <strong>first button </strong>from the left will be assigned the value <strong>0, </strong>the following would be <strong>1 </strong>and so on.</p>
New cards
8

How to import custom images in java

Declare and initialize an ImageIcon object

private ImageIcon img;

img = new ImageIcon (“file name“);

New cards
9

How to add buttons to the JOptionPane

Declare an array and fill in the buttons/dialog for each button

String[] buttons = new String[4] {“Yes”, “Yes to all”, “No”, “Cancel”};

JOptionPane.showOptionDialog(null, “Question ?”, “Buttons”, JOptionPane. WARNING_MESSAGE, 0, null, buttons, null);

New cards
10

What is SWING

A package allowing programmers to create applications in the GUI

New cards
11

What is JFrame

The main window where components like labels, buttons, textfields are added to create a GUI

New cards
12

Where do you set the properties of the frame?

In the constructor

New cards
13

What does setting null to setLocatioNrelativeTo(null); do

It sets the JFrame to the center of the users screens

New cards
14

Difference between private, protected, and public modifiers

Private: Makes data fields accessible in a singular class

Public: Makes data fields accessible in all classes within the project folder

Protected: Makes data fields accessible in all classes or subclasses

New cards
15

What JFrame method must always be used

seteVisible(true);

New cards
16

What must be written in main after setting the properties in the constructor?

new [class name](); —> This calls on the constructor

New cards
17

What 2 methods do you need to change the background colour of the frame

getContentPane() and setBackground()

getContentPane().setBackground(Color.BLUE);

<p>getContentPane() and setBackground()</p><p></p><p>getContentPane().setBackground(Color.BLUE);</p>
New cards
18

What is the difference between Graphics and Graphics2D

Graphics: It is used for simple drawings

Graphics2D: Used for more complex and high-quality graphics rendering.

New cards
19

How does drawing strings work in the paint method?

g2.drawString(“message”, x, y);

New cards
20

How to instantiate a font

Font f = new Font(“Papyrus”, Font.BOLD, 18);

New cards
21

How to instantiate a FontMetrics and what is FontMetrics

FontMetrics fm = getFontMetrics(f);

It is used to measure the size of characters, strings, and other text elements in a specific font

New cards
22

How to write custom fonts

Font f = Font.createFont(Font.TRUETYPE_FONT, new FILE(“file”)).deriveFont(30f)

New cards
23

How to draw images?

g2.drawImage(img.getImage(), xPos, yPos, this);

New cards
24

How to draw lines and rectangles?

g2.draw(new Line2D.Double(Origin X, Origin Y, Width, Height);

g2.draw(new Rectangle2D.Double(Origin X, Origin Y, Width, Height);

New cards
25

How to set colours of the shape drawn

g2.setColor(Color.COLOR);

g2.draw(new Rectangle2D.Double(Origin X, Origin Y, Width, Height);

New cards
26

How to import JPanel to a class

After the class name write “extends JPanel” and import the package

public class Example extends JPanel {

}

New cards
27

Is JFrame the same as JPanel?

JFrame represents a framed window and a JPanel represents some area in which controls

New cards
28

Where does JFrame go when using JPanel

Instead of writing Extends JFrame at the top, JFrame will be instantiated in side the constructor, and the name given must be used to set the JFrame properties

Ex:

JFrame jf = new JFrame();

jf. setSize(100, 500);

New cards
29

Biggest change in the JFrame when using JPanel

the setContentPane(this);

When the keyword this is set inside the parameters, it tells JFrame to add all components of JPane to the JFrame so we can see it.

New cards
30

What’s the difference between a method and a constructor?

A constructor instantiates field, named after the class, and has no return type

A method is named everything but the class name and has a return type, either void or a datatype

New cards
31

What makes up a method header

public int max(int num1, int num2){}

Visibility: Public

Return Type: int

Method Name: move

Parameters: int num1, int num2

New cards
32

What are the 3 keywords that a class containss?

Fields: Defines the global variables

Constructors: Initializes the fields

Methods: Defines the methods of the class and returns the data type

New cards
33

How to access another class in main

[Class name] [name] = new [Class name]();

[name].[method in class]();

Ex: Dice dice = new Dice();

dice.getRoll();

New cards
34

What is a Unified Modelling Language (UML) Diagram

A diagram used to help programmers organize their code to help non-programmers understand.

New cards
35

What is a UML made up of

Class Name

Fields

Constructors and Methods

New cards
36

How are the components of a UML denoted?

Fields: field name: Data Type

Constructor: [Constructor Name](Parameters)

Methods: [Method Name](Parameter): [Data Type]

<p><strong>Fields: </strong>field name: Data Type</p><p><strong>Constructor: </strong>[Constructor Name](Parameters)</p><p><strong>Methods: </strong>[Method Name](Parameter): [Data Type]</p>
New cards
37

Which symbols indicate the visibility?

Public: +

Private: -

Protected: #

New cards
38

What is an accessor and mutator?

Accessor: An accessor method, or getter, is used to retrieve the value of an instance variable. It typically follows a naming convention where the method name starts with "get" followed by the name of the variable with the first letter capitalized.

Mutator: A mutator method, or setter, is used to set or update the value of an instance variable. It typically follows a naming convention where the method name starts with "set" followed by the name of the variable with the first letter capitalized.

New cards
39

How does the RGB Color work?

There are 3 numbers that represent Red, Blue and Yellow

  • (0, 0, 0)

New cards
robot