Table of Contents
Java (Full course)................................................................................................................................................ 1
GUI................................................................................................................................................................... 16
Auston java....................................................................................................................................................... 17
Java (Full course)
48. Audio
import [Link].*;
import [Link];
import [Link];
import [Link];
public static void main(String[] args) throws UnsupportedAudioFileException,
IOException, LineUnavailableException {
Scanner scanner = new Scanner([Link]);
File file = new File("file_example_WAV_2MG.wav");
AudioInputStream audioStream = [Link](file);
Clip clip = [Link]();
[Link](audioStream);
String response = "";
while (){
[Link]("P = play, S = stop, R = reset, Q = quit");
[Link]("Enter your chocie: ");
response = [Link]();
response = [Link]();
switch (response){
case ("P"):
[Link]();
break;
case ("S"):
[Link]();
break;
case ("R"):
[Link](0);
break;
case ("Q"):
[Link]();
break;
default:
[Link]("Not a vaild response");
break;
}
[Link]("Byeee!");
47. FileReader
try {
FileReader fileReader = new FileReader("[Link]");
int data = [Link]();
while (data != -1){
[Link]((char)data);
data = [Link]();
}
[Link]();
} catch (FileNotFoundException e) {
[Link]();
} catch (IOException e) {
[Link]();
}
46. FileWriter
try {
FileWriter fileWriter = new FileWriter("[Link]");
[Link]("Thii is heading\n this is subheading");
[Link]("\n(A paper by Tayzar)");
[Link]();
} catch (IOException e) {
[Link]();
}
45. File class
File file = new File("/Users/macbook/Downloads/Secerct_file.txt");
if ([Link]()){
[Link]("This file exist");
[Link]([Link]());
[Link]([Link]());
[Link]([Link]());
[Link]();
}
else {
[Link]("This file does not exist");
}
44. Exception
Scanner scanner = new Scanner([Link]);
try{
[Link]("Enter a whole number to divide: ");
int x = [Link]();
[Link]("Enter a whole number to divide by: ");
int y = [Link]();
double z = x/y;
[Link]("The answer is " +z);
}
catch (ArithmeticException e){
[Link]("you can't divde a zero!");
}
catch (InputMismatchException e){
[Link]("PLEASE Enter a whole number!");
}
catch (Exception e){
[Link]("Someting went wrong");
}
finally {
[Link]();
}
43. Dynamic Polymorphism
Animal animal;
Scanner scanner = new Scanner([Link]);
[Link]("What animal you want?");
[Link]("Press [Link] or [Link]: ");
int choice = [Link]();
if (choice == 1){
animal = new Dog();
[Link]();
}
else if (choice == 2){
animal = new Cat();
[Link]();
}
else {
animal = new Animal();
[Link]();
}
public class Animal {
public void speak(){
[Link]("Animal goes *brrrr*");
}
}
public class Dog extends Animal{
@Override
public void speak(){
[Link]("Dog goes *bark*");
}
}
public class Cat extends Animal{
@Override
public void speak(){
[Link]("Cat goes *Meow*");
}
}
42. polymorphish
Car car = new Car();
Bicycles bicycles = new Bicycles();
Boat boat = new Boat();
Vehicles[] racers = {car, bicycles, boat};
for (Vehicles x : racers){
[Link]();
}
public class Vehicles {
void go(){
}
}
public class Car extends Vehicles{
@Override
void go(){
[Link]("This car is moving");
}
}
public class Boat extends Vehicles{
@Override
void go(){
[Link]("This boat is moving");
}
}
public class Bicycles extends Vehicles{
@Override
void go(){
[Link]("This bicycle is moving");
}
}
41. intrfaces
Fish fish = new Fish();
[Link]();
[Link]();
Hawl hawl = new Hawl();
[Link]();
Rabbit rabbit = new Rabbit();
[Link]();
public class Fish implements Prey,Predator{
@Override
public void hunt() {
[Link]("This fish it hunting the smaller fish");
}
@Override
public void flee() {
[Link]("This fish is fleeing form larger fish");
}
}
public class Hawl implements Predator{
@Override
public void hunt() {
[Link]("*It is hunting*");
}
}
public class Rabbit implements Prey {
@Override
public void flee() {
[Link]("*this is fleeing*");
}
}
public interface Prey {
void flee();
}
public interface Predator {
void hunt();
}
40. copy objects
Car car1 = new Car("BLue", "Prototype", 123);
// Car car2 = new Car("Pink", "Real", 12234);
//[Link](car1);
Car car2 = new Car(car1);
[Link](car1);
[Link](car2);
[Link]([Link]());
[Link]([Link]());
[Link]([Link]());
[Link]([Link]());
[Link]([Link]());
[Link]([Link]());
public class Car {
private String make;
private String model;
private int year;
Car(String make, String model, int year){
[Link](make);
[Link](model);
[Link](year);
}
Car(Car x){
[Link](x);
}
public String getMake(){
return make;
}
public String getModel(){
return model;
}
public int getYear(){
return year;
}
public void setMake(String make){
[Link] = make;
}
public void setModel(String model){
[Link] = model;
}
public void setYear(int year){
[Link] = year;
}
public void copy(Car x){
[Link]([Link]());
[Link]([Link]());
[Link]([Link]());
}
}
39. Encapsulation
Car car = new Car("BLue", "Prototype", 123);
[Link](2022);
[Link]([Link]());
[Link]([Link]());
[Link]([Link]());
public class Car {
private String make;
private String model;
private int year;
Car(String make, String model, int year){
[Link](make);
[Link](model);
[Link](year);
}
public String getMake(){
return make;
}
public String getModel(){
return model;
}
public int getYear(){
return year;
}
public void setMake(String make){
[Link] = make;
}
public void setModel(String model){
[Link] = model;
}
public void setYear(int year){
[Link] = year;
}
}
[Link]
Car2 car2 = new Car2();
[Link]();
public abstract class Vehicle {
abstract void go();
}
public class Car2 extends Vehicle{
@Override
void go(){
[Link]("This car is moving");
}
36. Super keywords
Hero hero =new Hero("Tayzar", 23, "Everything");
[Link]([Link]());
public class Person {
String name;
int age;
Person(String name, int age){
[Link] = name;
[Link] = age;
}
public String toString(){
return [Link] + "\n" + [Link] + "\n";
}
}
public class Hero extends Person{
String power;
Hero(String name, int age, String power){
super(name,age);
[Link] = power;
}
public String toString() {
return [Link]() + [Link] + "\n";
}
}
35. Methods overriding
Animal animal = new Animal();
[Link]();
dog dog = new dog();
[Link]();
public class Animal {
void speak(){
[Link]("Animal speaks");
}
}
public class dog extends Animal{
@Override
void speak(){
[Link]("The dogs *bark*");
}
34. Inheritant
Bicycle bicycle = new Bicycle();
[Link]();
Car2 car = new Car2();
[Link]();
[Link]([Link]);
[Link]([Link]);
public class Vehicle {
double speed;
void go(){
[Link]("This vehicle is moving");
}
void stop(){
[Link]("This vehicle is stopped");
}
}
public class Car2 extends Vehicle{
int wheels = 4;
int doors = 4;
}
public class Bicycle extends Vehicle{
int wheels = 2;
int pedals = 2;
}
33. Static keywords
Friends friend1 = new Friends("Java");
Friends friend2 = new Friends("HTLM");
Friends friend3 = new Friends("C");
Friends friend4 = new Friends("C++");
// [Link]([Link]);
[Link]();
public class Friends {
String name;
static int numbersOfFriends;
Friends(String name){
[Link] = name;
numbersOfFriends++;
}
static void displaysFriends(){
[Link]("You have "+numbersOfFriends+ " friends");
}
}
32. Objects passing
Garage garage = new Garage();
Car1 car1 = new Car1("BMW");
Car1 car2 = new Car1("Tesla");
[Link](car1);
[Link](car2);
public class Garage {
void park (Car1 abc){
[Link]([Link] +" is parked in the garage");
}
}
public class Car1 {
String name;
Car1(String name){
[Link] = name;
}
}
31. Arrays of objects
// Food[] refrigerator = new Food[3];
Food food1 = new Food("Pizza");
Food food2 = new Food("humbager");
Food food3 = new Food("hotdog");
Food[] refrigerator = {food1, food2, food3};
// refrigerator[0] = food1;
// refrigerator[1] = food2;
//refrigerator[2] = food3;
[Link](refrigerator[0].name);
[Link](refrigerator[1].name);
[Link](refrigerator[2].name);
// [Link]([Link]);
public class Food {
String name;
Food(String name){
[Link] = name;
}
}
30. toString methods
car car = new car();
// [Link]([Link]());
[Link](car);
public class car {
String make = "England";
String model = "Tokyo";
int year = 2021;
String color = "Black";
double price = 500000.00;
public String toString(){
// String myString = make+"\n"+model+"\n"+year+"\n"+color+"\n"+price;
//return myString; or
return make+"\n"+model+"\n"+year+"\n"+color+"\n"+price;
}
29. overloaded Constructors
Pizza pizza = new Pizza("Thicc curst", "Tomato", "Golden Egg");
[Link]("Here are the ingredients of your pizza: ");
[Link]([Link]);
[Link]([Link]);
[Link]([Link]);
[Link]([Link]);
public class Pizza {
String bread;
String saucse;
String cheese;
String topping;
Pizza(String bread, String saucse){
[Link] = bread;
[Link] = saucse;
}
Pizza(String bread, String saucse, String cheese){
[Link] = bread;
[Link] = saucse;
[Link] = cheese;
}
Pizza(String bread, String saucse, String cheese, String topping){
[Link] = bread;
[Link] = saucse;
[Link] = cheese;
[Link] = topping;
}
}
28. variable scope
DiceRoller diceRoller = new DiceRoller();
public class DiceRoller {
// [Global]
Random random;
int number;
DiceRoller(){
random = new Random();
number = 0;
roll();
}
void roll(){
number = [Link](6)+1;
[Link](number);
}
}
/*
// [Local]
DiceRoller(){
Random random = new Random();
int number = 0;
roll(random, number);
}
void roll(Random random, int number){
number = [Link](6)+1;
[Link](number);
}
*/
/*
27. Constructors
Human human1 = new Human("Jhon", 12, 23.4);
Human human2 = new Human("Hagai", 34, 234.4);
[Link]([Link]);
[Link]([Link]);
[Link]();
[Link]();
public class Human {
String name;
int age;
double weight;
Human(String name, int age, double weight){
[Link] = name;
[Link] = age;
[Link] = weight;
}
void eat(){
[Link]([Link] +" is eating");
}
void drink(){
[Link]([Link]+" is drinking *brup*");
}
26. objects(OOP)
car myCar = new car();
[Link]([Link]);
[Link]();
[Link]();
public class car {
String make = "England";
String model = "Tokyo";
int year = 2021;
String color = "Black";
double price = 500000.00;
void drive (){
[Link]("You drive the car");
}
void brake(){
[Link]("You steps on the brake");
}
25. final Keywords
final double PI = 3.142;
[Link](PI);
24. printf
int age = 12;
char symbol = '!';
double gpa = 2.3;
String name = "Tayzar";
boolean Male = true;
//[Coversion Characters]
// [Link]("%d %c %f %s %b", age, symbol, gpa, name, Male);
//[Width]
//[Link]("Hello %10s", name);
//[Precision]
//[Link]("You have %.2f", gpa);
//[flag]
[Link]("You have %,f", gpa);
//10f -10f -f +f 020f
23. Overloaded Methods
public class Main {
public static void main(String args[]){
add(1, 2);
add(1,2,3);
add(1,2,3,4);
}
static int add(int x, int y){
int z = x + y;
[Link]("This is the overloaded method #1");
[Link](z);
return z;
}
static int add(int x, int y, int a){
int z = x + y + a;
[Link]("This is the overloaded method #2");
[Link](z);
return z;
}
static int add(int x, int y, int a, int b){
int z = x + y + a + b;
[Link]("This is the overloaded method #3");
[Link](z);
return z;
}
static double add(double x, double y){
double z = x + y;
[Link]("This is the overloaded method #4");
[Link](z);
return z;
}
static double add(double x, double y, double a){
double z = x + y + a;
[Link]("This is the overloaded method #5");
[Link](z);
return z;
}
static double add(double x, double y, double a, double b){
double z = x + y + a + b;
[Link]("This is the overloaded method #6");
[Link](z);
return z;
}
}
22. Methods
hello("Power Range", 12);
}
static void hello(String name, int age){
[Link]("Hello "+name + ". You are " +age);
}
public class Main {
public static void main(String args[]) {
add(2,4);
}
static int add(int x, int y){
int z = x + y;
[Link](z);
return z;
}
}
21. For each loop
// String[] animals = {"cat", "dogs", "bird", "rat"};
ArrayList<String> animals = new ArrayList<String>();
[Link]("cat");
[Link]("birds");
for (String i : animals){
[Link](i);
}
18. Wrapper classes
Integer a = 123;
Double d = 2.3;
Boolean b = true;
String s = "Hey";
Character c = '=';
19. Array List
ArrayList<String> food = new ArrayList<String>();
[Link]("Power_Food");
[Link]("Strength");
[Link]("Water");
[Link](0, "Sleep"); // same as add
[Link](2);
[Link]();
for(int i = 0; i < [Link](); i++){
// size not length
[Link]([Link](i));
}
20. 2D array List
ArrayList<String> bakeryList = new ArrayList<String>();
[Link]("Pasta");
[Link]("Sushi");
[Link]("Pizza");
// [Link](bakeryList);
// [Link]([Link](0));
ArrayList<String> productList = new ArrayList<String>();
[Link]("Tomatos");
[Link]("Banana");
[Link]("Potato");
ArrayList<String> drinkList = new ArrayList<String>();
[Link]("Coffee");
[Link]("Bubble_tea");
combine
ArrayList<ArrayList<String>> groceryList = new ArrayList();
ArrayList<String> bakeryList = new ArrayList<String>();
[Link]("Pasta");
[Link]("Sushi");
[Link]("Pizza");
ArrayList<String> productList = new ArrayList<String>();
[Link]("Tomatos");
[Link]("Banana");
[Link]("Potato");
ArrayList<String> drinkList = new ArrayList<String>();
[Link]("Coffee");
[Link]("Bubble_tea");
[Link](productList);
[Link](drinkList);
[Link](bakeryList);
// [Link](groceryList);
[Link]([Link](0).get(0));
17. String functions
String name = "Tayzar";
// boolean result = [Link]("tayzar");
// requals mean exactly equal
// char result = [Link](1);
// int result = [Link]("y");
boolean result = [Link]();
[Link](result);
16. 2D arrays
String[][] currentListOfMedicince ={
{"Bitarmin", "Biojustsis", "Batmintin"},
{"Arenba", "Amberma", "Aquain"},
{"Cetinmin", "Cellgrow", "Cattalim"},
{"Digging", "Dulingo", "Doover"}
};
for (int i = 0; i<[Link]; i++){
[Link]();
for (int j = 0; j < currentListOfMedicince[i].length; j++){
[Link](currentListOfMedicince[i][j]+ " ");
}
}
15. Arrays
String[] subjects = {"Math", "Eng", "Science", "Chemical"};
//subjects [0] = "Myn";
[Link](subjects[0]);
String[] subjects = new String[3];
subjects[0] = "Math";
subjects[1] = "Science";
subjects[2] = "Chemical";
for (int i = 0; i < [Link]; i++){
[Link](subjects[i]);
14. nested loop
Scanner scanner = new Scanner([Link]);
int rows;
int columes;
String symbol = "";
[Link]("Enter # of rows: ");
rows = [Link]();
[Link]("Enter # of columes: ");
columes = [Link]();
[Link]("Enter a symbol to use: ");
symbol = [Link]();
for (int i = 1; i <= rows; i++){
[Link]();
for (int j = 1; j <= columes; j++){
[Link](symbol);
}
}
for (int i = 1; i <= 5; i++){
[Link]();
for (int j = i; j <= 5; j++){
[Link](j);
}
}
for (int i = 1; i <= 5; i++){
[Link]();
for (int j = i; j <= 5; j++){
[Link](i);
}
}
[Link] loop
// execute limited amount of time
for (int i = 10; i >= 0;){
// for (int i = 0; i <= 10; i++)
// for (int i = 10; i >= 0; i--)
// for (int i = 10; i >= 0; i-=2)
[Link](i);
i-=2;
}
[Link]("Happy new year.");
[Link] loop
Scanner scanner = new Scanner([Link]);
String name = "";
while ([Link]()){
// excutes the lines of code as long as that conditons still remain true
[Link]("Enter your name: ");
name = [Link]();
[Link]("Hello, Welcome " +name);
do{
// excutes the lines of code as long as that conditons still remain true
[Link]("Enter your name: ");
name = [Link]();
}while ([Link]());
11. Logical Operators
int temp;
Scanner scanner = new Scanner([Link]);
[Link]("Enter your temp: ");
temp = [Link]();
[Link](temp);
if (temp >= 30 && temp <= 20){
[Link]("It is nice outisde!");
}
else if (temp <= 10 || temp <=0){
[Link]("It is freezing out there!");
}
else if (temp != 15 && temp != 25){
[Link]("Same as ususal");
}
else {
[Link]("it is ranning!");
}
Scanner scanner = new Scanner([Link]);
[Link]("Enter the lower q or upper Q to quite");
String respond = [Link]();
if([Link]("q") || [Link]("Q")){
[Link]("You have quit the game");
}
else {
[Link]("You are still in the game");
}
Scanner scanner = new Scanner([Link]);
[Link]("Enter the lower q or upper Q to quite: ");
String respond = [Link]();
if( && ){
[Link]("You are still in the game");
}
else {
[Link]("You have quit the game");
}
2. Variables
int age = 23;
[Link]("I am " + age);
String name = "Tayzar";
[Link]("Hello " +name);
3. Swap Two variables
String x = "Water";
String y = "Acid";
String temp;
// Switcing the value
temp = x;
x = y;
y = temp;
// x = y Acid
// y = x Water
[Link]("x: " +x);
[Link]("y: " +y);
4. User input
Scanner scanner = new Scanner([Link]);
[Link]("Enter Your Name: ");
String name = [Link]();
// \n is gone
[Link]("Enter Your age: ");
int age = [Link]();
// \n does not go away
[Link]();
// \n now it is gone
[Link]("Enter your favorite food: ");
String food = [Link]();
// \n is gone
[Link]("Hello, Welcome to the programming world " +name);
[Link]("You are " +age+ "years old");
[Link]("Wow! your favorite food is " +food);
5. Experssion
//expression = operands & operators
// operands = values, variables, numbers, quantity
// operators = + - * / %
// int appleSlices = 4;
// double appleSlices = 4;
// appleSlices = appleSlices + 1;
// appleSlices += 1;
// appleSlices ++; // just one
// appleSlices = appleSlices / 3;
// [Link](appleSlices);
7. Math class
double a = 23.45;
double b = -30.0;
double c = [Link](a);
//max, min, abs, sqrt, pow, round, ceil, floor
[Link](c);
double x,y,z;
Scanner scanner = new Scanner([Link]);
[Link]("Enter the side x: ");
x = [Link]();
[Link]("Enter the side y: ");
y = [Link]();
// hypotenuse formula c = squaroot of a square + b square
z = [Link]((x*x)+(y*y));
[Link]("The hypotenuse is: " +z);
[Link]();
[Link] numbers
Random random = new Random();
// int x = [Link](6); // limit 0 - 5
//int x = [Link](6)+1; // limit now 0 - 6
// double y = [Link](); // 0 to 1
boolean z = [Link]();
[Link](z);
9. if statements
int typesOfGuess = 1;
// Scanner scanner = new Scanner([Link]);
// [Link]("Enter between 1 to 3");
// [Link]("Enter your number: ");
if (typesOfGuess == 1){
[Link]("You are a VIP guess!");
}
else if(typesOfGuess == 2){
[Link]("You are an entertainer.");
}
else if(typesOfGuess == 3){
[Link]("You are just a normal guess.");
}
else {
[Link]("You are not allowed to go in.");
}
[Link] statments
int gpa = 3;
switch (gpa) {
case 2:
[Link]("You did normal!");
break;
case 3:
[Link]("You did average!");
break;
case 4:
[Link]("You did awesome!");
break;
case 5:
[Link]("You did ellcentent!");
break;
default:
[Link]("Keep it up!");
}
GUI
69. mouse listener
new mouselistener();
import [Link].*;
import [Link].*;
import [Link];
import [Link];
public class mouselistener extends JFrame implements MouseListener {
JLabel label;
ImageIcon a;
ImageIcon b;
ImageIcon c;
ImageIcon d;
mouselistener() {
[Link](JFrame.EXIT_ON_CLOSE);
[Link](500, 500);
[Link](new FlowLayout());
label = new JLabel();
[Link](this);
a = new ImageIcon("[Link]");
b = new ImageIcon("[Link]");
c = new ImageIcon("[Link]");
d = new ImageIcon("[Link]");
[Link](a);
[Link](label);
[Link]();
[Link](null);
[Link](true);
}
@Override
public void mouseClicked(MouseEvent e) {
@Override
public void mousePressed(MouseEvent e) {
[Link](b);
@Override
public void mouseReleased(MouseEvent e) {
[Link](c);
@Override
public void mouseEntered(MouseEvent e) {
[Link](d);
@Override
public void mouseExited(MouseEvent e) {
[Link](a);
}
}
JLabel label;
mouselistener(){
[Link](JFrame.EXIT_ON_CLOSE);
[Link](500, 500);
[Link](null);
label = new JLabel();
[Link](0,0, 100, 100);
[Link]([Link]);
[Link](true);
[Link](this);
[Link](label);
[Link](true);
}
@Override
public void mouseClicked(MouseEvent e) {
//[Link]("You clicked the mouse ");
}
@Override
public void mousePressed(MouseEvent e) {
[Link]("You pressed the mouse ");
[Link]([Link]);
}
@Override
public void mouseReleased(MouseEvent e) {
[Link]("You released the mouse ");
[Link]([Link]);
@Override
public void mouseEntered(MouseEvent e) {
[Link]("You entered the component ");
[Link]([Link]);
}
@Override
public void mouseExited(MouseEvent e) {
[Link]("You existed the component ");
[Link]([Link]);
}
}
68. key listener
new keyListener();
import [Link].*;
import [Link].*;
import [Link];
import [Link];
public class keyListener extends JFrame implements KeyListener {
JLabel label;
ImageIcon icon;
keyListener(){
[Link](JFrame.EXIT_ON_CLOSE);
[Link](500, 500);
[Link](this);
[Link](null);
icon = new ImageIcon("[Link]");
label = new JLabel();
[Link](0,0,100,100);
[Link](icon);
//[Link]([Link]);
//[Link](true);
[Link]().setBackground([Link]);
[Link](label);
[Link](true);
}
@Override
public void keyTyped(KeyEvent e) {
switch ([Link]()){
case 'a' :
[Link]([Link]()-10, [Link]());
break;
case 'w' :
[Link]([Link](), [Link]()-10);
break;
case 's' :
[Link]([Link]()+10, [Link]());
break;
case 'd' :
[Link]([Link](), [Link]()+10);
break;
}
@Override
public void keyPressed(KeyEvent e) {
switch ([Link]()){
case 37 :
[Link]([Link]()-10, [Link]());
break;
case 38 :
[Link]([Link](), [Link]()-10);
break;
case 39 :
[Link]([Link]()+10, [Link]());
break;
case 40 :
[Link]([Link](), [Link]()+10);
break;
}
}
@Override
public void keyReleased(KeyEvent e) {
[Link]("YOu released key "+[Link]());
[Link]("YOu released code "+[Link]());
}
}
67. color Chooser
new colorselecter();
import [Link].*;
import [Link].*;
import [Link];
import [Link];
public class colorselecter extends JFrame implements ActionListener {
JButton button;
JLabel label;
colorselecter() {
[Link](JFrame.EXIT_ON_CLOSE);
[Link](new FlowLayout());
button = new JButton("Pick a color");
[Link](this);
label = new JLabel();
[Link]([Link]);
[Link]("This is a text");
[Link](new Font("MV Boli", [Link], 100));
[Link](true);
[Link](label);
[Link](button);
[Link]();
[Link](true);
@Override
public void actionPerformed(ActionEvent e) {
if ([Link]() == button){
JColorChooser colorChooser = new JColorChooser();
Color color = [Link](null, "Pick a color", [Link]);
[Link](color);
// [Link](color);
}
}
}
[Link] choicer class
new fileselecter();
import [Link].*;
import [Link].*;
import [Link];
import [Link];
import [Link];
public class fileselecter extends JFrame implements ActionListener {
JButton button;
fileselecter(){
[Link](JFrame.EXIT_ON_CLOSE);
[Link](new FlowLayout());
button = new JButton("Select file");
[Link](this);
[Link](button);
[Link]();
[Link](true);
@Override
public void actionPerformed(ActionEvent e) {
if ([Link]() == button){
JFileChooser fileChooser = new JFileChooser();
[Link](new File("."));
int respones = [Link](null);
//int respones = [Link](null);
if (respones == fileChooser.APPROVE_OPTION){
File file = new File([Link]().getAbsolutePath());
[Link](file);
}
}
}
}
65. Menu Bar
new menu();
import [Link].*;
import [Link].*;
import [Link];
public class menu extends JFrame implements ActionListener {
JMenuBar menuBar;
JMenu fileMenu;
JMenu editMenu;
JMenu helpMenu;
JMenuItem loadItem;
JMenuItem saveItem;
JMenuItem exitItem;
ImageIcon saveIcon;
ImageIcon loadIcon;
ImageIcon existIcon;
menu(){
[Link](JFrame.EXIT_ON_CLOSE);
[Link](500, 500);
[Link](new FlowLayout());
saveIcon = new ImageIcon("[Link]");
loadIcon = new ImageIcon("[Link]");
existIcon = new ImageIcon("[Link]");
menuBar = new JMenuBar();
fileMenu = new JMenu("File");
editMenu = new JMenu("Edit");
helpMenu = new JMenu("Help");
loadItem = new JMenuItem("Load");
saveItem = new JMenuItem("Save");
exitItem = new JMenuItem("Exist");
[Link](this);
[Link](this);
[Link](this);
[Link](loadIcon);
[Link](saveIcon);
[Link](existIcon);
[Link](KeyEvent.VK_F); // Alt + f to file
[Link](KeyEvent.VK_E); // Alt + e to file
[Link](KeyEvent.VK_H); // Alt + h to file
[Link](KeyEvent.VK_S); // S to save
[Link](KeyEvent.VK_L); // L to load
[Link](KeyEvent.VK_E); //E tp to exist
[Link](loadItem);
[Link](saveItem);
[Link](exitItem);
[Link](fileMenu);
[Link](editMenu);
[Link](helpMenu);
[Link](menuBar);
[Link](true);
}
@Override
public void actionPerformed(ActionEvent e) {
if ([Link]() == loadItem){
[Link]("Loaded file");
}
if ([Link]() == exitItem){
[Link](0);
}
if ([Link]() == saveItem){
[Link]("saved file");
}
}
}
64. progress bar
new progressbar();
import [Link].*;
import [Link].*;
public class progressbar {
JFrame frame = new JFrame();
JProgressBar bar = new JProgressBar(0,500);
progressbar(){
[Link](0);
[Link](0,0,420, 50);
[Link](true);
[Link](new Font("MV Boli", [Link], 25));
[Link]([Link]);
[Link]([Link]);
[Link](bar);
[Link](JFrame.EXIT_ON_CLOSE);
[Link](420, 420);
[Link](null);
[Link](true);
fill();
}
public void fill(){
int counter = 500;
while(counter>0){
[Link](counter);
try {
[Link](50);
} catch (InterruptedException e) {
[Link]();
}
counter -= 1;
}
[Link]("HP out");
}
}
63. Slider
new Slider();
import [Link].*;
import [Link].*;
import [Link].*;
public class Slider implements ChangeListener {
JFrame frame;
JLabel label;
JPanel panel;
JSlider slider;
Slider(){
frame = new JFrame("Slider");
label = new JLabel();
panel = new JPanel();
slider = new JSlider(0, 100, 50);
[Link](new Dimension(400, 200));
[Link](true);
[Link](10);
[Link](true);
[Link](25);
[Link](true);
[Link](new Font("MV Boli", [Link], 15));
[Link](new Font("MV Boli", [Link], 25));
//[Link]([Link]);
[Link]([Link]);
[Link]("°C = "+ [Link]());
[Link](this);
[Link](slider);
[Link](label);
[Link](panel);
[Link](JFrame.EXIT_ON_CLOSE);
[Link](500, 500);
[Link](true);
}
@Override
public void stateChanged(ChangeEvent e) {
[Link]("°C = "+ [Link]());
}
}
[Link] BOX
new combobox();
import [Link].*;
import [Link].*;
import [Link];
import [Link];
public class combobox extends JFrame implements ActionListener{
JComboBox comboBox;
combobox() {
[Link](JFrame.EXIT_ON_CLOSE);
[Link](new FlowLayout());
String[] animals = {"Dogs", "Cat", "Bird"};
comboBox = new JComboBox(animals);
[Link](this);
// [Link]("turtle");
// [Link](true);
//[Link]([Link]());
// [Link]("pig", 0);
// [Link](0);
// [Link]("Cat");
// [Link](0);
// [Link]();
[Link](comboBox);
[Link]();
[Link](true);
}
@Override
public void actionPerformed(ActionEvent e) {
if ([Link]() == comboBox)
{
[Link]([Link]());
}
}
}
61. Radio Button
new RadioButton();
public class RadioButton extends JFrame implements ActionListener {
JRadioButton pizzaButton;
JRadioButton bumgerButton;
JRadioButton hotdogButton;
ImageIcon pizzaIcon;
ImageIcon burgerIcon;
ImageIcon hotdogIcon;
RadioButton(){
[Link](JFrame.EXIT_ON_CLOSE);
[Link](new FlowLayout());
pizzaButton = new JRadioButton("pizza");
bumgerButton = new JRadioButton("burger");
hotdogButton = new JRadioButton("hotdog");
pizzaIcon = new ImageIcon("[Link]");
burgerIcon = new ImageIcon("[Link]");
hotdogIcon = new ImageIcon("[Link]");
[Link](this);
[Link](this);
[Link](this);
ButtonGroup group = new ButtonGroup();
[Link](pizzaButton);
[Link](bumgerButton);
[Link](hotdogButton);
[Link](pizzaIcon);
[Link](burgerIcon);
[Link](hotdogIcon);
[Link](pizzaButton);
[Link](bumgerButton);
[Link](hotdogButton);
[Link]();
[Link](true);
}
@Override
public void actionPerformed(ActionEvent e) {
if ([Link]() == pizzaButton){
[Link]("You order pizza");
}
else if ([Link]()== bumgerButton){
[Link]("You order burger");
}
else if([Link]() == hotdogButton){
[Link]("You order hotdog");
}
}
}
60. Check Box
new CheckBox();
import [Link].*;
import [Link].*;
import [Link];
import [Link];
public class CheckBox extends JFrame implements ActionListener {
JButton button;
JCheckBox checkBox;
CheckBox(){
[Link](JFrame.EXIT_ON_CLOSE);
[Link](new FlowLayout());
button = new JButton("Sumit");
[Link](this);
checkBox = new JCheckBox();
[Link]("I am not a robot");
[Link](false);
[Link](new Font(null, [Link], 23));
[Link](button);
[Link](checkBox);
[Link]();
[Link](true);
}
@Override
public void actionPerformed(ActionEvent e) {
if ([Link]() == button){
[Link]([Link]());
}
}
}
59. Text field
new TextField();
import [Link].*;
import [Link].*;
import [Link];
import [Link];
public class TextField extends JFrame implements ActionListener {
JButton button;
JTextField textField;
TextField(){
[Link](JFrame.EXIT_ON_CLOSE);
[Link](new FlowLayout());
button = new JButton("Sumit");
[Link](this);
textField = new JTextField();
[Link](new Dimension(250,40));
[Link](new Font("Concsal", [Link], 23));
[Link]([Link]);
[Link]([Link]);
[Link]([Link]);
[Link]("Username");
//[Link](false);
[Link](button);
[Link](textField);
[Link]();
[Link](true);
}
@Override
public void actionPerformed(ActionEvent e) {
if ([Link]() == button){
// [Link](false);
[Link]("Hello " +[Link]());
}
}
}
[Link] Pane
// [Link](null, "This is Non-display", "Title",
JOptionPane.PLAIN_MESSAGE );
// [Link](null, "This is Non-display", "Title",
JOptionPane.INFORMATION_MESSAGE );
// [Link](null, "This is Non-display", "Title",
JOptionPane.QUESTION_MESSAGE );
//[Link](null, "This is Non-display", "Title",
JOptionPane.WARNING_MESSAGE );
// [Link](null, "This is Non-display", "Title",
JOptionPane.ERROR_MESSAGE );
// int answer = [Link](null, "What is your fucking name
you little bitch?", "Title", JOptionPane.YES_NO_CANCEL_OPTION );
// [Link]([Link](null, "What is your fucking
name you little bitch?", "Title", JOptionPane.YES_NO_CANCEL_OPTION ));
// String name = [Link]("What is your name?: ");
// [Link]("Hello "+name);
ImageIcon icon = new ImageIcon("[Link]");
String[] respones = {"To be honest I don't die!", "No I ain't diying today!",
"*died*"};
[Link](
null,
"I am going to fucking kill you",
"Answer:",
JOptionPane.YES_NO_CANCEL_OPTION,
JOptionPane.INFORMATION_MESSAGE,
icon,
respones,
0);
}
57. Open a new GUI window
new LanchPage();
import [Link].*;
import [Link];
import [Link];
public class LanchPage implements ActionListener {
JFrame frame = new JFrame();
JButton button = new JButton("New Window");
LanchPage(){
[Link](100, 160, 200, 40);
[Link](false);
[Link](this);
[Link](JFrame.EXIT_ON_CLOSE);
[Link](400, 400);
[Link](null);
[Link](button);
[Link](true);
@Override
public void actionPerformed(ActionEvent e) {
if ([Link]()== button){
[Link]();
NewWindow myWindow = new NewWindow();
}
}
}
public class NewWindow {
JFrame frame = new JFrame();
JLabel label = new JLabel("Hello Madafaka!");
NewWindow(){
[Link](0, 0, 200, 100);
[Link](new Font(null, [Link], 25));
[Link](label);
[Link](JFrame.EXIT_ON_CLOSE);
[Link](400, 400);
[Link](null);
[Link](true);
}
}
[Link] Pane
JLabel label1 = new JLabel();
[Link](true);
[Link]([Link]);
[Link](50, 50, 200, 200);
JLabel label2 = new JLabel();
[Link](true);
[Link]([Link]);
[Link](100, 100, 200, 200);
JLabel label3 = new JLabel();
[Link](true);
[Link]([Link]);
[Link](150, 150, 200, 200);
JLayeredPane layeredPane = new JDesktopPane();
[Link](0,0, 500, 500);
[Link](label1, JLayeredPane.DEFAULT_LAYER);
[Link](label2, [Link](2));
[Link](label3, JLayeredPane.DRAG_LAYER);
JFrame frame = new JFrame("JLayereddPane");
[Link](layeredPane);
[Link](JFrame.EXIT_ON_CLOSE);
[Link](new Dimension(500, 500));
[Link](null);
[Link](true);
55. Grid Layout
JFrame frame = new JFrame();
[Link](JFrame.EXIT_ON_CLOSE);
[Link](500, 500);
[Link](new GridLayout(3,3, 10, 10));
[Link](new Button("1"));
[Link](new Button("2"));
[Link](new Button("3"));
[Link](new Button("4"));
[Link](new Button("5"));
[Link](new Button("6"));
[Link](new Button("7"));
[Link](new Button("8"));
[Link](new Button("9"));
[Link](true);
54. Flow Layout
JFrame frame = new JFrame();
[Link](JFrame.EXIT_ON_CLOSE);
[Link](500, 500);
[Link](new FlowLayout([Link],10,10));
JPanel panel1 = new JPanel();
[Link](new Dimension(250,250));
[Link]([Link]);
[Link](new FlowLayout());
[Link](new Button("1"));
[Link](new Button("2"));
[Link](new Button("3"));
[Link](new Button("4"));
[Link](new Button("5"));
[Link](new Button("6"));
[Link](new Button("7"));
[Link](new Button("8"));
[Link](new Button("9"));
[Link](panel1);
[Link](true);
53. Border Layout
public static void main(String[] args) {
JFrame frame = new JFrame();
[Link](JFrame.EXIT_ON_CLOSE);
[Link](500, 500);
[Link](new BorderLayout(10,10));
[Link](true);
JPanel panel1 = new JPanel();
JPanel panel2 = new JPanel();
JPanel panel3 = new JPanel();
JPanel panel4 = new JPanel();
JPanel panel5 = new JPanel();
[Link]([Link]);
[Link]([Link]);
[Link]([Link]);
[Link]([Link]);
[Link]([Link]);
[Link](new Dimension(100, 100));
[Link](new Dimension(100, 100));
[Link](new Dimension(100, 100));
[Link](new Dimension(100, 100));
[Link](new Dimension(100, 100));
//---------------------sub panles------------------------------
JPanel panel6 = new JPanel();
JPanel panel7 = new JPanel();
JPanel panel8 = new JPanel();
JPanel panel9 = new JPanel();
JPanel panel10 = new JPanel();
[Link]([Link]);
[Link]([Link]);
[Link](Color.DARK_GRAY);
[Link]([Link]);
[Link]([Link]);
[Link](new BorderLayout());
[Link](new Dimension(50, 50));
[Link](new Dimension(50, 50));
[Link](new Dimension(50, 50));
[Link](new Dimension(50, 50));
[Link](new Dimension(50, 50));
[Link](panel6,[Link]);
[Link](panel7,[Link]);
[Link](panel8,[Link]);
[Link](panel9,[Link]);
[Link](panel10,[Link]);
//-----------------sub panles-----------------------------
[Link](panel1,[Link]);
[Link](panel2,[Link]);
[Link](panel3,[Link]);
[Link](panel4,[Link]);
[Link](panel5,[Link]);
52. buttons
new subFram();
import [Link].*;
import [Link].*;
import [Link];
import [Link];
public class subFram extends JFrame implements ActionListener{
JButton button;
JLabel label;
ImageIcon icon;
ImageIcon icon2;
subFram(){
icon = new ImageIcon("[Link]");
icon2 = new ImageIcon("[Link]");
label = new JLabel();
[Link](icon2);
[Link](250, 250, 200, 200);
[Link](false);
button = new JButton();
[Link](100, 100, 250, 100);
[Link](this);
[Link]("Start");
[Link](false);
[Link](icon);
[Link]([Link]);
//[Link]([Link]);
[Link](-100);
[Link]([Link]);
[Link]([Link]);
[Link]([Link]());
[Link](JFrame.EXIT_ON_CLOSE);
[Link](null);
[Link](800, 800);
[Link](true);
[Link](button);
[Link](label);
}
@Override
public void actionPerformed(ActionEvent e) {
if ([Link]() == button){
[Link](true);
---------------------------------------------------------------------
import [Link].*;
import [Link];
import [Link];
public class subFram extends JFrame implements ActionListener {
JButton button;
subFram(){
button = new JButton();
[Link](200, 100, 100, 50);
[Link](this);
[Link](JFrame.EXIT_ON_CLOSE);
[Link](null);
[Link](800, 800);
[Link](true);
[Link](button);
}
@Override
public void actionPerformed(ActionEvent e) {
if ([Link]() == button){
[Link]("Boo");
[Link](false);
}
}
-----------------------------------------------------------------------------------------------
import [Link].*;
import [Link];
import [Link];
public class subFram extends JFrame implements ActionListener {
JButton button;
ImageIcon icon;
JLabel label;
subFram(){
icon = new ImageIcon("[Link]");
label = new JLabel();
[Link](icon);
[Link](250, 250, 200, 200);
[Link](false);
button = new JButton();
[Link](100, 100, 250, 100);
[Link](this);
[Link]("Start");
[Link](false);
[Link](JFrame.EXIT_ON_CLOSE);
[Link](500, 500);
[Link](null);
[Link](true);
[Link](button);
[Link](label);
}
@Override
public void actionPerformed(ActionEvent e) {
if ([Link]() == button){
[Link](true);
}
}
[Link]
ImageIcon icon = new ImageIcon("[Link]");
JLabel label = new JLabel();
[Link]("Hi");
[Link](icon);
//[Link]([Link]);
// [Link]([Link]);
[Link](100, 100, 240, 240);
JPanel redPanel = new JPanel();
[Link]([Link]);
[Link](0,0,250,250);
[Link](null);
// [Link](new BorderLayout());
JPanel bluePanel = new JPanel();
[Link]([Link]);
[Link](250,0,250,250);
[Link](null);
// [Link](new BorderLayout());
JPanel greenPanel = new JPanel();
[Link]([Link]);
[Link](0,250,500,250);
[Link](null);
// [Link](new BorderLayout());
JFrame frame = new JFrame();
[Link](700, 700);
[Link](JFrame.EXIT_ON_CLOSE);
[Link](null);
[Link](true);
[Link](label);
[Link](redPanel);
[Link](bluePanel);
[Link](greenPanel);
50. labels
ImageIcon icon = new ImageIcon("[Link]");
JFrame Frame = new JFrame();
JLabel label = new JLabel(); // create a label
Border border = [Link]([Link], 3);
[Link]("How are you?");// set text of label
// or JLabel label = new JLabel("How are you?");
[Link](icon);
[Link]([Link]); // Center, Left, Right of
imageicon
[Link]([Link]); //Top, Center, Button of imageicon
[Link]([Link]); // change front color
// [Link](new Color(0, 0, 0));
[Link](new Font("MV Boli", [Link], 24)); //front size
[Link](100); // or -25; set gap of text to image
[Link]([Link]);
[Link](true); // display background color
[Link](border);
[Link]([Link]);//set horizontal position of
icon+text
[Link]([Link]); //set vertical position of icon+text withthin
label
// [Link](100,0,250,250); //set x and y positions as well as dimensions
[Link](JFrame.EXIT_ON_CLOSE);
// [Link](500,500);
// [Link](null);
[Link](true);
[Link](label);
[Link]();
// [Link]().setBackground([Link]);
49. GUI
import [Link].*;
import [Link].*;
public class MyFrame extends JFrame {
MyFrame(){
[Link]("This is Title"); // set title of frame
[Link](JFrame.EXIT_ON_CLOSE); //exist out ot
application
[Link](false); // prevent frame from being resized
[Link](420,420); //Set x-demension and y-demension
[Link](true); //make frame
ImageIcon image = new ImageIcon("[Link]"); // crate logoicon
[Link]([Link]()); // change icon of frame
[Link]().setBackground([Link]); // change background color
}
}
MyFrame myFrame = new MyFrame();
or
new MyFrame();
JFrame Frame = new JFrame(); // create a frame
[Link]("This is Title"); // set title of frame
[Link](JFrame.EXIT_ON_CLOSE); //exist out ot
application
[Link](false); // prevent frame from being resized
[Link](420,420); //Set x-demension and y-demension
[Link](true); //make frame
ImageIcon image = new ImageIcon("[Link]"); // crate logoicon
[Link]([Link]()); // change icon of frame
[Link]().setBackground([Link]); // change background color
// [Link]().setBackground(new Color(0, 0, 0)); or 0xFFFFFFF //
change background color customize
6. GUI intro (Graphical user interface)
String name = [Link]("Enter your name");
// [Link](null, "Hello " +name);
int age = [Link]([Link]("Enter
Your age"));
// [Link](null, "You are " +age+ " years
old");
double height =
[Link]([Link]("Enter Your height"));
// [Link](null, "You are " +height+ " cm
tall");
[Link](null, "Hello " +name);
[Link](null, "You are " +age+ " years
old");
[Link](null, "You are " +height+ " cm
tall");
Auston java
int days = 1000;
int seconds = 864_00; // one day's seconds
int lightspeed = 186000;
long distance;
long conver_seconds;
conver_seconds = seconds * days;
distance = lightspeed * conver_seconds;
[Link]("In " +days+ " there are " +conver_seconds+ " seconds");
[Link]("There are "+distance + " miles in "+ days+ " days");
double pi = 3.142;
double area;
double r = 10.8;
area = pi * ([Link](r, 2));
[Link](area);
double balance = 234567.898;
Scanner scanner = new Scanner([Link]);
[Link]("Enter \"1\" to Deposite and \"2\" to Withdraw: ");
int choice = [Link]();
[Link]("Enter amount: ");
double amount = [Link]();
switch (choice){
case 1:
balance += amount;
break;
case 2:
balance -= amount;
}
[Link]("Your balance is " +balance);