Results 1 to 7 of 7
  1. #1
    mbschultz97 is offline Member
    Join Date
    May 2014
    Location
    Texas
    Posts
    73
    Rep Power
    0

    Default GUI/Event handler

    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;


    public class GUI extends JFrame {
    public GUI(){
    setAlwaysOnTop(true);
    getContentPane().setBackground(Color.LIGHT_GRAY);
    setTitle("TPCowSlayer");
    setBounds(100, 100, 148, 108);
    setSize(270,120);
    setBackground(Color.WHITE);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JPanel panel = new JPanel();
    getContentPane().add(panel);
    panel.setLayout(null);

    JRadioButton rdbtnBuryBones = new JRadioButton("Bury Bones");
    rdbtnBuryBones.setBounds(6, 7, 109, 23);
    panel.add(rdbtnBuryBones);

    JRadioButton rdbtnLootCowhide = new JRadioButton("Loot Cowhide");
    rdbtnLootCowhide.setBounds(6, 33, 109, 23);
    panel.add(rdbtnLootCowhide);

    JButton btnStart = new JButton("Start");
    btnStart.setBounds(155, 47, 89, 23);
    panel.add(btnStart);
    }
    }

    how do i set GUI visible false if btnStart is pressed?

  2. #2
    mmoop is offline Member
    Join Date
    Jun 2015
    Posts
    2
    Rep Power
    0

    Default Re: GUI/Event handler

    Java Code:
        JButton btnStart = new JButton("Start");
        btnStart.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e){
                    setVisible(false);
         }});
    Last edited by mmoop; 06-11-2015 at 06:04 AM. Reason: forgot override notation

  3. #3
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,423
    Blog Entries
    7
    Rep Power
    27

    Default Re: GUI/Event handler

    @mmoop: spoon feeding is frowned upon here; please don't just dump a piece of code that is supposed to be an answer to the topic question; it doesn't help the OP; s/he'll probably just copy and paste it without understanding anything ...

    kind regards,

    Jos
    Build a wall around Donald Trump; I'll pay for it.

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    12,059
    Rep Power
    25

    Default Re: GUI/Event handler

    Someone who has 66 posts and has been a member for more than a year and still doesn't know how to post code probably isn't very open to learning anything though.

    @mbschultz97: BB Code List - Java Programming Forum - Learn Java Programming

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  5. #5
    mbschultz97 is offline Member
    Join Date
    May 2014
    Location
    Texas
    Posts
    73
    Rep Power
    0

    Default Re: GUI/Event handler

    @DarrylBurke I've been inactive for a long time, sorry I forgot

  6. #6
    Gotcha is offline Member
    Join Date
    Jun 2015
    Location
    America
    Posts
    29
    Rep Power
    0

    Default Re: GUI/Event handler

    So I guess it is frowned upon to link a great example? (Top part is for PC and it is a neat example I have referenced while learning).. If I get to anything I don't understand I Google or even just YouTube it.
    Android TCP Connection Tutorial - My Android Solutions

    P.S. Bottom part is Android which is kinda cool if you agree :)

  7. #7
    Artemia is offline Member
    Join Date
    May 2015
    Location
    Netherlands
    Posts
    39
    Rep Power
    0

    Default Re: GUI/Event handler

    @mmoop: spoon feeding is frowned upon here; please don't just dump a piece of code that is supposed to be an answer to the topic question; it doesn't help the OP; s/he'll probably just copy and paste it without understanding anything ...
    How exactly do you get that linking an example is frowned upon from that quote?
    He's clearly talking about cases where instead of helping someone figure out how to solve his/her problem, some people write the code that solves the problem for them. This doesn't help them understand what went wrong or how to solve it themselves the next time.
    Having a great example from google or youtube ofcourse isn't the same because you can't get code customized to your exact needs from there, you will however get the info that will help you understand and solve your problem from those two.

    I think it's pretty clear what Jos meant and I totally agree with the message too, figuring out how to solve the problems you encounter (even with some help) will teach you more than someone spoonfeeding you code.

Similar Threads

  1. Problem inside of event handler
    By mwr1976 in forum New To Java
    Replies: 1
    Last Post: 11-12-2011, 04:11 AM
  2. event handler issues
    By kd7vea in forum AWT / Swing
    Replies: 11
    Last Post: 04-22-2011, 12:45 AM
  3. Replies: 0
    Last Post: 03-22-2010, 06:45 AM
  4. event handler not working properly
    By H3rtaherta in forum Java 2D
    Replies: 3
    Last Post: 11-24-2008, 02:39 AM
  5. JList and JButton event handler not working
    By H3rtaherta in forum AWT / Swing
    Replies: 3
    Last Post: 11-22-2008, 12:00 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •