Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 8 of 8

Thread: Problem netbeans gui button event handling

  1. #1
    Member
    Join Date
    Oct 2012
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Problem netbeans gui button event handling

    Hey guys, so my problem is that I created a new Jframe in netbeans, and I added a Jlist and a jButton, the list is supposed to display some books ( I also have a class Book created), so the button I added is named Show books, I created DefaultListModel that will contain the books so that I can pass it after the my List to show Books. So this is the code I wrote for handling event of my button:

    bookmodel.addElement(book1);
    bookmodel.addElement(book2);
    jList2.setModel(bookmodel);

    book1 and book2 are instances of class book that I already created, and of course I created an instance of the class DefaultListModel before. For now it's working, when I click on Show books button, the books I created get displayed in the list, but the problem is that whenever I reclick again on it, they are added another time, etc.. which should not be normal.. How can I do so that when clicking on the button, the books get shown only once and not each time ? Here is the screen of the application:
    Javaproblem - HostingPics.net - Hébergement d'images gratuit
    And here is what happens if I click many times on the show books button:
    java2problem - HostingPics.net - Hébergement d'images gratuit


    I really hope you will help me


  2. #2
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 140 Times in 135 Posts

    Default Re: Problem netbeans gui button event handling

    Where do you decide which books to show? One solution is to create the ListModel elsewhere, and in the show button simply display the list. For more detailed help though, you'll likely have to tell us more and show us more code. Also, your image links are showing as suspicious for my anti-virus program. Consider uploading your images here. But note that code is more helpful for us than images.

  3. #3
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Problem netbeans gui button event handling

    My eyes get bad as I get old. If you post the code on the forum it will be easier to see from my chair...

  4. #4
    Member
    Join Date
    Oct 2012
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Problem netbeans gui button event handling

    Here is the code of my Jframe:
    package gui;
    import java.io.IOException;
    import javax.swing.ImageIcon;
    import javax.swing.JOptionPane;
    import javax.swing.JScrollPane;
    import javax.swing.JTextArea;
    import javax.swing.UIManager;
    import java.awt.Container;
    import javax.swing.*;
            /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
     import amazonapplication.BookList;
     import amazonapplication.Book;
    /**
     *
     * @author 
     */
    public class NewJFrame extends javax.swing.JFrame {
     
        /**
         * Creates new form NewJFrame
         */
        DefaultListModel bookmodel=new DefaultListModel();
        BookList books=new BookList();
        Book book1=new Book("Les miserables","fds","dfsd",655,56,"dsfs","gf");
        Book book2=new Book("Germinal","fds","dfsd",655,56,"dsfs","gf");
     
        public NewJFrame() {
            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() {
     
            jTabbedPane1 = new javax.swing.JTabbedPane();
            jPanel1 = new javax.swing.JPanel();
            jScrollPane2 = new javax.swing.JScrollPane();
            jList2 = new javax.swing.JList();
            jTextField1 = new javax.swing.JTextField();
            jTextField2 = new javax.swing.JTextField();
            jTextField3 = new javax.swing.JTextField();
            jTextField4 = new javax.swing.JTextField();
            jTextField5 = new javax.swing.JTextField();
            jTextField6 = new javax.swing.JTextField();
            jTextField7 = new javax.swing.JTextField();
            jLabel1 = new javax.swing.JLabel();
            jLabel2 = new javax.swing.JLabel();
            jLabel3 = new javax.swing.JLabel();
            jLabel4 = new javax.swing.JLabel();
            jLabel5 = new javax.swing.JLabel();
            jLabel6 = new javax.swing.JLabel();
            jLabel7 = new javax.swing.JLabel();
            jButton1 = new javax.swing.JButton();
            jButton2 = new javax.swing.JButton();
            jButton3 = new javax.swing.JButton();
            jPanel2 = new javax.swing.JPanel();
            jMenuBar1 = new javax.swing.JMenuBar();
            jMenu1 = new javax.swing.JMenu();
            jMenu2 = new javax.swing.JMenu();
     
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
     
            DefaultListModel listModel;
            jList2.setModel(new javax.swing.AbstractListModel() {
                String[] strings = { ""};
                public int getSize() { return strings.length; }
                public Object getElementAt(int i) { return strings[i]; }
            });
            jScrollPane2.setViewportView(jList2);
     
            jTextField1.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jTextField1ActionPerformed(evt);
                }
            });
     
            jTextField2.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jTextField2ActionPerformed(evt);
                }
            });
     
            jTextField4.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jTextField4ActionPerformed(evt);
                }
            });
     
            jLabel1.setText("jLabel1");
     
            jLabel2.setText("jLabel2");
     
            jLabel3.setText("jLabel3");
     
            jLabel4.setText("jLabel4");
     
            jLabel5.setText("jLabel5");
     
            jLabel6.setText("jLabel6");
     
            jLabel7.setText("jLabel7");
     
            jButton1.setText("Show Books");
            jButton1.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jButton1ActionPerformed(evt);
                }
            });
     
            jButton2.setText("Add book");
            jButton2.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jButton2ActionPerformed(evt);
                }
            });
     
            jButton3.setText("Edit book");
     
            javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
            jPanel1.setLayout(jPanel1Layout);
            jPanel1Layout.setHorizontalGroup(
                jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 163, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addGap(56, 56, 56)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addGroup(jPanel1Layout.createSequentialGroup()
                                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                        .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 57, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 57, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                            .addComponent(jLabel5, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 57, Short.MAX_VALUE)
                                            .addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                                    .addGap(52, 52, 52)
                                    .addComponent(jTextField7, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jTextField6, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                            .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, 57, Short.MAX_VALUE)
                                            .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                        .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 57, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGap(52, 52, 52)
                                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jButton1))
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addGap(88, 88, 88)
                            .addComponent(jButton2)
                            .addGap(18, 18, 18)
                            .addComponent(jButton3)))
                    .addContainerGap(140, Short.MAX_VALUE))
            );
            jPanel1Layout.setVerticalGroup(
                jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addContainerGap()
                            .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 332, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addComponent(jButton1)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel1)
                                .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGap(18, 18, 18)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel2)
                                .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGap(28, 28, 28)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addGroup(jPanel1Layout.createSequentialGroup()
                                    .addComponent(jLabel4)
                                    .addGap(18, 18, 18)
                                    .addComponent(jLabel5)
                                    .addGap(18, 18, 18)
                                    .addComponent(jLabel6)
                                    .addGap(12, 12, 12))
                                .addGroup(jPanel1Layout.createSequentialGroup()
                                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(jLabel3))
                                    .addGap(11, 11, 11)
                                    .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(jTextField6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGap(13, 13, 13)))
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(jTextField7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel7))
                            .addGap(48, 48, 48)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jButton2)
                                .addComponent(jButton3))))
                    .addContainerGap(42, Short.MAX_VALUE))
            );
     
            jTabbedPane1.addTab("View books information", jPanel1);
     
            javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
            jPanel2.setLayout(jPanel2Layout);
            jPanel2Layout.setHorizontalGroup(
                jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 579, Short.MAX_VALUE)
            );
            jPanel2Layout.setVerticalGroup(
                jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 385, Short.MAX_VALUE)
            );
     
            jTabbedPane1.addTab("Search books", jPanel2);
     
            jMenu1.setText("File");
            jMenuBar1.add(jMenu1);
     
            jMenu2.setText("Edit");
            jMenuBar1.add(jMenu2);
     
            setJMenuBar(jMenuBar1);
     
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.Alignment.TRAILING)
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jTabbedPane1)
            );
     
            pack();
        }// </editor-fold>                        
     
        private void jTextField4ActionPerformed(java.awt.event.ActionEvent evt) {                                            
            // TODO add your handling code here:
        }                                           
     
        private void jTextField2ActionPerformed(java.awt.event.ActionEvent evt) {                                            
            // TODO add your handling code here:
        }                                           
     
        private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {                                            
            // TODO add your handling code here:
     
        }                                           
     
        private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
     
            bookmodel.addElement(book1);
            bookmodel.addElement(book2);
            jList2.setModel(bookmodel);
     
        }                                        
     
        private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                         
     
            String title= JOptionPane.showInputDialog("What is the title of the book?");
            String author=JOptionPane.showInputDialog("What is the name of the author?");
            String description=JOptionPane.showInputDialog("What is the description of the book?");
            String keywords=JOptionPane.showInputDialog("What are the keywords of the book?"); 
            String category=JOptionPane.showInputDialog("What is the category of the book?");
            String bPrice=JOptionPane.showInputDialog("What is the price of the book?");
            String bIsbn=JOptionPane.showInputDialog("What is the ISBN of the book?");
            int price=Integer.parseInt(bPrice);
            int Isbn=Integer.parseInt(bIsbn);
            Book book3=new Book(title,author,description,price,Isbn,keywords,category);
            bookmodel.addElement(book3);
     
     
        }                                        
     
        /**
         * @param args the command line arguments
         */
        public static void main(String args[]) {
            /* Set the Nimbus look and feel */
            //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
            /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
             * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
             */
            try {
                for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                    if ("Nimbus".equals(info.getName())) {
                        javax.swing.UIManager.setLookAndFeel(info.getClassName());
                        break;
                    }
                }
            } catch (ClassNotFoundException ex) {
                java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (InstantiationException ex) {
                java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (IllegalAccessException ex) {
                java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (javax.swing.UnsupportedLookAndFeelException ex) {
                java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            }
            //</editor-fold>
     
            /* Create and display the form */
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new NewJFrame().setVisible(true);
                }
            });
     
        }
        // Variables declaration - do not modify                     
        private javax.swing.JButton jButton1;
        private javax.swing.JButton jButton2;
        private javax.swing.JButton jButton3;
        private javax.swing.JLabel jLabel1;
        private javax.swing.JLabel jLabel2;
        private javax.swing.JLabel jLabel3;
        private javax.swing.JLabel jLabel4;
        private javax.swing.JLabel jLabel5;
        private javax.swing.JLabel jLabel6;
        private javax.swing.JLabel jLabel7;
        private javax.swing.JList jList2;
        private javax.swing.JMenu jMenu1;
        private javax.swing.JMenu jMenu2;
        private javax.swing.JMenuBar jMenuBar1;
        private javax.swing.JPanel jPanel1;
        private javax.swing.JPanel jPanel2;
        private javax.swing.JScrollPane jScrollPane2;
        private javax.swing.JTabbedPane jTabbedPane1;
        private javax.swing.JTextField jTextField1;
        private javax.swing.JTextField jTextField2;
        private javax.swing.JTextField jTextField3;
        private javax.swing.JTextField jTextField4;
        private javax.swing.JTextField jTextField5;
        private javax.swing.JTextField jTextField6;
        private javax.swing.JTextField jTextField7;
        // End of variables declaration                   
     
     
    }

    I am using netbeans so I just drag and drop components that I need.

    Here is the code of my class Book:

     
     
    package amazonapplication;
     
     
    public class Book {
        private int isbn;
        private String authors;
        private String title;
        private String description;
        private int price;
        private String keywords;
        private String category;
     
        public Book(String pTitle,String pAuthors,String pDescription,int pPrice,int pIsbn,String pKeywords,String pCategory){
         this.authors=pAuthors;
         this.title=pTitle;        
         this.description=pDescription;        
         this.price=pPrice;  
         this.keywords=pKeywords;        
         this.category=pCategory;  
         this.isbn=pIsbn;
        }
     
        public void setAuthors(String authors){
            this.authors=authors;
        }
        public void setTitle(String title){
            this.title=title;
        }
        public void setDescription(String description){
            this.description=description;
        }
        public void setIsbn(int isbn){
            this.isbn=isbn;
        }
        public void setPrice(int price){
            this.price=price;
        }
        public void setKeywords(String keywords){
            this.keywords=keywords;
        }
        public void setCategory(String category){
            this.category=category;
        }
        public int getIsbn(){
            return isbn;
        }
        public String getAuthors()  {
            return authors;
        }  
        public String getTitle()  {
            return title;
        }
        public String getDescription()  {
            return description;
        } 
        public String getKeywords()  {
            return keywords;
        }
        public String getCategory()  {
            return category;
                }
        public int getPrice()  {
            return price;
        }
        @Override
        public String toString(){
            return this.title;
        }
     
    }

  5. #5
    Member
    Join Date
    Oct 2012
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Problem netbeans gui button event handling

    Noone?

  6. #6
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 140 Times in 135 Posts

    Default Re: Problem netbeans gui button event handling

    Your code is only doing what you tell it to do. Here:

        private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                          
            bookmodel.addElement(book1);
            bookmodel.addElement(book2);
            jList2.setModel(bookmodel);
     
        }

    You are telling the program to add the two book items to the model each time the button is pressed. If you don't want this to happen then you will have to change the code. I'm confused though: what exactly do you want to have happen here? If you just want to show 2 books and nothing else, then create your DefaultListModel, stuff it with the books in the class's constructor and in your handler method above, put the ListModel into the JList, but don't add Books to the model if you don't want it to grow.

    Don't rely on NetBean's default variable naming since it will cause a debugging nightmare. What does jButton1 do? Will your future self remember what its purpose is 6 months from now? Instead give your variables meaningful names so that both we, your instructors, and your future self will know at a glance what they're supposed to be doing.

  7. #7
    Member
    Join Date
    Oct 2012
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Problem netbeans gui button event handling

    Well what I actually wanted to do is have a List that show all the book that are available, but also, when we add a book , the list should be updated so we wee all the books. Well this is the best I found to do it, I couldn't do it better.
    Also , if you noticed I have many textfield next to the list, and NORMALLY, what should happen is that whenever i click on a book in the list, its information should be displayed in the textfields, well I think that's too hard for me, I have no idea how to do it.

  8. #8
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Problem netbeans gui button event handling

    well I think that's too hard for me
    It is too hard for me too. Break the problem up multiple problems and solve one problem at a time.
    You want the values of a book to show in the text areas, right? That is a problem. Smaller problems that make up this problem could be listed as show the first value in the first box, show the next value in the next box, show the next value in the next box.
    Once you get it to work for one, you can make it work for many by doing the same thing over again, but relating to different values and different fields. (This should be a hint as to some reusable code, and perhaps a hint or two on parameters to a function or something of that nature)

    I have no idea how to do it
    Neither do I. But I think both of us could perform each individual step necessary once the problem is broken up into the necessary steps. So without worrying about code, try to write up a plan of attack on solving the first problem first.

Similar Threads

  1. GUI Scientific Calculator. Please help! (Event Handling)
    By BlackGazer in forum What's Wrong With My Code?
    Replies: 1
    Last Post: July 9th, 2011, 07:14 AM
  2. Event Handling
    By maress in forum What's Wrong With My Code?
    Replies: 0
    Last Post: January 24th, 2011, 03:29 AM
  3. newbie GUI/ event handling problem
    By zyspt in forum What's Wrong With My Code?
    Replies: 1
    Last Post: May 10th, 2010, 11:36 AM
  4. JButton event handling.
    By Prof in forum AWT / Java Swing
    Replies: 6
    Last Post: February 3rd, 2010, 10:29 AM
  5. Event handling
    By subhvi in forum AWT / Java Swing
    Replies: 3
    Last Post: August 26th, 2009, 11:20 AM