Git Product home page Git Product logo

ooplab's Introduction

Object-oriented Programming

Almost all of what I've written this Semester is here for CS214/0, Navigate to src Enjoy :)

Important

Keep Scrolling down for CS214 CheatSheet/Summary(Exceptions, Radio Buttons,...)

Some Notes:

  1. Feel Free to Fork or Clone the Repository and Edit as u want.
  2. In case there is any Problem in my Code or if you want to Contribute, you can use GitHub issues or pull requests (Assuming you know Github), If no, U can reach out to me from the one who told you about this Repo.

Iterator

Forward Iteration

  • itr.hasNext() true if there is a next element in the collection.
  • itr.hasNext() Returns the next object.

Backward Iteration

  • itr.hasPrevious() true if there is a previous element.
  • itr.previous() Returns the previous element.

Getting the Index of an Element

  • itr.nextIndex() Returns index of element that would be returned by subsequent call to next().
  • itr.previousIndex()

Sets

  • Testing if s2 is a subset of s1 s1.containsAll(s2) The answer is True or False
  • Setting s1 to the union of s1 and s2 s1.addAll(s2)
  • Setting s1 to the intersection of s1 and s2 s1.retainAll(s2)
  • Setting s1 to the difference of s1 and s2 s1.removeAll(s2)

instanceof

if(post instanceof MessagePost )
MessagePost msg = ( MessagePost )
… access MessagePost methods via msg ...

Radio Buttons

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class RadioButton implements ActionListener{
    static JRadioButton first;
    static JRadioButton second;
    static JTextField text;

    public static void main(String[] args){
        JFrame frame = new JFrame ("Radio Button");
        frame.setSize(500,500);
        frame.setBackground(Color.white);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        //Create a text field
        text = new JTextField();
        text.setBounds(0,0,500,50);
        frame.add(text);
        //Creat two radio Buttons
        first = new JRadioButton("First");
        second =  new JRadioButton("Second");
        first.setBounds(210, 100, 80, 60);
        second.setBounds(210, 200, 80, 60);
        frame.add(first);
        frame.add(second);
        //Create a radio Button Object
        RadioButton obj = new RadioButton();
        //Associate the radio buttons with ActionListener
        first.addActionListener(obj);
        second.addActionListener(obj);
        //Display the Frame
        frame.setVisible(true);
        }

    //Display the text of the selected Button
    public void actionPerformed(ActionEvent e) {
        String x = e.getActionCommand();
        if (x.equals("First")) {
            if (second.isSelected())
                second.setSelected(false);
        } else {
            if (first.isSelected())
                first.setSelected(false);
        }
        text.setText("The Button selected is: " + x);
}
}

CheckBox

import javax.swing.*;

    public class CheckBoxExample {
        CheckBoxExample() {
        JFrame myFrame =  new JFrame ("CheckBox Example ");

        JCheckBox pythonCheckBox  = new JCheckBox(" Python");
        pythonCheckBox.setBounds(100, 100, 90, 90);

        JCheckBox javaCheckBox = new JCheckBox("Java", true);
        javaCheckBox.setBounds(100, 190, 90, 90);

        myFrame.add(pythonCheckBox);
        myFrame.add(javaCheckBox);

        myFrame.setSize(400, 400);
        myFrame.setLayout(null);
        myFrame.setVisible(true);
    }
    public static void main(String[] arr){
        new CheckBoxExample();
    }
}

Exceptions

Types of Exceptions

  1. Checked Exceptions: Checked for at Compile time.
  2. Unchecked exceptions: Aren't checked at Compile time.

Standart Exception Types with Examples:

  • IndexOutOfBoundsException U have an array arr of length n ---> arr[n+2]
  • IllegalArgumentException calling a method print(int value) with print();
  • EOFException An end of file mark has been seen.
  • ArithmeticException Division by zero
  • NumberFormatException Using Illegal Number Format, like using a float instead of integer
  • NullPointerException a class method is being called by an object instance that is currently null

Notes:

  1. throw !(in Methods), u can use throw new Exception_type("Error Msg");
  2. throws Methods throwing Checked Exception must have throws for Exceptions that can be raised by a method.
  3. U can use Multiple catch statements with try
  4. u can use catch for Multiple Options (1 || 2)
  5. finally Perform any Common Actions whether an Exception is thrown or not, check Below:

try{
  writingthisFile();
} 
catch (FileNotFoundException e){
  CatchtheMSGifUCan();
}
finally{   // الي مبين انه وجوده وعدمه واحد
  closetheFile(); 
}

ooplab's People

Contributors

ahmad-mtr avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.