Results 1 to 15 of 15

Thread: Java question

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1

    Default Re: Java question

    Could you simply upload the entire source file as text, that way I can see how the various methods and variables ought to fit together.
    - Tellos Athenaios
    CUF tool - XIDX - PACK tool - SD tool - EVT tool - EB Install Guide - How to track down loading CTD's - EB 1.1 Maps thread


    ὁ δ᾽ ἠλίθιος ὣσπερ πρόβατον βῆ βῆ λέγων βαδίζει” – Kratinos in Dionysalexandros.

  2. #2
    the G-Diffuser Senior Member pevergreen's Avatar
    Join Date
    Nov 2006
    Location
    Brisbane, Australia
    Posts
    11,585
    Blog Entries
    2

    Default Re: Java question

    http://www.filefront.com/17312342/ContactEditorUI.txt/
    http://www.filefront.com/17312343/ContactEditorUI.java/
    http://www.filefront.com/17312344/ContactEditorUI.form/

    Spoiler Alert, click show to read: 
    Code:
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    
    /*
     * ContactEditorUI.java
     *
     * Created on 15/09/2010, 1:13:56 PM
     */
    
    package my.contacteditor;
    
    import java.io.BufferedWriter;
    import java.io.File;
    import java.io.FileWriter;
    
    /**
     *
     * @author 408797
     */
    public class ContactEditorUI extends javax.swing.JFrame {
    
        /** Creates new form ContactEditorUI */
        public ContactEditorUI() {
            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() {
    
            buttonGroup1 = new javax.swing.ButtonGroup();
            jPanel1 = new javax.swing.JPanel();
            jLabel1 = new javax.swing.JLabel();
            txtname = new javax.swing.JTextField();
            jLabel2 = new javax.swing.JLabel();
            txtsurname = new javax.swing.JTextField();
            jLabel3 = new javax.swing.JLabel();
            jLabel4 = new javax.swing.JLabel();
            txttile = new javax.swing.JTextField();
            txtnickname = new javax.swing.JTextField();
            jLabel5 = new javax.swing.JLabel();
            jComboBox1 = new javax.swing.JComboBox();
            btnname = new javax.swing.JButton();
            jPanel2 = new javax.swing.JPanel();
            jLabel6 = new javax.swing.JLabel();
            txtemail = new javax.swing.JTextField();
            jScrollPane1 = new javax.swing.JScrollPane();
            listemail = new javax.swing.JList();
            btnadd = new javax.swing.JButton();
            jButton2 = new javax.swing.JButton();
            btnremove = new javax.swing.JButton();
            jButton4 = new javax.swing.JButton();
            jLabel7 = new javax.swing.JLabel();
            jRadioButton1 = new javax.swing.JRadioButton();
            jRadioButton2 = new javax.swing.JRadioButton();
            jRadioButton3 = new javax.swing.JRadioButton();
            jButton5 = new javax.swing.JButton();
            jButton6 = new javax.swing.JButton();
    
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    
            jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Name", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 12))); // NOI18N
    
            jLabel1.setText("First Name:");
    
            txtname.setText(" ");
    
            jLabel2.setText("Last Name:");
    
            txtsurname.setText(" ");
    
            jLabel3.setText("Title:");
    
            jLabel4.setText("Nickname:");
    
            txttile.setText(" ");
    
            txtnickname.setText(" ");
    
            jLabel5.setText("Display Format:");
    
            btnname.setText("Add");
            btnname.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    btnnameActionPerformed(evt);
                }
            });
    
            javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
            jPanel1.setLayout(jPanel1Layout);
            jPanel1Layout.setHorizontalGroup(
                jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                    .addContainerGap()
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(btnname, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(jLabel5)
                                .addComponent(jLabel1)
                                .addComponent(jLabel3))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(jPanel1Layout.createSequentialGroup()
                                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(txtname, javax.swing.GroupLayout.DEFAULT_SIZE, 49, Short.MAX_VALUE)
                                        .addComponent(txttile, javax.swing.GroupLayout.DEFAULT_SIZE, 49, Short.MAX_VALUE))
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.TRAILING)
                                        .addComponent(jLabel4, javax.swing.GroupLayout.Alignment.TRAILING))
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(txtnickname, javax.swing.GroupLayout.DEFAULT_SIZE, 331, Short.MAX_VALUE)
                                        .addComponent(txtsurname, javax.swing.GroupLayout.DEFAULT_SIZE, 331, Short.MAX_VALUE)))
                                .addComponent(jComboBox1, 0, 454, Short.MAX_VALUE))))
                    .addContainerGap())
            );
            jPanel1Layout.setVerticalGroup(
                jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel1)
                        .addComponent(txtname, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel2)
                        .addComponent(txtsurname, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel3)
                        .addComponent(jLabel4)
                        .addComponent(txtnickname, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(txttile, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel5)
                        .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btnname))
            );
    
            jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "E-mail", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 12))); // NOI18N
    
            jLabel6.setText("E-mail Address:");
    
            txtemail.setText(" ");
    
            jScrollPane1.setViewportView(listemail);
    
            btnadd.setText("Add");
            btnadd.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    btnaddActionPerformed(evt);
                }
            });
    
            jButton2.setText("Edit");
    
            btnremove.setText("Remove");
            btnremove.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    btnremoveActionPerformed(evt);
                }
            });
    
            jButton4.setText("Advanced");
    
            jLabel7.setText("Mail Format:");
    
            buttonGroup1.add(jRadioButton1);
            jRadioButton1.setText("HTML");
            jRadioButton1.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jRadioButton1ActionPerformed(evt);
                }
            });
    
            buttonGroup1.add(jRadioButton2);
            jRadioButton2.setText("Plain Text");
    
            buttonGroup1.add(jRadioButton3);
            jRadioButton3.setText("Custom");
    
            javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
            jPanel2.setLayout(jPanel2Layout);
            jPanel2Layout.setHorizontalGroup(
                jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel2Layout.createSequentialGroup()
                    .addContainerGap()
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel2Layout.createSequentialGroup()
                            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addGroup(jPanel2Layout.createSequentialGroup()
                                    .addComponent(jLabel6)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(txtemail, javax.swing.GroupLayout.PREFERRED_SIZE, 367, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 451, Short.MAX_VALUE))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(jButton4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(btnremove, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(btnadd, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .addContainerGap(11, Short.MAX_VALUE))
                        .addGroup(jPanel2Layout.createSequentialGroup()
                            .addComponent(jLabel7)
                            .addContainerGap(490, Short.MAX_VALUE))))
                .addGroup(jPanel2Layout.createSequentialGroup()
                    .addGap(69, 69, 69)
                    .addComponent(jRadioButton1)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addComponent(jRadioButton2)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addComponent(jRadioButton3)
                    .addContainerGap(301, Short.MAX_VALUE))
            );
    
            jPanel2Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {btnadd, btnremove, jButton2, jButton4});
    
            jPanel2Layout.setVerticalGroup(
                jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel2Layout.createSequentialGroup()
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel2Layout.createSequentialGroup()
                            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel6)
                                .addComponent(txtemail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 121, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(jPanel2Layout.createSequentialGroup()
                            .addContainerGap()
                            .addComponent(btnadd)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jButton2)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(btnremove)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jButton4)))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addComponent(jLabel7)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jRadioButton1)
                        .addComponent(jRadioButton2)
                        .addComponent(jRadioButton3))
                    .addContainerGap(17, Short.MAX_VALUE))
            );
    
            jButton5.setText("OK");
    
            jButton6.setText("Cancel");
    
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addContainerGap()
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .addContainerGap())
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                            .addComponent(jButton5)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jButton6)
                            .addGap(31, 31, 31))))
            );
    
            layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jButton5, jButton6});
    
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jButton5)
                        .addComponent(jButton6))
                    .addContainerGap(54, Short.MAX_VALUE))
            );
    
            pack();
        }// </editor-fold>                        
    
        private void jRadioButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                              
            // TODO add your handling code here:
        }                                             
    
        private void btnaddActionPerformed(java.awt.event.ActionEvent evt) {                                       
            String name = txtemail.getText();
            int index = listemail.getSelectedIndex(); //get selected index
                if (index == -1) { //no selection, so insert at beginning
                    index = 0;
                } else {           //add after the selected item
                    index++;
        }
    
        listModel.insertElementAt(txtemail.getText(), index);
    
        //Reset the text field.
        txtemail.requestFocusInWindow();
        txtemail.setText("");
    
        //Select the new item and make it visible.
        listemail.setSelectedIndex(index);
        listemail.ensureIndexIsVisible(index);
    
    
    
            // TODO add your handling code here:
        }                                      
    
        private void btnremoveActionPerformed(java.awt.event.ActionEvent evt) {                                          
             int index = listemail.getSelectedIndex();
             listemail.remove(index);
    
            int size = listModel.getSize();
    
            if (size == 0) { //No email records left, disable the button
                btnremove.setEnabled(false);
    
            } else { //Select an index.
                if (index == listModel.getSize()) {
                    //removed item in last position
                    index--;
                }
    
            listemail.setSelectedIndex(index);
            listemail.ensureIndexIsVisible(index);
        }
    
        }                                         
    
    
        private void btnnameActionPerformed(java.awt.event.ActionEvent evt) {                                        
            String name = txtname.getText();
            String surname = txtsurname.getText();
            String title = txttitle.getText();
            String nickname = txtnickname.getText();
    
            File outFile = new File("Customer.txt");
            FileWriter out = new FileWriter(outFile, true);
        FileUtils.writeStringToFile(name, surname, nickname, title);
            out.close();
        }
    
    
            // TODO add your handling code here:
        }                                       
    public class Program
    {
            /**
        * @param args the command line arguments
        */
       public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new ContactEditorUI().setVisible(true);
                }
            });
        }
    
        // Variables declaration - do not modify                     
        private javax.swing.JButton btnadd;
        private javax.swing.JButton btnname;
        private javax.swing.JButton btnremove;
        private javax.swing.ButtonGroup buttonGroup1;
        private javax.swing.JButton jButton2;
        private javax.swing.JButton jButton4;
        private javax.swing.JButton jButton5;
        private javax.swing.JButton jButton6;
        private javax.swing.JComboBox jComboBox1;
        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.JPanel jPanel1;
        private javax.swing.JPanel jPanel2;
        private javax.swing.JRadioButton jRadioButton1;
        private javax.swing.JRadioButton jRadioButton2;
        private javax.swing.JRadioButton jRadioButton3;
        private javax.swing.JScrollPane jScrollPane1;
        private javax.swing.JList listemail;
        private javax.swing.JTextField txtemail;
        private javax.swing.JTextField txtname;
        private javax.swing.JTextField txtnickname;
        private javax.swing.JTextField txtsurname;
        private javax.swing.JTextField txttile;
        // End of variables declaration                   
    
    }
    Quote Originally Posted by TosaInu
    The org will be org until everyone calls it a day.

    Quote Originally Posted by KukriKhan View Post
    but I joke. Some of my best friends are Vietnamese villages.
    Quote Originally Posted by Lemur
    Anyone who wishes to refer to me as peverlemur is free to do so.

  3. #3

    Default Re: Java question

    Simply overwrite both form & java file with these contents:

    Java: http://pastebin.com/dj4gHDu4
    Form: http://pastebin.com/tTUygE7k

    And then you may want to read carefully to see what I changed and where.
    - Tellos Athenaios
    CUF tool - XIDX - PACK tool - SD tool - EVT tool - EB Install Guide - How to track down loading CTD's - EB 1.1 Maps thread


    ὁ δ᾽ ἠλίθιος ὣσπερ πρόβατον βῆ βῆ λέγων βαδίζει” – Kratinos in Dionysalexandros.

  4. #4
    the G-Diffuser Senior Member pevergreen's Avatar
    Join Date
    Nov 2006
    Location
    Brisbane, Australia
    Posts
    11,585
    Blog Entries
    2

    Default Re: Java question

    Thank you so very much Tellos, its still throwing an error though. it doesn't recognise this:

    Code:
    import org.apache.commons.FileUtils;
    package org.apache.commons does not exist

    Unused Import
    Output from running is:
    Code:
    run:
    java.lang.ExceptionInInitializerError
    Caused by: java.lang.RuntimeException: Uncompilable source code - package org.apache.commons does not exist
            at my.contacteditor.ContactEditorUI.<clinit>(ContactEditorUI.java:16)
    Could not find the main class: my.contacteditor.ContactEditorUI.  Program will exit.
    Exception in thread "main" Java Result: 1
    BUILD SUCCESSFUL (total time: 0 seconds)
    I removed it as a test: it runs, it adds things to the email list, but doesnt remove and it doesnt write to file, but it doesnt throw an error. It does create the text file though.

    Error of trying to remove:
    Code:
    run:
    Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: Array index out of range: 7
            at java.awt.Container.remove(Container.java:1136)
            at my.contacteditor.ContactEditorUI.btnremoveActionPerformed(ContactEditorUI.java:342)
            at my.contacteditor.ContactEditorUI.access$200(ContactEditorUI.java:22)
            at my.contacteditor.ContactEditorUI$3.actionPerformed(ContactEditorUI.java:171)
            at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
            at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
            at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
            at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
            at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
            at java.awt.Component.processMouseEvent(Component.java:6263)
            at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
            at java.awt.Component.processEvent(Component.java:6028)
            at java.awt.Container.processEvent(Container.java:2041)
            at java.awt.Component.dispatchEventImpl(Component.java:4630)
            at java.awt.Container.dispatchEventImpl(Container.java:2099)
            at java.awt.Component.dispatchEvent(Component.java:4460)
            at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4574)
            at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
            at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
            at java.awt.Container.dispatchEventImpl(Container.java:2085)
            at java.awt.Window.dispatchEventImpl(Window.java:2478)
            at java.awt.Component.dispatchEvent(Component.java:4460)
            at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
            at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
            at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
            at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
            at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
    Looking into it.
    Last edited by pevergreen; 09-23-2010 at 06:22.
    Quote Originally Posted by TosaInu
    The org will be org until everyone calls it a day.

    Quote Originally Posted by KukriKhan View Post
    but I joke. Some of my best friends are Vietnamese villages.
    Quote Originally Posted by Lemur
    Anyone who wishes to refer to me as peverlemur is free to do so.

  5. #5

    Default Re: Java question

    Well you used FileUtils.writeStringToFile() which is from Apache Commons. So you would need to have that library in an appropriate location or the classpath set appropriately to use it. The ArrayIndexOutOfBoundsException is due to an error on my part: (size -1) should've been size. The corrected version is at: http://pastebin.com/E7zL000f

    As for FileUtils: you used it, so I assumed that you knew what you were doing and since it appears to be from Apache Commons I added a corresponding import statement. Clearly I was wrong. Anyway, in Netbeans you can right click your project, go to “Properties” and add Libraries to your project there, that will ensure that the Classpath of your code is set appropriately for using the libraries. If you do not want to use FileUtils: you can remove:
    Code:
        private void toFile () throws Exception {
            // = null is needed to make the compiler happy otherwise it'll complain
            // about unintialised variables.
            FileWriter out = null;
            try {
                String name = txtname.getText();
                String surname = txtsurname.getText();
                String title = txttitle.getText();
                String nickname = txtnickname.getText();
    
                File outFile = new File("Customer.txt");
                out = new FileWriter(outFile, true);
                FileUtils.writeStringToFile(name, surname, nickname, title);
            }
            finally {
                if (out != null) {
                    out.close();
                }
            }
        }
    And replace it with:
    Code:
        private void toFile () throws Exception {
            // = null is needed to make the compiler happy otherwise it'll complain
            // about unintialised variables.
            java.io.PrintWriter out = null;
            try {
                String name = txtname.getText();
                String surname = txtsurname.getText();
                String title = txttitle.getText();
                String nickname = txtnickname.getText();
    
                File outFile = new File("Customer.txt");
                out = new java.io.PrintWriter(new FileWriter(outFile, true));
                // write contents to the file, one item per line
                for(String line: new String[] { name, surname, nickname, title }) {
                   out.println(line);
                }
                out.flush();
            }
            finally {
                if (out != null) {
                    out.close();
                }
            }
        }
    - Tellos Athenaios
    CUF tool - XIDX - PACK tool - SD tool - EVT tool - EB Install Guide - How to track down loading CTD's - EB 1.1 Maps thread


    ὁ δ᾽ ἠλίθιος ὣσπερ πρόβατον βῆ βῆ λέγων βαδίζει” – Kratinos in Dionysalexandros.

  6. #6
    the G-Diffuser Senior Member pevergreen's Avatar
    Join Date
    Nov 2006
    Location
    Brisbane, Australia
    Posts
    11,585
    Blog Entries
    2

    Default Re: Java question

    Quote Originally Posted by Tellos Athenaios View Post
    Well you used FileUtils.writeStringToFile() which is from Apache Commons. So you would need to have that library in an appropriate location or the classpath set appropriately to use it. The ArrayIndexOutOfBoundsException is due to an error on my part: (size -1) should've been size. The corrected version is at: http://pastebin.com/E7zL000f

    As for FileUtils: you used it, so I assumed that you knew what you were doing and since it appears to be from Apache Commons I added a corresponding import statement. Clearly I was wrong. .
    Yeah, you were kind of.

    Everything works great, except it still isn't removing items from the list.

    Code:
    run:
    Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: Array index out of range: 3
            at java.awt.Container.remove(Container.java:1136)
            at my.contacteditor.ContactEditorUI.btnremoveActionPerformed(ContactEditorUI.java:361)
            at my.contacteditor.ContactEditorUI.access$200(ContactEditorUI.java:21)
            at my.contacteditor.ContactEditorUI$3.actionPerformed(ContactEditorUI.java:170)
            at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
            at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
            at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
            at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
            at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
            at java.awt.Component.processMouseEvent(Component.java:6263)
            at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
            at java.awt.Component.processEvent(Component.java:6028)
            at java.awt.Container.processEvent(Container.java:2041)
            at java.awt.Component.dispatchEventImpl(Component.java:4630)
            at java.awt.Container.dispatchEventImpl(Container.java:2099)
            at java.awt.Component.dispatchEvent(Component.java:4460)
            at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4574)
            at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
            at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
            at java.awt.Container.dispatchEventImpl(Container.java:2085)
            at java.awt.Window.dispatchEventImpl(Window.java:2478)
            at java.awt.Component.dispatchEvent(Component.java:4460)
            at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
            at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
            at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
            at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
            at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
    You've helped so much, if I knew you in real life, I'd owe you like 3 cases of beer.
    Quote Originally Posted by TosaInu
    The org will be org until everyone calls it a day.

    Quote Originally Posted by KukriKhan View Post
    but I joke. Some of my best friends are Vietnamese villages.
    Quote Originally Posted by Lemur
    Anyone who wishes to refer to me as peverlemur is free to do so.

  7. #7

    Default Re: Java question

    Oh I see:
    Code:
    listemail.remove(index)
    should be
    Code:
    listModel().remove(index)
    - Tellos Athenaios
    CUF tool - XIDX - PACK tool - SD tool - EVT tool - EB Install Guide - How to track down loading CTD's - EB 1.1 Maps thread


    ὁ δ᾽ ἠλίθιος ὣσπερ πρόβατον βῆ βῆ λέγων βαδίζει” – Kratinos in Dionysalexandros.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Single Sign On provided by vBSSO