Sheph's Profile User Rating: -----

Reputation: 447 Architect
Group:
Contributors
Active Posts:
1,031 (0.73 per day)
Joined:
12-October 11
Profile Views:
7,107
Last Active:
User is offline Yesterday, 02:14 PM
Currently:
Offline

Previous Fields

Country:
US
OS Preference:
Windows
Favorite Browser:
Chrome
Favorite Processor:
Who Cares
Favorite Gaming Platform:
XBox
Your Car:
Honda
Dream Kudos:
125
Icon   Sheph is probably programming.

Posts I've Made

  1. In Topic: Best way to go through stages of a basic game.

    Posted 19 Aug 2015

    You could look into having some sort of state machine to defer control of the game to the current state. Check out the State Pattern. I find the wikipedia article a little hard to digest for this particular design pattern, so I added another article that may be of use.
    https://en.wikipedia...i/State_pattern
    https://sourcemaking..._patterns/state

    It might take a while to learn, and it's up to you to apply YAGNI (Ya ain't gonna need it) to see if it's right for your game. There could be simpler ways to do it depending on how you implement the game. Good luck.
  2. In Topic: Understanding what is happening with repaint() and paintComponent()

    Posted 18 Aug 2015

    First, I'd like to point you to the documentation available for all of the classes you are talking about.

    JPanel - http://docs.oracle.c...ing/JPanel.html
    JComponent - http://docs.oracle.c...JComponent.html
    Graphics - http://docs.oracle.c...t/Graphics.html
    Graphics2D - http://docs.oracle.c...Graphics2D.html
    repaint() - http://docs.oracle.c....html#repaint()

    It will be a beneficial skill for you to have if you are able to learn how to find this documentation when you are having questions about a class in a library that you didn't write. I will answer any of your questions that wouldn't be entirely clear after reading the docs.

    Why is this beneficial to use a JComponent over a JPanel, or does it even matter?
    It really doesn't much matter, but since JPanel is a subclass of JComponent, if you are only going to use the component for overriding its paintComponent() method, then you might as well not bring along all of the additional features and baggage of JPanel. Unless of course, JPanel has the features you want. Again, see the docs.

    Is this only necessary once when I load up the class? whats the benefits of graphics2D of just Graphics?
    As you should be able to tell by reading the docs, Graphics2D is a subclass of Graphics. Meaning it has all of the functionality of a Graphics object, plus some additional features that Graphics does not support. If you want access to these additional features, you must tell your program to treat it like a Graphics2D object, so you can call those methods. You do this by casting it. (But be careful, when casting objects, you must be sure that they are actually of that type. In this case, you are safe to cast it to Graphics2D.)

    Normally, since the method paintComponent() passes you a Graphics object, you MUST cast it to a Graphics2D object each call if you want the functionality, but since you are using an image whose context won't really change much, you can probably get away with storing an instance variable reference to the Graphics2D object.

    What does this even do? How does Java handle rendering?
    You will be able to find all of that information in the documentation. Start in Graphics2D, find the methods, click around. It's pretty easy.
  3. In Topic: Connect 4 GUI

    Posted 9 Jan 2015

    It is so stupid when you are told not to use a superior method because you haven't learned it yet. I could have you cheat and store your button states in a long, but that'd be pushing it. Anyway, ranting aside, you will need a way to determine which button is in which column. i would consider naming them: column1row1button, column1row2button etc. Then in the column1button handlers, you check each column1 labled button starting with the lowest row.

    public boolean isButtonEmpty(JButton btn) {
        return !(btn.getIcon()==x||btn.getIcon()==y);
    }
    
    public void setCurrentPlayerIcon(JButton btn) {
        if(player1==1)
            btn.setIcon(x);
        else
            btn.setIcon(y);
    }
    
    // in actionPerformed:
    
    if(clicked==column1row1button) {
        if(isButtonEmpty(column1row1button)) {
            setCurrentPlayerIcon(column1row1button);
            return;
        }
    
        if(isButtonEmpty(column1row2button)) {
            setCurrentPlayerIcon(column1row1button);
            return;
        }
    
        if(isButtonEmpty(column1row3button)) {
            setCurrentPlayerIcon(column1row1button);
            return;
        }
        // etc...
    }
    
    if(clicked==column2row1button) {
        if(isButtonEmpty(column2row1button)) {
            setCurrentPlayerIcon(column1row1button);
            return;
        }
    
        if(isButtonEmpty(column2row2button)) {
            setCurrentPlayerIcon(column1row1button);
            return;
        }
    
        if(isButtonEmpty(column2row3button)) {
            setCurrentPlayerIcon(column1row1button);
            return;
        }
        // etc...
    }
    

    Hope that helps...
  4. In Topic: Trouble with Draw/Paint in Swing (Sierpinski)

    Posted 4 Jan 2015

    So we see from CasiOo's example that most of your y values are negative or below 30sh. In the JFrame, the window border was probably covering the rectangles. using the JPanel we see that the top has a line of rectangles, but it is cut off. Perhaps you should pick more centrally located points that lie within the bounds of your panel. *That means it was probably working in the JFrame paint(), except that the window border was covering it, which is another good reason to use JPanel.

    Particularly, pointC[1] = (int) Math.round((Math.sin(60.0) * 100));, which always results in -30.
  5. In Topic: File Object - What is it?

    Posted 4 Jan 2015

    The API documentation describes it as "An abstract representation of file and directory pathnames."
    http://docs.oracle.c...va/io/File.html

    The File object won't create a new file on your computer when you create it, because it is only an abstraction. It does however have methods which you can call which will use the JVM's implementation to get the file system and actually create the file from the abstract data.

My Information

Member Title:
D.I.C Lover
Age:
24 years old
Birthday:
January 7, 1991
Gender:
Interests:
Tennis, Karate, Board & Card Games, Fantasy Novels
Full Name:
Richard Shepherd
Years Programming:
7
Programming Languages:
Java, C++, html, CSS and javascript.

Contact Information

E-mail:
Private
AIM:
AIM  Sheph1220
Yahoo:
Yahoo  Richjm12

Comments

Page 1 of 1
  1. Photo

    helppp Icon

    09 Feb 2013 - 21:48
    Can someone answer this for me Ill rep you
    http://www.dreamincode.net/forums/topic/311754-how-do-i-create-a-terms-of-conditions-popup-that-you-cannot-exit/page__p__1800087__fromsearch__1&#entry1800087
    sorry fro spamming
  2. Photo

    Sheph Icon

    07 Dec 2012 - 03:59
    Why, thank you! :)
  3. Photo

    raghav.naganathan Icon

    07 Dec 2012 - 03:44
    Congrats on the 400 :)
  4. Photo

    .Aaron Icon

    12 Jul 2012 - 23:24
    "It's printLn() (lowercase L) - not printIn. Why would an OutputStream have an IN function? :)"
    [Insert the thumbs up emoticon here]
  5. Photo

    fromTheSprawl Icon

    18 Apr 2012 - 19:10
    Oh, hey there, wasn't intentional, not trying to do a "Club 27" there. Things just got too much, I found something I want to do, rode a unicorn, found out there was no candy on top of Mt. Everest, and hitchhiked the way back here. So... sup? Hahaha.
  6. Photo

    Sheph Icon

    04 Mar 2012 - 22:11
    Thanks, Mylo. You are actually the reason I made it. I saw your suggestion in the tutorial suggestions thing when i was looking to become a contributor.
  7. Photo

    Mylo Icon

    29 Dec 2011 - 21:06
    The bitwise tutorial is appreciated =) I may learn a few more things from it
  8. Photo

    Sheph Icon

    10 Dec 2011 - 19:58
    Oh nice. Yeah I answered like 3 of those questions in 30 minutes one day, and after a while you start wondering why it isn't common sense.
    Side note. You are a creeper to come by that quickly. What do you have my profile monitored? jk
  9. Photo

    Sho Ke Icon

    09 Dec 2011 - 09:27
    " It's printLn() (lowercase L) - not printIn. Why would an OutputStream have an IN function? :) "
    :D
  10. Photo

    Sheph Icon

    08 Dec 2011 - 21:32
    I just changed it. Which part? the random order?
  11. Photo

    Sho Ke Icon

    08 Dec 2011 - 15:58
    Your signature made me giggle. *goes back to lurking*
  12. Photo

    Sheph Icon

    06 Nov 2011 - 17:00
    Yeah! Thanks for noticing! :)
  13. Photo

    DimitriV Icon

    06 Nov 2011 - 12:57
    You're a stalwart!
Page 1 of 1