Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Jbutton Help
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
romantic_programmer




PostPosted: Thu Jan 18, 2007 8:36 pm   Post subject: Jbutton Help

Ok, here is my problem. When i load up my buttons They are automatically enabled. i was wondering if their is a way to have them appear disabled when the buttons load? here is my code maybe some one can help me figure it out.


Java:
protected JButton ab, hb, fb, ib;

    public JJRealm_Adventures ()
    {
        ImageIcon leftButtonIcon = createImageIcon ("left.gif");

        ab = new JButton ("Attack", leftButtonIcon);
        ab.setMnemonic (KeyEvent.VK_A);
        ab.setActionCommand ("attack");

        hb = new JButton ("Heal", leftButtonIcon);
        hb.setMnemonic (KeyEvent.VK_H);
        hb.setActionCommand ("heal");

        fb = new JButton ("Flee", leftButtonIcon);
        //Use the default text position of CENTER, TRAILING (RIGHT).
        fb.setMnemonic (KeyEvent.VK_F);
        fb.setActionCommand ("flee");

        ib = new JButton ("Item", leftButtonIcon);
        //Use the default text position of CENTER, TRAILING (RIGHT).
        ib.setMnemonic (KeyEvent.VK_I);
        ib.setActionCommand ("item");

        //Listen for actions on buttons 1 and 3.
        ab.addActionListener (this);
        hb.addActionListener (this);
        fb.addActionListener (this);
        ib.addActionListener (this);

        ab.setToolTipText ("Click this button to attack");
        hb.setToolTipText ("Click this button to defend");
        fb.setToolTipText ("Click this button to flee");
        ib.setToolTipText ("Click this button to access an item");

        //Add Components to this container, using the default FlowLayout.
        add (ab);
        add (hb);
        add (fb);
        add (ib);
    }


    public void actionPerformed (ActionEvent e)
    {

        if ("attack".equals (e.getActionCommand ()))
        {
            monsterHP = (monsterHP - (playerATK - monsterAP));
            playerHP = (playerHP - (monsterATK - playerAP));
            drawPlayerGrid ();
            playerStats ();
            c.clear ();


        }
        else if ("heal".equals (e.getActionCommand ()))
        {
            playerHP = playerHP + 15;
            c.clear ();

        }
        else if ("flee".equals (e.getActionCommand ()))
        {
            c.clear ();

            c.setFont (Battle);
            c.drawString ("you have fled", 50, 50);
            c.getChar ();
            condition = 5;
        }
        else if ("item".equals (e.getActionCommand ()))
        {

        }

        if (monsterHP <= 0)
        {
            ab.setEnabled (false);
            fb.setEnabled (false);
            ib.setEnabled (false);
        }
        else if (playerHP <= 0)
        {
            ab.setEnabled (false);
            fb.setEnabled (false);
            ib.setEnabled (false);

        }
        else if (condition == 4)
        {
            ab.setEnabled (true);
            fb.setEnabled (true);
            ib.setEnabled (false);

        }
        if (race == "cleric")
        {
            hb.setEnabled (true);
        }
        else
        {
            hb.setEnabled (false);
        }
    }


    /** Returns an ImageIcon, or null if the path was invalid. */
    protected static ImageIcon createImageIcon (String path)
    {
        java.net.URL imgURL = JJRealm_Adventures.class.getResource (path);
        if (imgURL != null)
        {
            return new ImageIcon (imgURL);
        }
        else
        {
            return null;
        }
    }


    /**
     * Create the GUI and show it.  For thread safety,
     * this method should be invoked from the
     * event-dispatching thread.
     */
    private static void createAndShowGUI ()
    {

        //Create and set up the window.
        JFrame frame = new JFrame ("Battle");
        frame.setDefaultCloseOperation (JFrame.DO_NOTHING_ON_CLOSE);

        //Create and set up the content pane.
        JJRealm_Adventures newContentPane = new JJRealm_Adventures ();
        newContentPane.setOpaque (true); //content panes must be opaque
        frame.setContentPane (newContentPane);

        //Display the window.
        frame.pack ();
        frame.setVisible (true);

    }




//Schedule a job for the event-dispatching thread:
        //creating and showing this application's GUI.
        javax.swing.SwingUtilities.invokeLater (new Runnable ()
        {
            public void run ()
            {
                createAndShowGUI ();
            }
        }
        );

Sponsor
Sponsor
Sponsor
sponsor
HellblazerX




PostPosted: Thu Jan 18, 2007 8:56 pm   Post subject: Re: Jbutton Help

Java:
JButton.setEnabled (false)

Next time, for questions like these, refer to the Java Almanac.
romantic_programmer




PostPosted: Thu Jan 18, 2007 10:21 pm   Post subject: Re: Jbutton Help

ya i just figure it out before you posted... umm that site i cant seem to find anything but [url]java.sun.com[/url] has good tutorials.

Thank you for your post...

I also have another question it is about the .drawString I am doing some math calculations with it for my game and i only want it to display to the tenth decimal place.

I know their might be a method for this just i don't know what one or how to get it to work for me...

so if anyone has any input on this please let me know thank you.
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: