Jump to content

Philosobyte

Member
  • Posts

    596
  • Joined

  • Last visited

Reputation Activity

  1. Like
    Philosobyte got a reaction from sufyan98 in Cheap-ish audio interface ( Under £80 )   
    TL;DR - an audio interface has an A/D converter and a preamp. The preamp boosts the mic's weak analog signal, and the A/D converter converts that signal into a digital signal so that the computer can interpret it. (Computers can't interpret analog signals). 
     
    Long version:
    To understand that, you'll need a crash course in analog/digital signals.
    First, understand that sounds are continuous, mechanical waves like these: 
     
     
     
    These mechanical waves can be represented with an electrical signal in two ways: analog and digital. 
    With analog signals, sound waves are translated into an electric current with continuously varying voltage. If you see the bottom of the wave as black and the top of the wave as white, there are an infinite number of shades of gray between them because the wave is continuous. The same goes for the horizontal direction as well: there are infinitely many horizontal positions between one peak and the next peak.
     
    The problem is, a digital signal is represented with black and white 1s and 0s: there's no gray. Therefore, in order to represent sound, a converter has to "sample" the sound wave like so:
     
     
    Where the continuous wave is broken up into those blue dots, and those blue dots are translated into 1s and 0s to form 65,536 possible shades of gray for 16-bit audio, and 16.7m shades for 24-bit audio. And then for horizontal positions, there are 44,100 dots recorded every second in a 44.1kHz sampling rate, and 96,000 dots for a 96kHz sampling rate, etc.
     
    So what's the difference between analog and digital signals? Analog is a continuous stream of electricity with minute changes in voltage, while digital is a pulsating stream of 1s and 0s. 
     
    Obviously these two types of signals are incompatible, and we have a problem: microphones record sound in analog, while computers process all their data digitally. This is where audio interfaces come in. An audio interface has an "Analog to Digital" converter, or A/D converter, which samples the microphone's analog signal and turns it into a digital signal to send to the computer so the computer can understand it.
     
    We have another problem, though. Microphones use extremely thin diaphragms or voice coils to collect sound, and the analog signal is at a very low level. This weak signal isn't very useful for A/D converters, so audio interfaces have "preamps" which amplify the signal, adding gain so that it's loud enough to be useful. 
     
     
  2. Like
    Philosobyte reacted to ThinkWithPortals in Most photorealistic games of 2016/2015   
    Everybody's Gone To The Rapture is by far the most realistic-looking game I've yet seen. Just look at some screenshots (warning, big images ahead):
     
     
  3. Like
    Philosobyte reacted to mathijs727 in Most photorealistic games of 2016/2015   
    Although I havent played the game myself, the game that impressed me the most is The Division ( its technically a 2015 game):
     
  4. Like
    Philosobyte reacted to Railgun in Most photorealistic games of 2016/2015   
    Minecraft
    Anything recently made by Dice (Battlefront, Battlefield 1)
    The Rapture
     
  5. Informative
    Philosobyte reacted to Enderman in New info released on the Calyos fanless PCs   
    So a few months ago I contacted them to see if they were selling just the cooling system and case, and the reply was no because it would be too complicated for a user to set up themselves.
    They also told me that they were preparing a line of systems at different price points around $1k-$5k euros.
     
    Today I got an email with a lot more information, including THREE OTHER fanless case+cooling designs!
    Also:
    Here is all the info you can read for yourself (this information cannot be found on their website yet, so it's a pretty exclusive first look )
     



     
    Source: my email
    Website: http://www.calyos-tm.com/calyos-fanless-pc-workstation/
     
    Any guesses on what the other cases are going to be? Maybe more from Lian-Li?
  6. Agree
    Philosobyte reacted to roughavoc in Microphone.... :)   
    Did anyone actually read OPs post? You are all recommending microphones that will pick up keyboard and background noises super loud.
    You want a Super Cardioid or a Dynamic microphone:
    Q1U ATR2100
  7. Funny
    Philosobyte reacted to SSL in Flat vs curved studio monitor placement   
    How hard would it be to try and find out, on a scale of 1 to Easy?
  8. Agree
    Philosobyte reacted to PlutoNZL in Rotating Matrix - Java   
    Can you give a sample input, expected output, and actual output.
    I ran your method with this input:
     1  2  3  4 
     5  6  7  8 
     9 10 11 12 
    13 14 15 16 
    And got this output:
     4  8 12 16 
     3  7 11 15 
     2  6 10 14 
     1  5  9 13 
     
    Is this not correct?
  9. Informative
    Philosobyte got a reaction from 15-211-186 in Trigonometry word problem!   
    If you use secant, then it would be sec 30* = x/(unlabeled side)
    and that's unsolvable because you have two variables.
     
    Secant and cosine deal with the side which touches the angle, while cosecant and sine deal with the side opposite of the angle. The 4 in the triangle is on the opposite side, so you would have to use cosecant or sine. 
     
    Another way to solve number 2 would be to use the 30 60 90 special right triangle. Any right triangle with the angle 30 must also have the angle 60, and vice versa. If the shortest side opposite 30 degrees is x, then the hypotenuse is 2x. Since in this case x = 4, the hypotenuse is 2(4) = 8.
    (The leftover side is sqrt(3) * x, so in case you're wondering, the remaining side is 6.928). 
    Glad I could help. 
  10. Agree
    Philosobyte got a reaction from flowalex in which mic?   
    XLR microphones are not inherently better than USB microphones, but they often are better because of price range differences. 
    XLR microphones transmit an analog signal through an XLR cable. That signal has to be amplified by a preamp and converted by analog to digital converters (A/D converters) into a digital signal which the computer can understand. 
    USB microphones have a preamp and A/D converters built in. That's why they can output their data in a digital USB format. 
     
    The implications of this are that USB microphones are limited by the quality of their internal preamp and A/D converters, while XLR microphones don't have that bottleneck - with XLR microphones, you choose which preamps and converters to use and you can upgrade them later. 
     
    Since XLR microphones are usually paired with good preamps and converters, such as in a Focusrite Scarlett 2i2 or Steinberg UR22 audio interface, they tend to have better sound than USB mics which are usually paired with lesser preamps/converters. 
     
    This also means that when you buy an XLR microphone, you'll have to factor in the price of an audio interface and an XLR cable. Good audio interfaces start at around $100 (Mackie Blackjack) and you can get good XLR cables from Monoprice. 
  11. Informative
    Philosobyte got a reaction from seduce_me in which mic?   
    XLR microphones are not inherently better than USB microphones, but they often are better because of price range differences. 
    XLR microphones transmit an analog signal through an XLR cable. That signal has to be amplified by a preamp and converted by analog to digital converters (A/D converters) into a digital signal which the computer can understand. 
    USB microphones have a preamp and A/D converters built in. That's why they can output their data in a digital USB format. 
     
    The implications of this are that USB microphones are limited by the quality of their internal preamp and A/D converters, while XLR microphones don't have that bottleneck - with XLR microphones, you choose which preamps and converters to use and you can upgrade them later. 
     
    Since XLR microphones are usually paired with good preamps and converters, such as in a Focusrite Scarlett 2i2 or Steinberg UR22 audio interface, they tend to have better sound than USB mics which are usually paired with lesser preamps/converters. 
     
    This also means that when you buy an XLR microphone, you'll have to factor in the price of an audio interface and an XLR cable. Good audio interfaces start at around $100 (Mackie Blackjack) and you can get good XLR cables from Monoprice. 
  12. Informative
    Philosobyte got a reaction from Cvdasfg in which mic?   
    XLR microphones are not inherently better than USB microphones, but they often are better because of price range differences. 
    XLR microphones transmit an analog signal through an XLR cable. That signal has to be amplified by a preamp and converted by analog to digital converters (A/D converters) into a digital signal which the computer can understand. 
    USB microphones have a preamp and A/D converters built in. That's why they can output their data in a digital USB format. 
     
    The implications of this are that USB microphones are limited by the quality of their internal preamp and A/D converters, while XLR microphones don't have that bottleneck - with XLR microphones, you choose which preamps and converters to use and you can upgrade them later. 
     
    Since XLR microphones are usually paired with good preamps and converters, such as in a Focusrite Scarlett 2i2 or Steinberg UR22 audio interface, they tend to have better sound than USB mics which are usually paired with lesser preamps/converters. 
     
    This also means that when you buy an XLR microphone, you'll have to factor in the price of an audio interface and an XLR cable. Good audio interfaces start at around $100 (Mackie Blackjack) and you can get good XLR cables from Monoprice. 
  13. Like
    Philosobyte reacted to Cvdasfg in which mic?   
    Thank you very much! That is super helpful.
  14. Like
    Philosobyte reacted to fizzlesticks in Here we go again...   
    http://www.infoarena.ro/problema/strabunica
  15. Agree
    Philosobyte reacted to Bacon8tor in Know Java. Want to learn C++   
    I agree with everyone, start from the beginning I have taught myself several languages, and although it is repetitive I always sit through the same boring stuff but its that one little difference that if you skip it, is gonna keep you scratching your head for hours, then realize it was something small. 
     
    I use Visual Studios for all my C++ seems to do the job quite well, C++ is one of my favorite languages, syntactically very easy to read/write at least to me.....unlike my relationship with java.   
  16. Informative
    Philosobyte got a reaction from Claryn in non-static method cannot be referenced from a static context   
    I explained this somewhat in your other thread. 
     
    The problem here is you're not understanding the most important, foundational concept in OOP. And that's the difference between a class and an object. 
     
    A class is a definition of something, and an object is an instance of something. Classes can only use class methods, and not instance methods. meanwhile, objects can use both class methods and instance methods (but in my opinion should stick with using only instance methods). 
     
     For example, let's say we have this class and these objects:
     
    class Human: the definition of a certain species of bipedal organism which has high intelligence and refined motor skills. 
    objects Mary, Jane, and Watson: each of these three objects is an instance of Human. Each of these objects are created from the definition Human. 

    These two types are not interchangeable - neither in real life nor in Java. There are going to be methods which can only be carried out by the Human definition (or the "entire Human race") and there are methods which can only be carried out by individual humans. This is seen in the following example code. 
     
    public class Human { //1 - class variables (also known as static variables) static double averageHeight = 177.8; static double averageWeight = 141.53; static double maxRunningSpeed = 44.2; static long populationCount = 7000000000L; //2 - instance variables double height; double weight; double runningSpeed; String name; public Human(String name, double height, double weight, double runningSpeed) { this.name = name; this.height = height; this.weight = weight; this.runningSpeed = runningSpeed; } //3 - instance method public void run() { System.out.println(name + " is running at " + runningSpeed + " km/hr."); } //4 - class method (also known as static method) public static void goThroughExtinction() { populationCount = 0; System.out.println("Oh noes! It appears that the human race is no more."); } } public class Main { public static void main(String[] args) { Human Mary = new Human("Mary", 163, 156, 13); Human Jane = new Human("Jane", 166, 141, 19); Human Watson = new Human("Watson", 172, 185, 32); Human.run(); //5 - Static context error Watson.run(); Human.goThroughExtinction(); Mary.goThroughExtinction(); //6 - no error, but avoid this } } 1: Class variables apply to not any one object in particular, but all objects. In this case, the average height, weight, and top running speed apply to the entire Human species.
     
    2: Instance variables apply to a single object and do not necessarily represent the class. In this case, a single person's height and weight doesn't represent the height and weight of the entire Human species.
     
    3 and 5: An instance method is an action which can only be carried out by an individual object, not a class. You can say that a single person such as Watson ran at a speed of 32 km/hr, but it doesn't make sense to say "the entire human species ran at a speed of 32 km/hr." The entire human species isn't a thing that can run; only members of the human species can run. That's why you're getting a static context error. You're trying to make a class execute an instance method like I'm trying to make the human species run, and that isn't possible.
     
    4 and 6. A class method is an action which should only be carried out by the class, not the object. The entire human species can go through extinction and die off, but it doesn't make sense to say "Mary went through extinction." A single person can't go "extinct." Despite this, Java allows you to use an object to execute a class method. So even though it doesn't make sense to say that Mary went through extinction, Java allows you to do it. 
     
    -------------------------------------------------------------------------------
     
    So how does this apply to you? Well, first of all, what I just explained is the entire point of Object-Oriented Programming (OOP) languages such as Java. If you don't completely understand this concept, you won't be progressing very far in Java. 
     
    Second of all, points 3 and 5 explain the error you described in your original post. If you consider that
     
    1. classes can't execute instance methods
    2. playGame is a class
    3. #startNewGame is an instance method
     
    it follows logically that playGame can't execute #startNewGame. That line of code in your original post won't work. Instead, you have to create a playGame, like this:
    playGame game = new playGame(); game.startNewGame(); In this case game is an object. Since instance methods are meant to be used with objects, you won't get an error here. 
     
    In my opinion, though your overall class/method structure is convoluted and doesn't make sense OOP-wise. A class should be a definition, a "class" of objects, while a method should be an action, a thing you can do. Your structure does not follow this principle because one of your classes is named "play game," which is an action instead of a definition. 
  17. Informative
    Philosobyte got a reaction from Zonus in Alternatives to Samson Meteor and Meteorite?   
    It still sounds excellent with only moderate sibilance and not much lost bass (actually sounds like increased upper bass - not boomy). However, at a normal speaking volume I have to set the Meteor's volume to 80%, and there will be noise. The noise is low enough that for Skype and gaming use, no one will really notice it unless they listen for it. However, it might not be ideal for YouTube use because audio compression will increase the noise floor even further. For Youtube, you should keep the microphone closer to you. 
     
    Try to keep the microphone relatively vertical when it is a meter away from you. Or if you're going to tilt the microphone significantly, make sure it's standing on something absorbent like cloth instead of wood or glass or plastic. At a meter away with a strong horizontal tilt, reflections from hard surfaces will add a boxy sound to your voice.
     
     
  18. Agree
    Philosobyte reacted to don_svetlio in Uni Programming Laptop   
    Dell Inspiron 7559
  19. Agree
    Philosobyte got a reaction from elpiop in non-static method cannot be referenced from a static context   
    I explained this somewhat in your other thread. 
     
    The problem here is you're not understanding the most important, foundational concept in OOP. And that's the difference between a class and an object. 
     
    A class is a definition of something, and an object is an instance of something. Classes can only use class methods, and not instance methods. meanwhile, objects can use both class methods and instance methods (but in my opinion should stick with using only instance methods). 
     
     For example, let's say we have this class and these objects:
     
    class Human: the definition of a certain species of bipedal organism which has high intelligence and refined motor skills. 
    objects Mary, Jane, and Watson: each of these three objects is an instance of Human. Each of these objects are created from the definition Human. 

    These two types are not interchangeable - neither in real life nor in Java. There are going to be methods which can only be carried out by the Human definition (or the "entire Human race") and there are methods which can only be carried out by individual humans. This is seen in the following example code. 
     
    public class Human { //1 - class variables (also known as static variables) static double averageHeight = 177.8; static double averageWeight = 141.53; static double maxRunningSpeed = 44.2; static long populationCount = 7000000000L; //2 - instance variables double height; double weight; double runningSpeed; String name; public Human(String name, double height, double weight, double runningSpeed) { this.name = name; this.height = height; this.weight = weight; this.runningSpeed = runningSpeed; } //3 - instance method public void run() { System.out.println(name + " is running at " + runningSpeed + " km/hr."); } //4 - class method (also known as static method) public static void goThroughExtinction() { populationCount = 0; System.out.println("Oh noes! It appears that the human race is no more."); } } public class Main { public static void main(String[] args) { Human Mary = new Human("Mary", 163, 156, 13); Human Jane = new Human("Jane", 166, 141, 19); Human Watson = new Human("Watson", 172, 185, 32); Human.run(); //5 - Static context error Watson.run(); Human.goThroughExtinction(); Mary.goThroughExtinction(); //6 - no error, but avoid this } } 1: Class variables apply to not any one object in particular, but all objects. In this case, the average height, weight, and top running speed apply to the entire Human species.
     
    2: Instance variables apply to a single object and do not necessarily represent the class. In this case, a single person's height and weight doesn't represent the height and weight of the entire Human species.
     
    3 and 5: An instance method is an action which can only be carried out by an individual object, not a class. You can say that a single person such as Watson ran at a speed of 32 km/hr, but it doesn't make sense to say "the entire human species ran at a speed of 32 km/hr." The entire human species isn't a thing that can run; only members of the human species can run. That's why you're getting a static context error. You're trying to make a class execute an instance method like I'm trying to make the human species run, and that isn't possible.
     
    4 and 6. A class method is an action which should only be carried out by the class, not the object. The entire human species can go through extinction and die off, but it doesn't make sense to say "Mary went through extinction." A single person can't go "extinct." Despite this, Java allows you to use an object to execute a class method. So even though it doesn't make sense to say that Mary went through extinction, Java allows you to do it. 
     
    -------------------------------------------------------------------------------
     
    So how does this apply to you? Well, first of all, what I just explained is the entire point of Object-Oriented Programming (OOP) languages such as Java. If you don't completely understand this concept, you won't be progressing very far in Java. 
     
    Second of all, points 3 and 5 explain the error you described in your original post. If you consider that
     
    1. classes can't execute instance methods
    2. playGame is a class
    3. #startNewGame is an instance method
     
    it follows logically that playGame can't execute #startNewGame. That line of code in your original post won't work. Instead, you have to create a playGame, like this:
    playGame game = new playGame(); game.startNewGame(); In this case game is an object. Since instance methods are meant to be used with objects, you won't get an error here. 
     
    In my opinion, though your overall class/method structure is convoluted and doesn't make sense OOP-wise. A class should be a definition, a "class" of objects, while a method should be an action, a thing you can do. Your structure does not follow this principle because one of your classes is named "play game," which is an action instead of a definition. 
  20. Agree
    Philosobyte got a reaction from Blade of Grass in non-static method cannot be referenced from a static context   
    I explained this somewhat in your other thread. 
     
    The problem here is you're not understanding the most important, foundational concept in OOP. And that's the difference between a class and an object. 
     
    A class is a definition of something, and an object is an instance of something. Classes can only use class methods, and not instance methods. meanwhile, objects can use both class methods and instance methods (but in my opinion should stick with using only instance methods). 
     
     For example, let's say we have this class and these objects:
     
    class Human: the definition of a certain species of bipedal organism which has high intelligence and refined motor skills. 
    objects Mary, Jane, and Watson: each of these three objects is an instance of Human. Each of these objects are created from the definition Human. 

    These two types are not interchangeable - neither in real life nor in Java. There are going to be methods which can only be carried out by the Human definition (or the "entire Human race") and there are methods which can only be carried out by individual humans. This is seen in the following example code. 
     
    public class Human { //1 - class variables (also known as static variables) static double averageHeight = 177.8; static double averageWeight = 141.53; static double maxRunningSpeed = 44.2; static long populationCount = 7000000000L; //2 - instance variables double height; double weight; double runningSpeed; String name; public Human(String name, double height, double weight, double runningSpeed) { this.name = name; this.height = height; this.weight = weight; this.runningSpeed = runningSpeed; } //3 - instance method public void run() { System.out.println(name + " is running at " + runningSpeed + " km/hr."); } //4 - class method (also known as static method) public static void goThroughExtinction() { populationCount = 0; System.out.println("Oh noes! It appears that the human race is no more."); } } public class Main { public static void main(String[] args) { Human Mary = new Human("Mary", 163, 156, 13); Human Jane = new Human("Jane", 166, 141, 19); Human Watson = new Human("Watson", 172, 185, 32); Human.run(); //5 - Static context error Watson.run(); Human.goThroughExtinction(); Mary.goThroughExtinction(); //6 - no error, but avoid this } } 1: Class variables apply to not any one object in particular, but all objects. In this case, the average height, weight, and top running speed apply to the entire Human species.
     
    2: Instance variables apply to a single object and do not necessarily represent the class. In this case, a single person's height and weight doesn't represent the height and weight of the entire Human species.
     
    3 and 5: An instance method is an action which can only be carried out by an individual object, not a class. You can say that a single person such as Watson ran at a speed of 32 km/hr, but it doesn't make sense to say "the entire human species ran at a speed of 32 km/hr." The entire human species isn't a thing that can run; only members of the human species can run. That's why you're getting a static context error. You're trying to make a class execute an instance method like I'm trying to make the human species run, and that isn't possible.
     
    4 and 6. A class method is an action which should only be carried out by the class, not the object. The entire human species can go through extinction and die off, but it doesn't make sense to say "Mary went through extinction." A single person can't go "extinct." Despite this, Java allows you to use an object to execute a class method. So even though it doesn't make sense to say that Mary went through extinction, Java allows you to do it. 
     
    -------------------------------------------------------------------------------
     
    So how does this apply to you? Well, first of all, what I just explained is the entire point of Object-Oriented Programming (OOP) languages such as Java. If you don't completely understand this concept, you won't be progressing very far in Java. 
     
    Second of all, points 3 and 5 explain the error you described in your original post. If you consider that
     
    1. classes can't execute instance methods
    2. playGame is a class
    3. #startNewGame is an instance method
     
    it follows logically that playGame can't execute #startNewGame. That line of code in your original post won't work. Instead, you have to create a playGame, like this:
    playGame game = new playGame(); game.startNewGame(); In this case game is an object. Since instance methods are meant to be used with objects, you won't get an error here. 
     
    In my opinion, though your overall class/method structure is convoluted and doesn't make sense OOP-wise. A class should be a definition, a "class" of objects, while a method should be an action, a thing you can do. Your structure does not follow this principle because one of your classes is named "play game," which is an action instead of a definition. 
  21. Like
    Philosobyte got a reaction from Nineshadow in Yet another algorithmic problem...   
    Not sure if I understand it yet, but here's a shot. I assume that you're doing this for C++. I don't know anything about C++, but I would do it in Java by using a HashMap<Integer, Integer>. A map is like a list of mappings, where the first half of the mapping is the "key" and the second half of the mapping is an assigned "value." I think you could simulate a map by using two arrays (or two vectors in C++, I believe), but since a map exists in C++ I'll just use the pseudocode for a map. 
     
    In this case, the first integer (the key) is a number in the sequence and the second integer (the value) is how many times that number shows up. With this method, you only need to go through the sequence once. 
     
    Here's some pseudocode for the process:
    You have three variables: an empty map the original sequence an integer removedCounter You read the first number in the sequence, which is 3. If the map does not already have the key 3, then { Add the mapping (3, 1) to the map. //This means that the number 3 has now shown up in the original sequence 1 time. } else if the map already has the key 3, then { If the value mapped to the key 3 is less than k, then { Replace the mapping with (3, originalValue + 1) //This increments the number of times 3 has shown up by one. } else if the value mapped to the key 3 is more than k, then { Add 1 to your removedCounter. Go on to the next number in the sequence. } } Print removedCounter.  
    This doesn't actually remove anything from the sequence. If you're required to have that in code, then you could easily add in a vector of removed numbers. 
     
    edit: a Java version of the program with 6 integers and a k value of 1 takes less than a millisecond to run. The Java version with 1 million integers and a k value of 1 takes 320 - 360 milliseconds to run in IntelliJ Idea on a Core i3-4000M. With a k value of 1 million, it takes 800 - 900 milliseconds to run. C++ should be faster than Java, and you're likely using a more powerful computer than mine. I don't have time to implement a two-vector version instead of the map version, but you might squeeze some extra speed out of it if you use the two-vector version. 
  22. Informative
    Philosobyte reacted to sushisharkjl in Will this work? (Mic Setup)   
    I have one of those cables (I'm not sure of the exact brand but it does appear to be the same one) that I use with a ~$50 Sennheiser dynamic mic (which I sold after getting a condenser) and it worked fairly well without a preamp. The noise is bearable, but definitely much, much worse than my current audio setup (Scarlett 2i2 + AT2035).
  23. Informative
    Philosobyte got a reaction from Claryn in Several instances of one jFrame Form?   
    It could be solved if you declared all the objects inside of a class, but outside of a method. Like so:
    public class PlayGame { public static cahPlayer player1; public static cahPlayer player2; public static cahPlayer player3; public static cahPlayer player4; public static cahPlayer player5; public static cahPlayer player6; public static void startNewGame(int numPlayers) { if (numPlayers == 3) { player1 = new cahPlayer(); player2 = new cahPlayer(); player3 = new cahPlayer(); } /* etcetera, skipping 4 and 5 */ else if (numPlayers == 6) { player1 = new cahPlayer(); player2 = new cahPlayer(); player3 = new cahPlayer(); player4 = new cahPlayer(); player5 = new cahPlayer(); player6 = new cahPlayer(); } } } In this case, each player is a class variable because each player is static. This means that the class PlayGame owns the players. Since PlayGame owns the players, you can access each player within PlayGame by simply calling "player1" or "player2," but if you're outside of PlayGame you access them by calling "PlayGame.player1" or "PlayGame.player2" etc. This setup should work. 
     
    Have you learned arraylists yet? If not, ignore this next section. If you have learned arraylists, then this would be a very good time to use them to make sure that you can do more than six players without repeating a bunch of unnecessary code. For example, the following is a replacement for the above code which does the same thing, but is much more flexible with how many players you can input: 
    public class PlayGame { public static ArrayList<cahPlayer> list = new ArrayList<>(); public static void startNewGame(int numPlayers) { for(int i = 0; i < numPlayers; i++) { list.add(new cahPlayer()); } } //if I want to access a cahPlayer's variables, I can just do: public void example(int indexOfPlayer) { list.get(indexOfPlayer).textField1.setText("etc."); } //An alternative to using lists is to use a map, if you want to give a name to each player and be able to access each player by name. But you might not have learned maps yet, so I'll hold off on recommending them. }  
  24. Agree
    Philosobyte got a reaction from BlueDragon in Several instances of one jFrame Form?   
    It could be solved if you declared all the objects inside of a class, but outside of a method. Like so:
    public class PlayGame { public static cahPlayer player1; public static cahPlayer player2; public static cahPlayer player3; public static cahPlayer player4; public static cahPlayer player5; public static cahPlayer player6; public static void startNewGame(int numPlayers) { if (numPlayers == 3) { player1 = new cahPlayer(); player2 = new cahPlayer(); player3 = new cahPlayer(); } /* etcetera, skipping 4 and 5 */ else if (numPlayers == 6) { player1 = new cahPlayer(); player2 = new cahPlayer(); player3 = new cahPlayer(); player4 = new cahPlayer(); player5 = new cahPlayer(); player6 = new cahPlayer(); } } } In this case, each player is a class variable because each player is static. This means that the class PlayGame owns the players. Since PlayGame owns the players, you can access each player within PlayGame by simply calling "player1" or "player2," but if you're outside of PlayGame you access them by calling "PlayGame.player1" or "PlayGame.player2" etc. This setup should work. 
     
    Have you learned arraylists yet? If not, ignore this next section. If you have learned arraylists, then this would be a very good time to use them to make sure that you can do more than six players without repeating a bunch of unnecessary code. For example, the following is a replacement for the above code which does the same thing, but is much more flexible with how many players you can input: 
    public class PlayGame { public static ArrayList<cahPlayer> list = new ArrayList<>(); public static void startNewGame(int numPlayers) { for(int i = 0; i < numPlayers; i++) { list.add(new cahPlayer()); } } //if I want to access a cahPlayer's variables, I can just do: public void example(int indexOfPlayer) { list.get(indexOfPlayer).textField1.setText("etc."); } //An alternative to using lists is to use a map, if you want to give a name to each player and be able to access each player by name. But you might not have learned maps yet, so I'll hold off on recommending them. }  
  25. Informative
    Philosobyte got a reaction from Claryn in Several instances of one jFrame Form?   
    Two problems:
     
    1. Variables are only visible within the code block which they were declared in. Therefore, in your series of if statements, each cahPlayer (player1, player2, player3, etc.) can only be used and seen within the if block. That's why they have to be declared outside of the if block, like this:
    public void example1(int numPlayers) { if (numPlayers == 3) { cahPlayer player1 = new cahPlayer(); cahPlayer player2 = new cahPlayer(); cahPlayer player3 = new cahPlayer(); } player1.doSomething(); //this will fail because we're attempting to call player1 out of its block. } public void example2(int numPlayers) { cahPlayer player1; cahPlayer player2; cahPlayer player3; if (numPlayers == 3) { player1 = new cahPlayer(); player2 = new cahPlayer(); player3 = new cahPlayer(); } player1.doSomeAction(); //this will be successful because we're accessing player1 from its block. }  
    2. When you use cahPlayer.player1.PBC.setText(), you're assuming that cahPlayer owns the variable player1. The format is Class.staticVariable.doSomething() or object.instanceVariable.doSomething(); Both of these statements are basically saying "the Class owns the staticVariable" or "the object owns the instance variable"
    However, since you're declaring player1 inside of a method, it's a local variable and it's not owned by an object or class. Therefore, you would have to put only player1.PBC.setText() instead of cahPlayer.player1.PBC.setText();
     
    These two reasons are why you're getting errors. I haven't looked at the pastebin code yet.
     
    Also, keep in mind that all classes should be capitalized. So it should really be CahPlayer instead of cahPlayer. 
×