Results 1 to 9 of 9
Like Tree1Likes
  • 1 Post By JosAH

Thread: HELP!!! please

  1. #1
    keekeee14 is offline Member
    Join Date
    Aug 2012
    Posts
    2
    Rep Power
    0

    Default HELP!!! please

    The applet program is suppose to have three buttons that when clicked, three textboxs appear with the same name as the button.





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

    public class MouseClick
    {


    public static void main(String[] args)
    {
    String a = new String(" who?");
    String b = new String("what?");
    String c = new String("when?");
    Label objLabel1 = new Label(a);
    objLabel1.setBounds(20,75,40,40);
    Label objLabel2 = new Label(b);
    objLabel2.setBounds(85,120,40,40);
    Label objLabel3 = new Label(c);
    objLabel3.setBounds(130,185,40,40);
    MouseClick MC= new MouseClick();
    }

    public MouseClick()
    {
    JFrame h= new JFrame("Button and labels");
    final JPanel d = new JPanel();
    Button e= new Button(a);
    e.setBounds(20,30,40,40);
    JButton f= new JButton(b);
    f.setBounds(85,75, 40, 40);
    JButton g = new JButton(c);
    g.setBounds(130, 120, 40, 40);
    d.add(e);
    d.add(f);
    d.add(g);
    h.getContentPane().add(d);


    d.add(objLabel1);
    objLabel1.setVisible(false);
    d.add(objLabel2);
    objLabel2.setVisible(false);
    d.add(objLabel3);
    objLabel3.setVisible(false);
    h.addWindowListener(new WindowAdapter()
    {
    public void windowClosing(WindowEvent we)
    {
    System.exit(0);
    }
    });
    h.setSize(400,400);
    h.setVisible(true);
    }

    public class MyMouseListener extends MouseAdapter
    {
    public void mouseClicked(MouseEvent me)
    {
    objLabel1.setVisible(true);
    objLabel2.setVisible(true);
    objLabel3.setVisible(true);
    }
    }
    }

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: HELP!!! please

    What is your question, where exactly are you stuck? If you can ask a specific question, we'll be much better able to help you.

  3. #3
    .paul. is offline Member
    Join Date
    Jun 2012
    Posts
    73
    Blog Entries
    1
    Rep Power
    0

    Default Re: HELP!!! please

    there aren't any textboxes. there are a Button, 2 JButtons, a JFrame, a JPanel, + 3 Labels

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: HELP!!! please

    Suggestions:
    • Don't mix awt and Swing components. Stick with just Swing components such as JButtons, JLabels, and JTextFields.
    • Use ActionListeners with JButtons, not MouseListeners. ActionListeners are built to work extremely well with buttons and are harder to mess up.
    • Avoid absolute positioning but instead use layout managers to help you position components. The tutorials will help you figure out how to do this.
    • After displaying new components or removing components from a container, call revalidate() and repaint() on that container to display the changes.
    • Go through the standard Java Swing tutorials as they will explain all this and a lot better than I can.
    • Please try to make your question headings here more informative. "Help please" tells us nothing about your problem. A more informative title would be something like, "help displaying components in a GUI" or something similar. This would clue GUI experts to look at your thread. Your title will have the opposite effect.


    Much luck!

  5. #5
    keekeee14 is offline Member
    Join Date
    Aug 2012
    Posts
    2
    Rep Power
    0

    Default Re: HELP!!! please

    Quote Originally Posted by Fubarable View Post
    What is your question, where exactly are you stuck? If you can ask a specific question, we'll be much better able to help you.
    I want to know why it doesn't work. ( i meant labels instead of textboxes)

  6. #6
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: HELP!!! please

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

  7. #7
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: HELP!!! please

    Quote Originally Posted by keekeee14 View Post
    The applet program ...
    What applet program? I don't see any Applet anywhere in that code.

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

  8. #8
    kammce's Avatar
    kammce is offline Senior Member
    Join Date
    Dec 2010
    Location
    California
    Posts
    194
    Rep Power
    4

    Default Re: HELP!!! please

    Quote Originally Posted by keekeee14 View Post
    I want to know why it doesn't work. ( i meant labels instead of textboxes)
    So, you have no idea why this program is not working so you have placed the whole thing here. Also, PLEASE place [code] tags around your code. makes it much easier to see and read and allows us to help you.

    Also, PLEASE follow the instructions made by Fubarable. He read through your entire program and gave you great advice on how to fix your program. Lastly, besides actually removing components, you could use setVisible(false); on them so that they disappear. All components inhereit thier powers from javax.swing.JComponent so all swing components can set their visibility. java.awt.Component, cannot. This is why one should not be using AWT. Just does not have those great features in there. Now, if you DO want to remove them, in which case, follow Fubarable.
    My API:
    Java Code:
    cat > a.out || cat > main.class

  9. #9
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,353
    Blog Entries
    7
    Rep Power
    20

    Default Re: HELP!!! please

    Great topic title; I personally thought someone was drowning ...

    kind regards,

    Jos
    awinston likes this.
    cenosillicaphobia: the fear for an empty beer glass

Tags for this Thread

Posting Permissions

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