Looks like no one added any tags here yet for you.
What is JOptionPane
A class enabling programmers to use dialog boxes to recieve user input
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);
5 Different types of Messages
Error_Message
Information_Message
Warning_Message
Question_Message
Plain_Message
What is polymorphism?
Fuck you nigger Richard
Difference between scanner and JOptionPane
JOptionPane only takes in STRING values while Scanner can read all datatypes
Difference between showMessageDialog() and showInputDialog()
showMessageDialog() - Does not return or input anything
showInputDialog() - Can read user input
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.
How to import custom images in java
Declare and initialize an ImageIcon object
private ImageIcon img;
img = new ImageIcon (“file name“);
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);
What is SWING
A package allowing programmers to create applications in the GUI
What is JFrame
The main window where components like labels, buttons, textfields are added to create a GUI
Where do you set the properties of the frame?
In the constructor
What does setting null to setLocatioNrelativeTo(null); do
It sets the JFrame to the center of the users screens
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
What JFrame method must always be used
seteVisible(true);
What must be written in main after setting the properties in the constructor?
new [class name](); —> This calls on the constructor
What 2 methods do you need to change the background colour of the frame
getContentPane() and setBackground()
getContentPane().setBackground(Color.BLUE);
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.
How does drawing strings work in the paint method?
g2.drawString(“message”, x, y);
How to instantiate a font
Font f = new Font(“Papyrus”, Font.BOLD, 18);
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
How to write custom fonts
Font f = Font.createFont(Font.TRUETYPE_FONT, new FILE(“file”)).deriveFont(30f)
How to draw images?
g2.drawImage(img.getImage(), xPos, yPos, this);
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);
How to set colours of the shape drawn
g2.setColor(Color.COLOR);
g2.draw(new Rectangle2D.Double(Origin X, Origin Y, Width, Height);
How to import JPanel to a class
After the class name write “extends JPanel” and import the package
public class Example extends JPanel {
}
Is JFrame the same as JPanel?
JFrame represents a framed window and a JPanel represents some area in which controls
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);
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.
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
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
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
How to access another class in main
[Class name] [name] = new [Class name]();
[name].[method in class]();
Ex: Dice dice = new Dice();
dice.getRoll();
What is a Unified Modelling Language (UML) Diagram
A diagram used to help programmers organize their code to help non-programmers understand.
What is a UML made up of
Class Name
Fields
Constructors and Methods
How are the components of a UML denoted?
Fields: field name: Data Type
Constructor: [Constructor Name](Parameters)
Methods: [Method Name](Parameter): [Data Type]
Which symbols indicate the visibility?
Public: +
Private: -
Protected: #
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.
How does the RGB Color work?
There are 3 numbers that represent Red, Blue and Yellow
(0, 0, 0)