ICS3U1 - Object Oriented Programming

0.0(0)
studied byStudied by 5 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/38

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

39 Terms

1
New cards

What is JOptionPane

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

2
New cards

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>
3
New cards

5 Different types of Messages

  1. Error_Message

  2. Information_Message

  3. Warning_Message

  4. Question_Message

  5. Plain_Message

4
New cards

What is polymorphism?

Fuck you nigger Richard

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

Difference between scanner and JOptionPane

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

6
New cards

Difference between showMessageDialog() and showInputDialog()

showMessageDialog() - Does not return or input anything

showInputDialog() - Can read user input

7
New cards

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>
8
New cards

How to import custom images in java

Declare and initialize an ImageIcon object

private ImageIcon img;

img = new ImageIcon (“file name“);

9
New cards

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);

10
New cards

What is SWING

A package allowing programmers to create applications in the GUI

11
New cards

What is JFrame

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

12
New cards

Where do you set the properties of the frame?

In the constructor

13
New cards

What does setting null to setLocatioNrelativeTo(null); do

It sets the JFrame to the center of the users screens

14
New cards

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

15
New cards

What JFrame method must always be used

seteVisible(true);

16
New cards

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

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

17
New cards

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>
18
New cards

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.

19
New cards

How does drawing strings work in the paint method?

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

20
New cards

How to instantiate a font

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

21
New cards

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

22
New cards

How to write custom fonts

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

23
New cards

How to draw images?

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

24
New cards

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);

25
New cards

How to set colours of the shape drawn

g2.setColor(Color.COLOR);

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

26
New cards

How to import JPanel to a class

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

public class Example extends JPanel {

}

27
New cards

Is JFrame the same as JPanel?

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

28
New cards

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);

29
New cards

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.

30
New cards

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

31
New cards

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

32
New cards

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

33
New cards

How to access another class in main

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

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

Ex: Dice dice = new Dice();

dice.getRoll();

34
New cards

What is a Unified Modelling Language (UML) Diagram

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

35
New cards

What is a UML made up of

Class Name

Fields

Constructors and Methods

36
New cards

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>
37
New cards

Which symbols indicate the visibility?

Public: +

Private: -

Protected: #

38
New cards

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.

39
New cards

How does the RGB Color work?

There are 3 numbers that represent Red, Blue and Yellow

  • (0, 0, 0)