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

Thread: please help, simple problem

  1. #1
    Junior Member
    Join Date
    Nov 2011
    Posts
    4
    My Mood
    Cold
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default please help, simple problem

    hi completely new here, and semi new to java programming i apologies if this is completely off what i want it to be doing, I'm trying to get an input of a date in the format of dd/mm/yyy and once the enter button is pressed it grabs the day then output its in the jTextFieldOutput.

    i think I'm completely off on what i meant to be doing, so i apologies if this makes you laugh





    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
     
    /*
     * JFrame.java
     *
     * Created on Nov 13, 2011, 1:44:14 PM
     */
    package date;
     
    import javax.swing.JOptionPane;
    /**
     *
     * @author grandmstramrod
     */
    public class JFrame extends javax.swing.JFrame {
     
        public String name;
        private boolean day,month,year;
     
        /** Creates new form JFrame */
        public JFrame() {
            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() {
     
            jTextFieldInput = new javax.swing.JTextField();
            jButtonEnter = new javax.swing.JButton();
            jTextFieldOutput = new javax.swing.JTextField();
     
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
            setBackground(new java.awt.Color(153, 153, 153));
     
            jTextFieldInput.setText("jTextField1");
     
            jButtonEnter.setText("jButton1");
            jButtonEnter.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jButtonEnterActionPerformed(evt);
                }
            });
     
            jTextFieldOutput.setText("jTextField2");
     
            org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                .add(layout.createSequentialGroup()
                    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
                        .add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup()
                            .add(88, 88, 88)
                            .add(jTextFieldInput))
                        .add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup()
                            .add(91, 91, 91)
                            .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
                                .add(org.jdesktop.layout.GroupLayout.LEADING, jTextFieldOutput)
                                .add(org.jdesktop.layout.GroupLayout.LEADING, jButtonEnter, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 187, Short.MAX_VALUE))))
                    .addContainerGap())
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                .add(layout.createSequentialGroup()
                    .addContainerGap()
                    .add(jTextFieldInput, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 47, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(18, 18, 18)
                    .add(jButtonEnter, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 63, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(11, 11, 11)
                    .add(jTextFieldOutput, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 54, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(99, Short.MAX_VALUE))
            );
     
            pack();
        }// </editor-fold>
     
        private void jButtonEnterActionPerformed(java.awt.event.ActionEvent evt) {
     
            name=jTextFieldInput.getText();
     
    name = subName (day, month, year);
     
    checkinput();
    jTextFieldOutput.setText("the day is" + day );
     
    // TODO add your handling code here:
        }
     
        /**
         * @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(JFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (InstantiationException ex) {
                java.util.logging.Logger.getLogger(JFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (IllegalAccessException ex) {
                java.util.logging.Logger.getLogger(JFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (javax.swing.UnsupportedLookAndFeelException ex) {
                java.util.logging.Logger.getLogger(JFrame.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 JFrame().setVisible(true);
                }
            });
        }
        // Variables declaration - do not modify
        private javax.swing.JButton jButtonEnter;
        private javax.swing.JTextField jTextFieldInput;
        private javax.swing.JTextField jTextFieldOutput;
        // End of variables declaration
     
     
     
      public void checkinput(){
     
        String subName =  jTextFieldInput.getText(); 
     
        if (subName.isEmpty()){
                JOptionPane.showMessageDialog(null,subName,"is empty",JOptionPane.ERROR_MESSAGE);
     
            }else{
       try {
                 day = dateFormat.parse (jTextFieldInput.getText());
                  = Integer.parseInt (jTextFieldOutput.getText());
                 } catch (NumberFormatException n) {
                subName (day);


  2. #2
    Junior Member
    Join Date
    Nov 2011
    Posts
    4
    My Mood
    Cold
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: please help, simple problem

    ps the code is not complete...

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: please help, simple problem

    Do you have any specific questions about your code?
    Please ask them.

  4. #4
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: please help, simple problem

    Where are you getting input from the user?

  5. #5
    Junior Member
    Join Date
    Nov 2011
    Posts
    4
    My Mood
    Cold
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: please help, simple problem

    do apologies guys, relalised that i needed to sub string the input to be able to create an output while on the way to work, sorry to waste your time but sure my code will need emending when i update it tomorrow.

    apologies

Similar Threads

  1. beginner needs help with simple problem
    By ddonn in forum What's Wrong With My Code?
    Replies: 2
    Last Post: October 21st, 2011, 11:16 AM
  2. Need help with a simple jsp and servlet problem
    By javacoder_APAC in forum Java Servlet
    Replies: 4
    Last Post: March 23rd, 2011, 08:32 AM
  3. Very simple problem...PLEASE HELP!
    By dungeondragon in forum What's Wrong With My Code?
    Replies: 4
    Last Post: March 1st, 2011, 07:19 AM
  4. Simple problem...
    By _lithium_ in forum What's Wrong With My Code?
    Replies: 9
    Last Post: February 6th, 2011, 12:02 AM
  5. Simple import problem
    By Mekster in forum Java IDEs
    Replies: 3
    Last Post: November 13th, 2009, 09:17 PM