PleaseHelpne's Profile User Rating: -----

Reputation: -1 Dishonored
Group:
New Members
Active Posts:
8 (0.01 per day)
Joined:
11-May 12
Profile Views:
208
Last Active:
User is offline May 12 2012 05:56 PM
Currently:
Offline

Previous Fields

Dream Kudos:
0
Icon   PleaseHelpne has not set their status

Posts I've Made

  1. In Topic: How can I remove the submenus in this program? (picture included)

    Posted 12 May 2012

    Alright! Nevermind everyone, I figured it out. Thanks so much for your tips, though!
  2. In Topic: How can I remove the submenus in this program? (picture included)

    Posted 12 May 2012

    View Postoha055, on 12 May 2012 - 10:15 AM, said:

    what happens if you remove this line?

    groupPlayers1.add(rbMenuItem);


    Posted Image
    I did that and some more, but now Computer doesn't show up. What did I do wrong?

      menu = new JMenu("Players");
            menu.setMnemonic(KeyEvent.VK_P);
            menuBar.add(menu);
            submenu = new JMenu("Player 1");
            ButtonGroup groupPlayers1 = new ButtonGroup();
            rbMenuItem = new JRadioButtonMenuItem("Human");
            if (p1.getType() == 0) rbMenuItem.setSelected(true);
            rbMenuItem.setName("P1Human");
            rbMenuItem.addItemListener(this);
            groupPlayers1.add(rbMenuItem);
            submenu.add(rbMenuItem);
            rbMenuItem = new JRadioButtonMenuItem("Computer");
            //if (p1.getType() == 1) rbMenuItem.setSelected(true);
            //rbMenuItem.setName("P1Random");
           // rbMenuItem.addItemListener(this);
            //groupPlayers1.add(rbMenuItem);
           // subsubmenu.add(rbMenuItem);
           // rbMenuItem = new JRadioButtonMenuItem("Defensive Player");
            //if (p1.getType() == 2) rbMenuItem.setSelected(true);
           // rbMenuItem.setName("P1Defensive");
           // rbMenuItem.addItemListener(this);
           // groupPlayers1.add(rbMenuItem);
           // subsubmenu.add(rbMenuItem);
           // rbMenuItem = new JRadioButtonMenuItem("Aggressive Player");
            if (p1.getType() == 3) rbMenuItem.setSelected(true);
            rbMenuItem.setName("P1Aggressive");
            rbMenuItem.addItemListener(this);
           // groupPlayers1.add(rbMenuItem);
            //subsubmenu.add(rbMenuItem);
            //rbMenuItem = new JRadioButtonMenuItem("MinMax Player");
            //if (p1.getType() == 4) rbMenuItem.setSelected(true);
            //rbMenuItem.setName("P1MinMax");
           // rbMenuItem.addItemListener(this);
           // groupPlayers1.add(rbMenuItem);
           // subsubmenu.add(rbMenuItem);
           // submenu.add(subsubmenu);
    


    View PosttlhIn`toq, on 12 May 2012 - 10:19 AM, said:

    I'm confused as to why this is causing you grief. You can see where they are created starting at line 12.

    Comment out the lines that make them.

    You could let them be created and just not add them.
    See in line 35 where they are added to the groupPlayer1?
    Comment out that line: 35

    I'm guessing you didn't make this code. Do you have no understanding of any of this; its all gibberish to you? You're dismantling someone else's code in an effort to learn java?

    There are three routes people seem to take when learning programming.
    • Just start trying to create programs
    • Start taking apart other programs and try to figure out the language by reverse engineering
    • Follow a guided learning course (school or self-teaching books)


    For the life of me I can't figure out why people try 1 & 2.
    Sure, 35 years ago the only way I could learn BASIC as a kid was to type programs from a book into a TRS-80 model 1 or Commodore VIC-20, then figure out the commands and syntax by watching the results as the program ran. There simply wasn't any courses for a kid back then.

    But now, you can't help but to trip over "Learn {coding language} in 3 weeks" type books and the entire internet is at your disposal for tutorials.

    I strongly suggest taking the guided learning approach. Those book authors go in a certain order for a reason: They know what they're doing and they know the best order to learn the materials.

    Quote

    Where do I start?


    You start by learning a coding language FIRST.
    Learn to plan before you type.
    THEN you start designing software with a purpose.


    If this sounds like you

    Newbie/Rookie said:

    I have a little programming experience but I need to write ...
    read this section
    Spoiler


    Otherwise, you can just jump to the resources here:
    Some of the tutorials below are for C# or Java not C, C++, VB.NET [...]. But the conceptual stuff of classes, object oriented design, events etc. are not language specific and should give you enough guidance in theory of program development for you to be able to look-up specific code example in your chosen coding language.



    Resources, references and suggestions for new programmers. - Updated Mar 2012
    Spoiler



    I agree with you! However, the truth is I learn far better when I analyze other programmer's code! I get to delete and add code, and see how it works myself. It gets deep into my mind because I can connect it to other things I know, other than just being spoon fed instructions.
  3. In Topic: How can I make this applet into a standalone application?

    Posted 11 May 2012

    View Postoha055, on 11 May 2012 - 05:48 PM, said:

    at the top of your init method put

    setVisible(true);
    
    



    Thank you! Main is working perfectly now!
    Any tips on how to make the window bigger? When I run main, the program starts, but the window is minimized. I want to make it at least 500x500, but i'm not sure how
  4. In Topic: How can I make this applet into a standalone application?

    Posted 11 May 2012

    View Postoha055, on 11 May 2012 - 05:23 PM, said:

    after extending JFrame, the second thing you need to do is create a main method so that the program executes. Think of the main method as the equivalent of the JApplets init method.

    public static void main(String[] args) {
    new BlackjackGUI();
    }
    
    


    Also, put the init method in a constructor for the BlackjackGUI class, so that it is called upon startup. Since you aren't dealing with an applet anymore, the init method isn't called automatically.

    public BlackjackGUI() {
    init();
    }
    
    



    Thank you so much. I added this code (the new constructor is at the top and the main method is at the bottom)
    But when I run the main method, nothing happens.

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    
    public class BlackjackGUI extends JFrame {
    
        public BlackjackGUI(){
            init();
        }
    
        public void init() {
            setBackground( new Color(130,50,40) );
    
            BlackjackCanvas board = new BlackjackCanvas();
            getContentPane().add(board, BorderLayout.CENTER);
    
            JPanel buttonPanel = new JPanel();
            buttonPanel.setBackground( new Color(220,200,180) );
            getContentPane().add(buttonPanel, BorderLayout.SOUTH);
    
            JButton hit = new JButton( "Hit!" );
            hit.addActionListener(board);
            buttonPanel.add(hit);
    
            JButton stand = new JButton( "Stand!" );
            stand.addActionListener(board);
            buttonPanel.add(stand);
    
            JButton newGame = new JButton( "New Game" );
            newGame.addActionListener(board);
            buttonPanel.add(newGame);
    
        } 
    
        public Insets getInsets() {
            return new Insets(3,3,3,3);
        }
    
        class BlackjackCanvas extends JPanel implements ActionListener {
    
            Deck deck;         
            BlackjackHand dealerHand;  
            BlackjackHand playerHand;   
            String message; 
    
            boolean gameInProgress;  
    
            Font bigFont;     
            Font smallFont;    
    
            BlackjackCanvas() {
    
                setBackground( new Color(0,120,0) );
                smallFont = new Font("SansSerif", Font.PLAIN, 12);
                bigFont = new Font("Serif", Font.BOLD, 14);
                doNewGame();
            }
    
            public void actionPerformed(ActionEvent evt) {
    
                String command = evt.getActionCommand();
                if (command.equals("Hit!"))
                    doHit();
                else if (command.equals("Stand!"))
                    doStand();
                else if (command.equals("New Game"))
                    doNewGame();
            }
    
            void doHit() {
    
                if (gameInProgress == false) {
                    message = "Click \"New Game\" to start a new game.";
                    repaint();
                    return;
                }
                playerHand.addCard( deck.dealCard() );
                if ( playerHand.getBlackjackValue() > 21 ) {
                    message = "You've busted!  Sorry, you lose.";
                    gameInProgress = false;
                }
                else if (playerHand.getCardCount() == 5) {
                    message = "You win by taking 5 cards without going over 21.";
                    gameInProgress = false;
                }
                else {
                    message = "You have " + playerHand.getBlackjackValue() + ".  Hit or Stand?";
                }
                repaint();
            }
    
            void doStand() {
    
                if (gameInProgress == false) {
                    message = "Click \"New Game\" to start a new game.";
                    repaint();
                    return;
                }
                gameInProgress = false;
                while (dealerHand.getBlackjackValue() <= 16 && dealerHand.getCardCount() < 5)
                    dealerHand.addCard( deck.dealCard() );
                if (dealerHand.getBlackjackValue() > 21)
                    message = "You win!  Dealer has busted with " + dealerHand.getBlackjackValue() + ".";
                else if (dealerHand.getCardCount() == 5)
                    message = "Sorry, you lose.  Dealer took 5 cards without going over 21.";
                else if (dealerHand.getBlackjackValue() > playerHand.getBlackjackValue())
                    message = "Sorry, you lose, " + dealerHand.getBlackjackValue()
                    + " to " + playerHand.getBlackjackValue() + ".";
                else if (dealerHand.getBlackjackValue() == playerHand.getBlackjackValue())
                    message = "Sorry, you lose.  Dealer wins on a tie.";
                else
                    message = "You win, " + playerHand.getBlackjackValue()
                    + " to " + dealerHand.getBlackjackValue() + "!";
                repaint();
            }
    
            void doNewGame() {
    
                if (gameInProgress) {
    
                    message = "You still have to finish this game!";
                    repaint();
                    return;
                }
                deck = new Deck();   
                dealerHand = new BlackjackHand();
                playerHand = new BlackjackHand();
                deck.shuffle();
                dealerHand.addCard( deck.dealCard() ); 
                dealerHand.addCard( deck.dealCard() );
                playerHand.addCard( deck.dealCard() );
                playerHand.addCard( deck.dealCard() );
                if (dealerHand.getBlackjackValue() == 21) {
                    message = "Sorry, you lose.  Dealer has Blackjack.";
                    gameInProgress = false;
                }
                else if (playerHand.getBlackjackValue() == 21) {
                    message = "You win!  You have Blackjack.";
                    gameInProgress = false;
                }
                else {
                    message = "You have " + playerHand.getBlackjackValue() + ".  Hit or stand?";
                    gameInProgress = true;
                }
                repaint();
            }  // end newGame();
    
            public void paintComponent(Graphics g) {
    
                super.paintComponent(g); 
                g.setFont(bigFont);
                g.setColor(Color.green);
                g.drawString(message, 10, getSize().height - 10);
    
                g.drawString("Dealer's Cards:", 10, 23);
                g.drawString("Your Cards:", 10, 153);
    
    
                g.setFont(smallFont);
                if (gameInProgress)
                    drawCard(g, null, 10, 30);
                else
                    drawCard(g, dealerHand.getCard(0), 10, 30);
                for (int i = 1; i < dealerHand.getCardCount(); i++)
                    drawCard(g, dealerHand.getCard(i), 10 + i * 90, 30);
    
    
                for (int i = 0; i < playerHand.getCardCount(); i++)
                    drawCard(g, playerHand.getCard(i), 10 + i * 90, 160);
    
            }  
    
            void drawCard(Graphics g, Card card, int x, int y) {
    
                if (card == null) {  
    
                    g.setColor(Color.blue);
                    g.fillRect(x,y,80,100);
                    g.setColor(Color.white);
                    g.drawRect(x+3,y+3,73,93);
                    g.drawRect(x+4,y+4,71,91);
                }
                else {
                    g.setColor(Color.white);
                    g.fillRect(x,y,80,100);
                    g.setColor(Color.gray);
                    g.drawRect(x,y,79,99);
                    g.drawRect(x+1,y+1,77,97);
                    if (card.getSuit() == Card.DIAMONDS || card.getSuit() == Card.HEARTS)
                        g.setColor(Color.red);
                    else
                        g.setColor(Color.black);
                    g.drawString(card.getValueAsString(), x + 10, y + 30);
                    g.drawString("of", x+ 10, y + 50);
                    g.drawString(card.getSuitAsString(), x + 10, y + 70);
                }
            } 
    
        } 
        public static void main(String[] args) {
            new BlackjackGUI();
        }
    
    } 
    
    
  5. In Topic: How can I make this applet into a standalone application?

    Posted 11 May 2012

    View Postmacosxnerd101, on 11 May 2012 - 04:45 PM, said:

    You could add your Applet to a JFrame, and use the JFrame for your standalone application.


    Thank you! I replaced the code as
    public class BlackjackGUI extends JFrame.
    

    However, I'm not sure how i'm supposed to use Jframe as my standalone application.

My Information

Member Title:
New D.I.C Head
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:

Contact Information

E-mail:
Click here to e-mail me

Friends

PleaseHelpne hasn't added any friends yet.

Comments

PleaseHelpne has no profile comments yet. Why not say hello?