how can I create gui pop-ups

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #16
    You may (or may not) also find this article informative.

    P.S Don't forget to use code tags when posting code.

    Comment

    • kenrocks
      New Member
      • Oct 2008
      • 25

      #17
      can u please give me a brief example of how to use the show method.,......I still can't get a hold of the components of this method such as the invoker.waaaaaa a..plsss..help

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #18
        Originally posted by kenrocks
        can u please give me a brief example of how to use the show method.,......I still can't get a hold of the components of this method such as the invoker.waaaaaa a..plsss..help
        Try this in your actionPerformed method:

        Code:
        popup.show(this, 30, 10);
        It shows the popup menu at location (30,10) in the frame. Make sure that you
        fix the errors I described above as well.

        kind regards,

        Jos

        Comment

        • kenrocks
          New Member
          • Oct 2008
          • 25

          #19
          Originally posted by JosAH
          Try this in your actionPerformed method:

          Code:
          popup.show(this, 30, 10);
          It shows the popup menu at location (30,10) in the frame. Make sure that you
          fix the errors I described above as well.

          kind regards,

          Jos
          what does the "this" do?

          Comment

          • r035198x
            MVP
            • Sep 2006
            • 13225

            #20
            Originally posted by kenrocks
            what does the "this" do?
            That's the currently executing instance
            May I suggest going through Sun's Java tutorial at this stage. There is no point in trying to create GUI programs before grasping the basic concepts of the language.

            Comment

            • kenrocks
              New Member
              • Oct 2008
              • 25

              #21
              how come nothing happens?

              Comment

              • r035198x
                MVP
                • Sep 2006
                • 13225

                #22
                Originally posted by kenrocks
                how come nothing happens?
                You mean you see nothing? Well that depends on what your code is looking like now. e.g. Did you correct all the mistakes pointed to by Jos above?

                P.S You won't be making those mistakes after reading that tutorial that I suggested above.

                Comment

                • JosAH
                  Recognized Expert MVP
                  • Mar 2007
                  • 11453

                  #23
                  Originally posted by kenrocks
                  how come nothing happens?
                  I don't think programming is for your because

                  1) you don't read the tips and hints given to you;
                  2) you don't read tutorials, you just blindly guess;
                  3) you're not willing to experiment a bit with your own code.

                  Here; try your (slightly modified) class:

                  Code:
                  import java.awt.*;
                  import java.awt.event.*;
                  import javax.swing.*;
                  import javax.swing.event.*;
                  
                  public class Popup extends JPanel implements ActionListener {
                  
                  private JButton jcomp1;
                  JPopupMenu popup = new JPopupMenu();
                  //Up a=new Up();
                  public Popup() {
                  //construct components
                  jcomp1 = new JButton ("Button 1");
                  
                  //adjust size and set layout
                  setPreferredSize (new Dimension (150, 63));
                  setLayout (null);
                  
                  //add components
                  add (jcomp1);
                  
                  //set component bounds (only needed by Absolute Positioning)
                  jcomp1.setBounds (10, 15, 100, 20);
                  JMenuItem menuItem;
                  
                  //Create the popup menu.
                  menuItem = new JMenuItem("A popup menu item");
                  jcomp1.addActionListener(this);
                  popup.add(menuItem);
                  menuItem = new JMenuItem("Another popup menu item");
                  popup.add(menuItem);
                  
                  }
                  public void actionPerformed(ActionEvent e) {
                  
                  	popup.show(this, 30, 10);
                  }
                  
                  
                  public static void main (String[] args) {
                  JFrame frame = new JFrame ("MyPanel");
                  frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
                  frame.getContentPane().add (new Popup());
                  frame.pack();
                  frame.setVisible (true);
                  }
                  }
                  I consider this thread closed after this spoonfeeding.

                  Jos (moderator)

                  Comment

                  Working...