creating the array is so clever! at first i thought it was a little redundant since you could this and save one step frame.add(new JLabel(new ImageIcon("src\\cards\\"+i+".png"))); but then I realized that creating and filling the array, you can use the array positions as "names" for the objects so you can correct a specific Jlabel later. beautiful!
This may just be me... but I feel like this is like watching a really entertaining gaming video. It might be the colors, idk. Thx for the great explanation! :P
i think using this for swing is not the best idea as naming the object has flexibilty to use them for styling and other action and mouse listners etc.. but while programing this can be used here and there to remove the redundancy and unnecessory codes.
This is also likely more efficient in memory as you don't have a object in multiple places in memory I.E. Bunny bunny = new Bunny(); --- adds object to memory Pet pet = new Pet(bunny); --- creates another object in memory and stores the location of bunny as well (I think?) vs Pet pet = new Pet(new Bunny()); -- the Bunny no longer exists afterwards and doesn't need a pointer to it so all the info is in pet and is still accessible PLEASE DO NOT TAKE THIS AS PROFESSIONAL ADVISE -- this is my personal interpretation of the benefits and I could be WRONG, if so please make me aware. Either way it still saves lines of code and effort.
AOA, Man you are under-rated. You really should have more subs than you already have (by the quality of your work). Also, let's say I want to download your videos on MP4 quality, how may I so that? (Legally)
@@BroCodez wow Google sure knows what is spam and what is not. Wondering where all the 200 IQ algorithm experts went. Also AOA stands for Assalam O Alaikum which is Arabic for may you live in peace (just if you were wondering). AOA again.
But isn't it considered bad practice to just skip naming variables to make readable code? I've been forcing myself to do so thinking it was a better idea, but I didn't know not naming objects was actually considered to be a valid method...
holy crap, that would be awesome. You could write a sub-program for each card for each card's effects. I'm now imagining all the work that went into a game like Magic The Gathering Online
import java.util.Scanner; class AE extends Exception { AE(String m) { super(m); } } class Main { public static void main(String[] args) { Scanner s = new Scanner(System.in); int age; age = s.nextInt(); try { if (age < 18) { throw new AE("You are not 18"); } else { System.out.println("You are 18+"); } } catch (AE e) { System.out.println("An error occurred: " + e.getMessage()); } } } other way around
import java.awt.*;
import java.util.*;
import javax.swing.*;
public class Main {
public static void main(String[] args) {
JFrame frame = new JFrame();
ArrayList deck = new ArrayList();
/*
ImageIcon AC = new ImageIcon("src\\cards\\1.png");
JLabel AClabel = new JLabel(AC);
deck.add(AClabel);
ImageIcon TwoC = new ImageIcon("src\\cards\\2.png");
JLabel TwoClabel = new JLabel(TwoC);
deck.add(TwoClabel);
... repeat for all 52 cards :(
*/
for(int i =1;i
"Hard"way to add objects
import java.awt.*;
import java.util.*;
import javax.swing.*;
public class Main
{
public static void main (String[]args)
{
JFrame frame = new JFrame ();
ArrayList < JLabel > deck = new ArrayList < JLabel > ();
ImageIcon AC = new ImageIcon ("src\\cards\\1.png");
JLabel AClabel = new JLabel (AC);
deck.add (AClabel);
ImageIcon twoC = new ImageIcon ("src\\cards\\2.png");
JLabel twoClabel = new JLabel (twoC);
deck.add (twoClabel);
frame.add (deck.get (0));
frame.add (deck.get (1));
frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
frame.setSize (380, 380);
frame.setLayout (new FlowLayout ());
frame.setVisible (true);
}
}
______________________________
SIMPLE WAY
import java.awt.*;
import java.util.*;
import javax.swing.*;
public class Main
{
public static void main (String[]args)
{
JFrame frame = new JFrame ();
ArrayList < JLabel > deck = new ArrayList < JLabel > ();
for (int i = 1; i
creating the array is so clever! at first i thought it was a little redundant since you could this and save one step
frame.add(new JLabel(new ImageIcon("src\\cards\\"+i+".png")));
but then I realized that creating and filling the array, you can use the array positions as "names" for the objects so you can correct a specific Jlabel later.
beautiful!
Not what I was looking for. But something I never thought of doing and glad to know now.
No words to tell How much u'r helping me
This may just be me... but I feel like this is like watching a really entertaining gaming video. It might be the colors, idk.
Thx for the great explanation! :P
Line NO.10. We don’t need to type two times JLabel in if you we are using JDK 8 or above.
Great vid as usual!
thanks man!
Another great video. Thanks a lot. Happy New Year and wishing you all the best.
Great
Nice
i think using this for swing is not the best idea as naming the object has flexibilty to use them for styling and other action and mouse listners etc.. but while programing this can be used here and there to remove the redundancy and unnecessory codes.
Best of the best
great tutorial
Great♥
Very cool video :) Now that I think about it, I probably could have been more efficient by using this method in one of my prior projects
Get used to that. As you gain new skills, you find more shortcuts to things you have coded previously lol
Coolies! Thank you for the lesson.
This is also likely more efficient in memory as you don't have a object in multiple places in memory I.E.
Bunny bunny = new Bunny(); --- adds object to memory
Pet pet = new Pet(bunny); --- creates another object in memory and stores the location of bunny as well (I think?)
vs
Pet pet = new Pet(new Bunny()); -- the Bunny no longer exists afterwards and doesn't need a pointer to it so all the info is in pet and is still accessible
PLEASE DO NOT TAKE THIS AS PROFESSIONAL ADVISE -- this is my personal interpretation of the benefits and I could be WRONG, if so please make me aware. Either way it still saves lines of code and effort.
helpful, thanks
Legend as always
This is to defeat the EVIL TH-cam ALGORITHM.
GO, BRO!!
Where can i find pictures Like u have BRO ?
Can you make video your whole day as Programmer ?
jAVAFX TUTURIAL PLEASE
omg . Just 3 lines of code , thanks !
thanks bro
AOA, Man you are under-rated. You really should have more subs than you already have (by the quality of your work). Also, let's say I want to download your videos on MP4 quality, how may I so that? (Legally)
You're comment ended up in my spam folder lol. Thank you. However I am not sure how to download TH-cam videos
@@BroCodez wow Google sure knows what is spam and what is not. Wondering where all the 200 IQ algorithm experts went. Also AOA stands for Assalam O Alaikum which is Arabic for may you live in peace (just if you were wondering). AOA again.
good tuto
thanks for watching Sidof
Thanks
this is genius
We're cooking with petrol now!!
But isn't it considered bad practice to just skip naming variables to make readable code?
I've been forcing myself to do so thinking it was a better idea, but I didn't know not naming objects was actually considered to be a valid method...
🤩
Cool!
thanks again bro
Can I know where are you from??
(Not intending to be bad)
For me, I am from 🇬🇧🇬🇧
@@BroCodez nice to meet you bud:)
@@BroCodez love your java tutorials:)
Ly bro 7
Danke
hi :)
I'm so lazy to continue. HELP :(
I don’t know how to download these pictures so I can’t type same project with you.
I made them myself. This is more of a demonstration, but any pictures or images could work
holy crap, that would be awesome. You could write a sub-program for each card for each card's effects. I'm now imagining all the work that went into a game like Magic The Gathering Online
@@VXFluff ayy bro. u made good music. naisu
import java.util.Scanner;
class AE extends Exception {
AE(String m) {
super(m);
}
}
class Main {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int age;
age = s.nextInt();
try {
if (age < 18) {
throw new AE("You are not 18");
} else {
System.out.println("You are 18+");
}
} catch (AE e) {
System.out.println("An error occurred: " + e.getMessage());
}
}
}
other way around
Thanks