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 3 of 3

Thread: result set array button

  1. #1
    Junior Member dread_arisawa's Avatar
    Join Date
    Aug 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default result set array button

    hi everyone i try to create some program that made button from the array and this array get its items form result set , can you help me because i have try it there's no error message but program can't be launch where i've got wrong and once morei am using netbeans ,

     
    import java.sql.*;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import java.awt.*;
    import java.awt.event.*;
    import javax.media.Controller;
    import javax.swing.*;
     
     
    public class betapoint extends javax.swing.JFrame {
     
        public String[] buttonTxt;
        JButton[] buttons = new JButton[buttonTxt.length];
        public betapoint() {
            initComponents();
        }
        public void ButtonPanel() {
            for (int i = 0; i < buttons.length; i++) {
            buttons[i] = new JButton(buttonTxt[i]);
            buttons[i].setSize(80, 80);
            buttons[i].addActionListener((ActionListener) jPanel1);
            this.add(buttons[i]);
    }
    }
     
     
        public void getshow() {
     
           float nilai = Float.parseFloat(jTextField1.getText());
     
           try {
    			Class.forName(Koneksi.driver);
     
                            Connection konek1;
                            konek1 = DriverManager.getConnection (Koneksi.database, Koneksi.user, Koneksi.pass);
                            Statement st1 = konek1.createStatement();
                            ResultSet rs1 = st1.executeQuery("SELECT no FROM lookout WHERE nilai <='" + nilai + "'");
                            while(rs1.next())
    				{ 
                                String buttonTxt = rs1.getString("no");
                                System.out.println(buttonTxt);
    			    }
       			konek1.close();
    		}
     
                    catch (SQLException ex) {
                    Logger.getLogger(betapoint.class.getName()).log(Level.SEVERE, null, ex);
                }            catch (ClassNotFoundException ex){
                    System.out.println("ERROR ->>> can't open Database . . .");
                    Logger.getLogger(betapoint.class.getName()).log(Level.SEVERE, null, ex);
                }
        }
    private void initComponents() {
     
            jButton1 = new javax.swing.JButton();
            jTextField1 = new javax.swing.JTextField();
            jPanel1 = new javax.swing.JPanel();
     
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
     
            jButton1.setText("ok");
     
     private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
            getshow();
        } 
     
    public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new betapoint().setVisible(true);
     
                }
            });
        }
     
    private javax.swing.JButton jButton1;
     private javax.swing.JPanel jPanel1;
    private javax.swing.JTextField jTextField1;


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: result set array button

    This statement looks strange:
    buttons[i].addActionListener((ActionListener) jPanel1);

    Where do you create jPanel1 that makes it an ActionListener?

    You need to read about how to create and use listeners.


    You have two variables with the same name:

    public String[] buttonTxt;
    and
    String buttonTxt = rs1.getString("no");

    You need to resolve this. One must be wrong.
    Last edited by Norm; August 17th, 2010 at 02:42 PM.

  3. #3
    Junior Member dread_arisawa's Avatar
    Join Date
    Aug 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: result set array button

    thanks for quick respond norm and sorry for late reply

    yes i guess i must learn more about ActionListener

    the second problem i forgot to delete string in the second variable

    its must like this

     
    public String[] buttonTxt;
     
    .....
     
    buttonTxt = rs1.getString("no");

Similar Threads

  1. Return result from JOptionPane to JFrame
    By cselic in forum AWT / Java Swing
    Replies: 7
    Last Post: May 13th, 2010, 01:17 PM
  2. Please help with Actionlistener-Button
    By ashleykathy in forum AWT / Java Swing
    Replies: 1
    Last Post: March 4th, 2010, 08:21 PM
  3. Want to move my button away from center.
    By Fendaril in forum AWT / Java Swing
    Replies: 2
    Last Post: November 6th, 2009, 10:05 PM
  4. how to using button to change linechart
    By NARs in forum AWT / Java Swing
    Replies: 3
    Last Post: October 30th, 2009, 12:53 PM
  5. Problem of getting result than SQL to JTable
    By MS_Dark in forum Exceptions
    Replies: 1
    Last Post: March 10th, 2009, 06:26 AM