Results 1 to 6 of 6
  1. #1
    raihan26 is offline Member
    Join Date
    Mar 2010
    Posts
    18
    Rep Power
    0

    Default Problem With GUI of Net Beans

    I have created a GUI on the Netbeans.... and I wanted to make a cross sign (x)
    at the same point where user is clicking on the map.... As I have done it successfully.... but the problem is that when I am clicking on the map the cross sign is not coming at the same point.... it is coming very far from that point where i am clicking.... for example I have attached the sample image of my application.... when I am clicking on L of Los Angeles in the given map.... the red cross sign is showing very far from it... I don't why is it happening so.... Anybody any idea on this what can be the problem... This is my code...

    Java Code:
     public class frame extends javax.swing.JFrame implements MouseListener, MouseMotionListener {
    
        /** Creates new form frame */
        public frame() {
            initComponents();
        }
    
        /** This method is called from within the constructor to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
         */
        @SuppressWarnings("unchecked")
        // <editor-fold defaultstate="collapsed" desc="Generated Code">
        private void initComponents() {
    
            jPanel1 = new javax.swing.JPanel();
            jLabel1 = new javax.swing.JLabel();
            jPanel2 = new javax.swing.JPanel();
            jLabel2 = new javax.swing.JLabel();
            jRadioButton1 = new javax.swing.JRadioButton();
            jRadioButton2 = new javax.swing.JRadioButton();
            jRadioButton3 = new javax.swing.JRadioButton();
            jRadioButton4 = new javax.swing.JRadioButton();
            jTextField1 = new javax.swing.JTextField();
            jLabel3 = new javax.swing.JLabel();
            jTextField2 = new javax.swing.JTextField();
            jTextField3 = new javax.swing.JTextField();
            jLabel4 = new javax.swing.JLabel();
            jCheckBox1 = new javax.swing.JCheckBox();
            jCheckBox2 = new javax.swing.JCheckBox();
            jTextField4 = new javax.swing.JTextField();
            jButton1 = new javax.swing.JButton();
            jButton2 = new javax.swing.JButton();
    
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    
            jPanel1.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 1, true));
            jPanel1.setPreferredSize(new java.awt.Dimension(600, 500));
            jPanel1.addMouseListener(new java.awt.event.MouseAdapter() {
                public void mouseClicked(java.awt.event.MouseEvent evt) {
                    jPanel1MouseClicked(evt);
                }
            });
    
            jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
            jLabel1.setIcon(new javax.swing.ImageIcon("C:\\photos\\la.jpg")); // NOI18N
            jLabel1.setPreferredSize(new java.awt.Dimension(600, 500));
            jLabel1.addMouseListener(new java.awt.event.MouseAdapter() {
                public void mouseClicked(java.awt.event.MouseEvent evt) {
                    jLabel1MouseClicked(evt);
                }
                public void mouseEntered(java.awt.event.MouseEvent evt) {
                    jLabel1MouseEntered(evt);
                }
                public void mousePressed(java.awt.event.MouseEvent evt) {
                    jLabel1MousePressed(evt);
                }
            });
            jLabel1.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
                public void mouseMoved(java.awt.event.MouseEvent evt) {
                    jLabel1MouseMoved(evt);
                }
            });
    
            javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
            jPanel1.setLayout(jPanel1Layout);
            jPanel1Layout.setHorizontalGroup(
                jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 601, Short.MAX_VALUE)
            );
            jPanel1Layout.setVerticalGroup(
                jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            );
    
            javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
            jPanel2.setLayout(jPanel2Layout);
            jPanel2Layout.setHorizontalGroup(
                jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 362, Short.MAX_VALUE)
            );
            jPanel2Layout.setVerticalGroup(
                jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, 359, Short.MAX_VALUE)
            );
    
            jRadioButton1.setFont(new java.awt.Font("Rockwell", 1, 14));
            jRadioButton1.setText("Nearest Neighbour");
    
            jRadioButton2.setFont(new java.awt.Font("Rockwell", 1, 14));
            jRadioButton2.setText("Range");
    
            jRadioButton3.setFont(new java.awt.Font("Rockwell", 1, 14));
            jRadioButton3.setText("Find Matching Restaurant");
    
            jRadioButton4.setFont(new java.awt.Font("Rockwell", 1, 14));
            jRadioButton4.setText("Find Relevant Photos");
    
            jTextField1.setText("jTextField1");
            jTextField1.addMouseListener(new java.awt.event.MouseAdapter() {
                public void mouseClicked(java.awt.event.MouseEvent evt) {
                    jTextField1MouseClicked(evt);
                }
            });
    
            jLabel3.setFont(new java.awt.Font("Rockwell", 1, 14));
            jLabel3.setText("Current Coordinates (X,Y)");
    
            jTextField2.setEditable(false);
            jTextField2.setFont(new java.awt.Font("Rockwell", 1, 18));
    
            jTextField3.setText("jTextField3");
    
            jLabel4.setFont(new java.awt.Font("Rockwell", 1, 14));
            jLabel4.setText("Active Features");
    
            jCheckBox1.setFont(new java.awt.Font("Rockwell", 1, 14));
            jCheckBox1.setText("Restaurants");
    
            jCheckBox2.setFont(new java.awt.Font("Rockwell", 1, 14));
            jCheckBox2.setText("Photos");
    
            jTextField4.setText("jTextField4");
    
            jButton1.setFont(new java.awt.Font("Rockwell", 1, 14));
            jButton1.setText("Clear");
    
            jButton2.setFont(new java.awt.Font("Rockwell", 1, 14));
            jButton2.setText("Submit Query");
    
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGroup(layout.createSequentialGroup()
                                    .addGap(14, 14, 14)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 348, Short.MAX_VALUE)
                                        .addComponent(jRadioButton2)
                                        .addComponent(jRadioButton1)
                                        .addComponent(jRadioButton4)
                                        .addComponent(jRadioButton3))))
                            .addGap(52, 52, 52))
                        .addGroup(layout.createSequentialGroup()
                            .addGap(31, 31, 31)
                            .addComponent(jLabel3)
                            .addGap(18, 18, 18)
                            .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(78, 78, 78)))
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 600, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGroup(layout.createSequentialGroup()
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(layout.createSequentialGroup()
                                    .addGap(44, 44, 44)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(jCheckBox2)
                                        .addComponent(jCheckBox1)))
                                .addGroup(layout.createSequentialGroup()
                                    .addGap(25, 25, 25)
                                    .addComponent(jLabel4))
                                .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, 244, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addGroup(layout.createSequentialGroup()
                                    .addGap(220, 220, 220)
                                    .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGap(26, 26, 26))
                                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 195, Short.MAX_VALUE)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addComponent(jButton1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(jButton2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                    .addGap(25, 25, 25))))))
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(18, 18, 18)
                            .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(18, 18, 18)
                            .addComponent(jRadioButton1)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jRadioButton2)
                            .addGap(18, 18, 18)
                            .addComponent(jRadioButton3)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                            .addComponent(jRadioButton4))
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 500, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addGroup(layout.createSequentialGroup()
                                    .addComponent(jLabel4)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(jCheckBox1))
                                .addComponent(jTextField4))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jCheckBox2)))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel3)
                                .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGap(20, 20, 20))
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                            .addComponent(jButton1)
                            .addGap(18, 18, 18)
                            .addComponent(jButton2)
                            .addGap(40, 40, 40))))
            );
    
            pack();
        }// </editor-fold>
    
       public void mouseMoved(java.awt.event.MouseEvent evt) {
           if (evt.getSource() == jLabel1) {
              frame.this.jLabel1MouseMoved(evt);
            }
        }
    public void mouseEntered(java.awt.event.MouseEvent evt) {
            //if (evt.getSource() == jLabel1) {
              //  frame.this.jLabel1MouseEntered(evt);
            //}
        }
    public void mouseDragged(java.awt.event.MouseEvent evt) {
    
        }
    public void mouseExited(java.awt.event.MouseEvent evt) {
    
        }
    public void mouseReleased(java.awt.event.MouseEvent evt) {
    
        }
    public void mousePressed(java.awt.event.MouseEvent evt) {
    
        }
    public void mouseClicked(java.awt.event.MouseEvent evt) {
    
        }
    
        private void jLabel1MouseMoved(java.awt.event.MouseEvent evt) {                                   
            // TODO add your handling code here:
           eventOutput("", evt);
    
        }                                  
    
        private void jLabel1MouseEntered(java.awt.event.MouseEvent evt) {                                     
            // TODO add your handling code here:
            eventOutput("", evt);
        }                                    
    
        private void jLabel1MousePressed(java.awt.event.MouseEvent evt) {
            // TODO add your handling code here:
                
        }
    
        private void jLabel1MouseClicked(java.awt.event.MouseEvent evt) {
            // TODO add your handling code here:
                 int x = evt.getX();  // x-coordinate where user clicked.
                 int y = evt.getY();  // y-coordinate where user clicked.
                 System.out.println(" " +x);
                 System.out.println(" " +y);
    
                 Graphics g = getGraphics();  // Graphics context for drawing
                                              // directly on this JPanel.
                  Graphics2D g2 = (Graphics2D) g;
                  Graphics2D g1 = (Graphics2D) g;
                 if ( evt.isMetaDown() ) {
                        // User right-clicked at the point (x,y).
                        // Draw a blue oval centered at the point (x,y).
                        // (A black outline around the oval will make it
                        // more distinct when ovals and rects overlap.)
                     g2.setColor(Color.red);
                     g2.setStroke(new BasicStroke(2));
                     g1.setStroke(new BasicStroke(4));
    
                     g2.draw(new Line2D.Double(x+5, y+5, x-5, y-5));
                     g1.draw(new Line2D.Double(x+5, y-5, x-5, y+5));
                   //  g2.drawString("", x, 10);
                     //g.fillOval( x - 30, y - 15, 60, 30 );
                     //g.setColor(Color.black);
                     //g.drawOval( x - 30, y - 15, 60, 30 );
                 }
        }
    
        private void jPanel1MouseClicked(java.awt.event.MouseEvent evt) {
            // TODO add your handling code here:
        }
    
        private void jTextField1MouseClicked(java.awt.event.MouseEvent evt) {
            // TODO add your handling code here:
        }
    void eventOutput(String eventDescription, MouseEvent evt) {
            jTextField2.setText(eventDescription
                    + " (" + evt.getX() + "," + evt.getY() + ")"
                    );
          //  jTextField2.setCaretPosition(jTextField2.getDocument().getLength());
        }
        /**
        * @param args the command line arguments
        */
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new frame().setVisible(true);
                }
            });
        }

  2. #2
    raihan26 is offline Member
    Join Date
    Mar 2010
    Posts
    18
    Rep Power
    0

    Default

    This is sample image of my application for the above program....... Any guess what can be the problem....
    Attached Thumbnails Attached Thumbnails Problem With GUI of Net Beans-test.jpg  

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    Means that your coordinates are not correct. At which point you keep the origin as the UI, left-top corner or right-bottom corner or any other location?

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

    Default

    Raihan: Has this been cross-posted on JavaRanch?

    Edit: I have answered my own question and see that yes it has. Raihan, please read the JavaRanch FAQ regarding crossposting without notification. The same rules and etiquette apply here. Thank you for your cooperation.
    Last edited by Fubarable; 04-02-2010 at 07:38 PM.

  5. #5
    raihan26 is offline Member
    Join Date
    Mar 2010
    Posts
    18
    Rep Power
    0

    Default

    Yeah I have posted over there also just for knowing what wrong I am doing.... but I have figured it out what is the problem... Thanks anywaz

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by Fubarable View Post
    Raihan: Has this been cross-posted on JavaRanch?

    Edit: I have answered my own question and see that yes it has. Raihan, please read the JavaRanch FAQ regarding crossposting without notification. The same rules and etiquette apply here. Thank you for your cooperation.
    I quite from here then.

Similar Threads

  1. Problem in Net beans
    By isurues in forum NetBeans
    Replies: 3
    Last Post: 06-13-2008, 12:58 PM
  2. How to make Beans Lazily-instantiating beans
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 03-30-2008, 11:10 AM
  3. beans
    By mcal in forum New To Java
    Replies: 0
    Last Post: 03-03-2008, 07:34 PM
  4. How to make Beans Lazily-instantiating beans
    By JavaBean in forum Java Tip
    Replies: 0
    Last Post: 09-26-2007, 09:41 PM
  5. problem with ejb 3.0 entity beans with manyToMany relationship
    By makcro in forum Enterprise JavaBeans (EJB)
    Replies: 0
    Last Post: 07-26-2007, 08:37 PM

Posting Permissions

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