Java (Full Course)
Java (Full Course)
GUI................................................................................................................................................................... 16
Auston java....................................................................................................................................................... 17
import javax.sound.sampled.*;
import java.io.File;
import java.io.IOException;
import java.util.Scanner;
}
System.out.println("Byeee!");
47. FileReader
try {
FileReader fileReader = new FileReader("Paper.txt");
int data = fileReader.read();
while (data != -1){
System.out.print((char)data);
data = fileReader.read();
}
fileReader.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
46. FileWriter
try {
FileWriter fileWriter = new FileWriter("Paper.txt");
fileWriter.write("Thii is heading\n this is subheading");
fileWriter.append("\n(A paper by Tayzar)");
fileWriter.close();
} catch (IOException e) {
e.printStackTrace();
}
44. Exception
Scanner scanner = new Scanner(System.in);
try{
System.out.print("Enter a whole number to divide: ");
int x = scanner.nextInt();
double z = x/y;
System.out.println("The answer is " +z);
}
catch (ArithmeticException e){
System.out.println("you can't divde a zero!");
}
catch (InputMismatchException e){
System.out.println("PLEASE Enter a whole number!");
}
catch (Exception e){
System.out.println("Someting went wrong");
}
finally {
scanner.close();
}
43. Dynamic Polymorphism
Animal animal;
Scanner scanner = new Scanner(System.in);
System.out.println("What animal you want?");
System.out.print("Press 1.Dog or 2.Cat: ");
int choice = scanner.nextInt();
if (choice == 1){
animal = new Dog();
animal.speak();
}
else if (choice == 2){
animal = new Cat();
animal.speak();
}
else {
animal = new Animal();
animal.speak();
}
public class Animal {
@Override
public void speak(){
System.out.println("Dog goes *bark*");
}
}
public class Cat extends Animal{
@Override
public void speak(){
System.out.println("Cat goes *Meow*");
}
}
42. polymorphish
void go(){
}
}
public class Car extends Vehicles{
@Override
void go(){
System.out.println("This car is moving");
}
}
41. intrfaces
Fish fish = new Fish();
fish.flee();
fish.hunt();
@Override
public void flee() {
}
}
@Override
public void hunt() {
System.out.println("*It is hunting*");
}
}
public class Rabbit implements Prey {
@Override
public void flee() {
System.out.println("*this is fleeing*");
}
}
void flee();
}
public interface Predator {
void hunt();
}
System.out.println(car1);
System.out.println(car2);
System.out.println(car1.getMake());
System.out.println(car1.getMake());
System.out.println(car1.getYear());
System.out.println(car2.getMake());
System.out.println(car2.getMake());
System.out.println(car2.getYear());
}
public String getMake(){
return make;
}
public String getModel(){
return model;
}
public int getYear(){
return year;
}
39. Encapsulation
@Override
void go(){
System.out.println("This car is moving");
}
String power;
Hero(String name, int age, String power){
super(name,age);
this.power = power;
}
public String toString() {
return super.toString() + this.power + "\n";
}
}
void speak(){
System.out.println("Animal speaks");
}
}
public class dog extends Animal{
@Override
void speak(){
System.out.println("The dogs *bark*");
}
34. Inheritant
System.out.println(car.doors);
System.out.println(bicycle.pedals);
double speed;
void go(){
System.out.println("This vehicle is moving");
}
void stop(){
System.out.println("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
// System.out.println(Friends.numbersOfFriends);
Friends.displaysFriends();
Friends(String name){
this.name = name;
numbersOfFriends++;
}
static void displaysFriends(){
System.out.println("You have "+numbersOfFriends+ " friends");
}
}
garage.park(car1);
garage.park(car2);
System.out.println(refrigerator[0].name);
System.out.println(refrigerator[1].name);
System.out.println(refrigerator[2].name);
// System.out.println(food1.name);
// System.out.println(car.toString());
System.out.println(car);
public class car {
String bread;
String saucse;
String cheese;
String topping;
this.bread = bread;
this.saucse = saucse;
}
Pizza(String bread, String saucse, String cheese){
this.bread = bread;
this.saucse = saucse;
this.cheese = cheese;
}
Pizza(String bread, String saucse, String cheese, String topping){
this.bread = bread;
this.saucse = saucse;
this.cheese = cheese;
this.topping = topping;
}
}
// [Global]
Random random;
int number;
DiceRoller(){
random = new Random();
number = 0;
roll();
}
void roll(){
number = random.nextInt(6)+1;
System.out.println(number);
}
}
/*
// [Local]
DiceRoller(){
Random random = new Random();
int number = 0;
roll(random, number);
}
void roll(Random random, int number){
number = random.nextInt(6)+1;
System.out.println(number);
}
*/
/*
27. Constructors
Human human1 = new Human("Jhon", 12, 23.4);
Human human2 = new Human("Hagai", 34, 234.4);
System.out.println(human1.age);
System.out.println(human2.age);
human1.eat();
human2.drink();
String name;
int age;
double weight;
void eat(){
System.out.println(this.name +" is eating");
}
void drink(){
System.out.println(this.name+" is drinking *brup*");
}
26. objects(OOP)
myCar.drive();
myCar.brake();
24. printf
//[Coversion Characters]
// System.out.printf("%d %c %f %s %b", age, symbol, gpa, name, Male);
//[Width]
//System.out.printf("Hello %10s", name);
//[Precision]
//System.out.printf("You have %.2f", gpa);
//[flag]
System.out.printf("You have %,f", gpa);
//10f -10f -f +f 020f
add(1, 2);
add(1,2,3);
add(1,2,3,4);
}
static int add(int x, int y){
int z = x + y;
System.out.println("This is the overloaded method #1");
System.out.println(z);
return z;
}
static int add(int x, int y, int a){
int z = x + y + a;
System.out.println("This is the overloaded method #2");
System.out.println(z);
return z;
}
static int add(int x, int y, int a, int b){
int z = x + y + a + b;
System.out.println("This is the overloaded method #3");
System.out.println(z);
return z;
}
static double add(double x, double y){
double z = x + y;
System.out.println("This is the overloaded method #4");
System.out.println(z);
return z;
}
static double add(double x, double y, double a){
double z = x + y + a;
System.out.println("This is the overloaded method #5");
System.out.println(z);
return z;
}
static double add(double x, double y, double a, double b){
double z = x + y + a + b;
System.out.println("This is the overloaded method #6");
System.out.println(z);
return z;
}
}
22. Methods
add(2,4);
}
Integer a = 123;
Double d = 2.3;
Boolean b = true;
String s = "Hey";
Character c = '=';
// System.out.println(bakeryList);
// System.out.println(bakeryList.get(0));
combine
groceryList.add(productList);
groceryList.add(drinkList);
groceryList.add(bakeryList);
// System.out.println(groceryList);
System.out.println(groceryList.get(0).get(0));
System.out.println(result);
16. 2D arrays
String[][] currentListOfMedicince ={
{"Bitarmin", "Biojustsis", "Batmintin"},
{"Arenba", "Amberma", "Aquain"},
{"Cetinmin", "Cellgrow", "Cattalim"},
{"Digging", "Dulingo", "Doover"}
};
15. Arrays
subjects[0] = "Math";
subjects[1] = "Science";
subjects[2] = "Chemical";
13.for loop
12.While loop
while (name.isBlank()){
// excutes the lines of code as long as that conditons still remain true
System.out.print("Enter your name: ");
name = scanner.nextLine();
do{
// excutes the lines of code as long as that conditons still remain true
System.out.print("Enter your name: ");
name = scanner.nextLine();
}while (name.isBlank());
int temp;
Scanner scanner = new Scanner(System.in);
System.out.print("Enter your temp: ");
temp = scanner.nextInt();
System.out.println(temp);
}
else {
System.out.println("You are still in the game");
}
2. Variables
String x = "Water";
String y = "Acid";
String temp;
// x = y Acid
// y = x Water
System.out.println("x: " +x);
System.out.println("y: " +y);
4. User input
5. Experssion
// int appleSlices = 4;
// double appleSlices = 4;
// appleSlices = appleSlices + 1;
// appleSlices += 1;
// appleSlices ++; // just one
// appleSlices = appleSlices / 3;
// System.out.println(appleSlices);
7. Math class
double a = 23.45;
double b = -30.0;
double c = Math.sqrt(a);
//max, min, abs, sqrt, pow, round, ceil, floor
System.out.println(c);
double x,y,z;
Scanner scanner = new Scanner(System.in);
System.out.print("Enter the side x: ");
x = scanner.nextDouble();
System.out.print("Enter the side y: ");
y = scanner.nextDouble();
// hypotenuse formula c = squaroot of a square + b square
z = Math.sqrt((x*x)+(y*y));
System.out.println("The hypotenuse is: " +z);
scanner.close();
8.Random numbers
9. if statements
int typesOfGuess = 1;
// Scanner scanner = new Scanner(System.in);
// System.out.println("Enter between 1 to 3");
// System.out.println("Enter your number: ");
if (typesOfGuess == 1){
System.out.println("You are a VIP guess!");
}
else if(typesOfGuess == 2){
System.out.println("You are an entertainer.");
}
else if(typesOfGuess == 3){
System.out.println("You are just a normal guess.");
}
else {
System.out.println("You are not allowed to go in.");
}
10.Switch statments
int gpa = 3;
switch (gpa) {
case 2:
System.out.println("You did normal!");
break;
case 3:
System.out.println("You did average!");
break;
case 4:
System.out.println("You did awesome!");
break;
case 5:
System.out.println("You did ellcentent!");
break;
default:
System.out.println("Keep it up!");
}
GUI
new mouselistener();
import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
JLabel label;
ImageIcon a;
ImageIcon b;
ImageIcon c;
ImageIcon d;
mouselistener() {
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(500, 500);
this.setLayout(new FlowLayout());
label.setIcon(a);
this.add(label);
this.pack();
this.setLocationRelativeTo(null);
this.setVisible(true);
}
@Override
public void mouseClicked(MouseEvent e) {
@Override
public void mousePressed(MouseEvent e) {
label.setIcon(b);
@Override
public void mouseReleased(MouseEvent e) {
label.setIcon(c);
@Override
public void mouseEntered(MouseEvent e) {
label.setIcon(d);
@Override
public void mouseExited(MouseEvent e) {
label.setIcon(a);
}
}
JLabel label;
mouselistener(){
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(500, 500);
this.setLayout(null);
this.add(label);
this.setVisible(true);
}
@Override
public void mouseClicked(MouseEvent e) {
//System.out.println("You clicked the mouse ");
}
@Override
public void mousePressed(MouseEvent e) {
System.out.println("You pressed the mouse ");
label.setBackground(Color.black);
}
@Override
public void mouseReleased(MouseEvent e) {
System.out.println("You released the mouse ");
label.setBackground(Color.blue);
@Override
public void mouseEntered(MouseEvent e) {
System.out.println("You entered the component ");
label.setBackground(Color.yellow);
}
@Override
public void mouseExited(MouseEvent e) {
System.out.println("You existed the component ");
label.setBackground(Color.red);
}
}
new keyListener();
import javax.swing.*;
import java.awt.*;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
JLabel label;
ImageIcon icon;
keyListener(){
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(500, 500);
this.addKeyListener(this);
this.setLayout(null);
this.getContentPane().setBackground(Color.black);
this.add(label);
this.setVisible(true);
}
@Override
public void keyTyped(KeyEvent e) {
switch (e.getKeyChar()){
case 'a' :
label.setLocation(label.getX()-10, label.getY());
break;
case 'w' :
label.setLocation(label.getX(), label.getY()-10);
break;
case 's' :
label.setLocation(label.getX()+10, label.getY());
break;
case 'd' :
label.setLocation(label.getX(), label.getY()+10);
break;
}
@Override
public void keyPressed(KeyEvent e) {
switch (e.getKeyCode()){
case 37 :
label.setLocation(label.getX()-10, label.getY());
break;
case 38 :
label.setLocation(label.getX(), label.getY()-10);
break;
case 39 :
label.setLocation(label.getX()+10, label.getY());
break;
case 40 :
label.setLocation(label.getX(), label.getY()+10);
break;
}
}
@Override
public void keyReleased(KeyEvent e) {
}
}
new colorselecter();
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
JButton button;
JLabel label;
colorselecter() {
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLayout(new FlowLayout());
this.add(label);
this.add(button);
this.pack();
this.setVisible(true);
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == button){
label.setForeground(color);
// label.setBackground(color);
}
}
}
new fileselecter();
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
JButton button;
fileselecter(){
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLayout(new FlowLayout());
button = new JButton("Select file");
button.addActionListener(this);
this.add(button);
this.pack();
this.setVisible(true);
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == button){
JFileChooser fileChooser = new JFileChooser();
fileChooser.setCurrentDirectory(new File("."));
if (respones == fileChooser.APPROVE_OPTION){
System.out.println(file);
}
}
}
}
new menu();
import javax.swing.*;
import java.awt.event.*;
import java.awt.FlowLayout;
JMenuBar menuBar;
JMenu fileMenu;
JMenu editMenu;
JMenu helpMenu;
JMenuItem loadItem;
JMenuItem saveItem;
JMenuItem exitItem;
ImageIcon saveIcon;
ImageIcon loadIcon;
ImageIcon existIcon;
menu(){
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(500, 500);
this.setLayout(new FlowLayout());
loadItem.addActionListener(this);
saveItem.addActionListener(this);
exitItem.addActionListener(this);
loadItem.setIcon(loadIcon);
saveItem.setIcon(saveIcon);
exitItem.setIcon(existIcon);
fileMenu.setMnemonic(KeyEvent.VK_F); // Alt + f to file
editMenu.setMnemonic(KeyEvent.VK_E); // Alt + e to file
helpMenu.setMnemonic(KeyEvent.VK_H); // Alt + h to file
saveItem.setMnemonic(KeyEvent.VK_S); // S to save
loadItem.setMnemonic(KeyEvent.VK_L); // L to load
exitItem.setMnemonic(KeyEvent.VK_E); //E tp to exist
fileMenu.add(loadItem);
fileMenu.add(saveItem);
fileMenu.add(exitItem);
menuBar.add(fileMenu);
menuBar.add(editMenu);
menuBar.add(helpMenu);
this.setJMenuBar(menuBar);
this.setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == loadItem){
System.out.println("Loaded file");
}
if (e.getSource() == exitItem){
System.exit(0);
}
if (e.getSource() == saveItem){
System.out.println("saved file");
}
}
}
new progressbar();
import java.awt.*;
import javax.swing.*;
progressbar(){
bar.setValue(0);
bar.setBounds(0,0,420, 50);
bar.setStringPainted(true);
bar.setFont(new Font("MV Boli", Font.BOLD, 25));
bar.setForeground(Color.red);
bar.setBackground(Color.BLACK);
frame.add(bar);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(420, 420);
frame.setLayout(null);
frame.setVisible(true);
fill();
}
public void fill(){
}
63. Slider
new Slider();
import javax.swing.event.*;
import javax.swing.*;
import java.awt.*;
Slider(){
slider.setPaintTicks(true);
slider.setMinorTickSpacing(10);
slider.setPaintTrack(true);
slider.setMajorTickSpacing(25);
slider.setPaintLabels(true);
slider.setFont(new Font("MV Boli", Font.PLAIN, 15));
label.setFont(new Font("MV Boli", Font.PLAIN, 25));
//slider.setOrientation(SwingConstants.HORIZONTAL);
slider.setOrientation(SwingConstants.VERTICAL);
slider.addChangeListener(this);
panel.add(slider);
panel.add(label);
frame.add(panel);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(500, 500);
frame.setVisible(true);
}
@Override
public void stateChanged(ChangeEvent e) {
}
}
62.Combo BOX
new combobox();
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
JComboBox comboBox;
combobox() {
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLayout(new FlowLayout());
this.add(comboBox);
this.pack();
this.setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == comboBox)
{
System.out.println(comboBox.getSelectedItem());
}
}
}
new RadioButton();
JRadioButton pizzaButton;
JRadioButton bumgerButton;
JRadioButton hotdogButton;
ImageIcon pizzaIcon;
ImageIcon burgerIcon;
ImageIcon hotdogIcon;
RadioButton(){
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLayout(new FlowLayout());
pizzaButton.addActionListener(this);
bumgerButton.addActionListener(this);
hotdogButton.addActionListener(this);
pizzaButton.setIcon(pizzaIcon);
bumgerButton.setIcon(burgerIcon);
hotdogButton.setIcon(hotdogIcon);
this.add(pizzaButton);
this.add(bumgerButton);
this.add(hotdogButton);
this.pack();
this.setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == pizzaButton){
System.out.println("You order pizza");
}
else if (e.getSource()== bumgerButton){
System.out.println("You order burger");
}
else if(e.getSource() == hotdogButton){
System.out.println("You order hotdog");
}
}
}
new CheckBox();
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class CheckBox extends JFrame implements ActionListener {
JButton button;
JCheckBox checkBox;
CheckBox(){
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLayout(new FlowLayout());
this.add(button);
this.add(checkBox);
this.pack();
this.setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == button){
System.out.println(checkBox.isSelected());
}
}
}
new TextField();
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class TextField extends JFrame implements ActionListener {
JButton button;
JTextField textField;
TextField(){
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLayout(new FlowLayout());
this.add(button);
this.add(textField);
this.pack();
this.setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == button){
// button.setEnabled(false);
System.out.println("Hello " +textField.getText());
}
}
}
58.Joption Pane
// JOptionPane.showMessageDialog(null, "This is Non-display", "Title",
JOptionPane.PLAIN_MESSAGE );
// JOptionPane.showMessageDialog(null, "This is Non-display", "Title",
JOptionPane.INFORMATION_MESSAGE );
// JOptionPane.showMessageDialog(null, "This is Non-display", "Title",
JOptionPane.QUESTION_MESSAGE );
//JOptionPane.showMessageDialog(null, "This is Non-display", "Title",
JOptionPane.WARNING_MESSAGE );
// JOptionPane.showMessageDialog(null, "This is Non-display", "Title",
JOptionPane.ERROR_MESSAGE );
// int answer = JOptionPane.showConfirmDialog(null, "What is your fucking name
you little bitch?", "Title", JOptionPane.YES_NO_CANCEL_OPTION );
// System.out.println(JOptionPane.showConfirmDialog(null, "What is your fucking
name you little bitch?", "Title", JOptionPane.YES_NO_CANCEL_OPTION ));
// String name = JOptionPane.showInputDialog("What is your name?: ");
// System.out.println("Hello "+name);
JOptionPane.showOptionDialog(
null,
"I am going to fucking kill you",
"Answer:",
JOptionPane.YES_NO_CANCEL_OPTION,
JOptionPane.INFORMATION_MESSAGE,
icon,
respones,
0);
}
new LanchPage();
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(400, 400);
frame.setLayout(null);
frame.add(button);
frame.setVisible(true);
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource()== button){
frame.dispose();
NewWindow myWindow = new NewWindow();
}
}
}
NewWindow(){
frame.add(label);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(400, 400);
frame.setLayout(null);
frame.setVisible(true);
}
}
56.Layered Pane
layeredPane.add(label1, JLayeredPane.DEFAULT_LAYER);
layeredPane.add(label2, Integer.valueOf(2));
layeredPane.add(label3, JLayeredPane.DRAG_LAYER);
frame.setVisible(true);
panel1.add(new Button("1"));
panel1.add(new Button("2"));
panel1.add(new Button("3"));
panel1.add(new Button("4"));
panel1.add(new Button("5"));
panel1.add(new Button("6"));
panel1.add(new Button("7"));
panel1.add(new Button("8"));
panel1.add(new Button("9"));
frame.add(panel1);
frame.setVisible(true);
panel1.setBackground(Color.lightGray);
panel2.setBackground(Color.BLACK);
panel3.setBackground(Color.BLUE);
panel4.setBackground(Color.GREEN);
panel5.setBackground(Color.YELLOW);
//---------------------sub panles------------------------------
panel6.setBackground(Color.RED);
panel7.setBackground(Color.MAGENTA);
panel8.setBackground(Color.DARK_GRAY);
panel9.setBackground(Color.PINK);
panel10.setBackground(Color.WHITE);
panel5.setLayout(new BorderLayout());
panel5.add(panel6,BorderLayout.NORTH);
panel5.add(panel7,BorderLayout.WEST);
panel5.add(panel8,BorderLayout.EAST);
panel5.add(panel9,BorderLayout.SOUTH);
panel5.add(panel10,BorderLayout.CENTER);
//-----------------sub panles-----------------------------
frame.add(panel1,BorderLayout.NORTH);
frame.add(panel2,BorderLayout.WEST);
frame.add(panel3,BorderLayout.EAST);
frame.add(panel4,BorderLayout.SOUTH);
frame.add(panel5,BorderLayout.CENTER);
52. buttons
new subFram();
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
JButton button;
JLabel label;
ImageIcon icon;
ImageIcon icon2;
subFram(){
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLayout(null);
this.setSize(800, 800);
this.setVisible(true);
this.add(button);
this.add(label);
}
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == button){
label.setVisible(true);
---------------------------------------------------------------------
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLayout(null);
this.setSize(800, 800);
this.setVisible(true);
this.add(button);
}
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == button){
System.out.println("Boo");
button.setEnabled(false);
}
}
-----------------------------------------------------------------------------------------------
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
JButton button;
ImageIcon icon;
JLabel label;
subFram(){
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(500, 500);
this.setLayout(null);
this.setVisible(true);
this.add(button);
this.add(label);
}
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == button){
label.setVisible(true);
}
}
51.panels
50. labels
Frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// Frame.setSize(500,500);
// Frame.setLayout(null);
Frame.setVisible(true);
Frame.add(label);
Frame.pack();
// Frame.getContentPane().setBackground(Color.BLACK);
49. GUI
import javax.swing.*;
import java.awt.*;
MyFrame(){
double height =
Double.parseDouble(JOptionPane.showInputDialog("Enter Your height"));
// JOptionPane.showMessageDialog(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;
switch (choice){
case 1:
balance += amount;
break;
case 2:
balance -= amount;
}