Results 1 to 19 of 19
  1. #1
    aboyse1990 is offline Member
    Join Date
    Nov 2014
    Posts
    61
    Rep Power
    0

    Post Linking programs

    I have this code:

    Java Code:
    package javaproject;
    
    public class Circuits{
        
        public static void main(String[] args){
            
            String[][] Circuit = {{"Circuit One", "Jerk", "Russian Twists", "Squats",
                "Squat Jumps", "Deadlift"},
                
                {"Circuit Two", "Pull Ups", "Around the Body Pass", "Two Arm Swings",
                    "One Arm Swings", "Snatch"},
                
                {"Circuit Three", "Long Cycle", "One Arm Clean", "Alternating Kettlebell Row",
                    "Two Arm Swings", "Double Jerks"},
                
                {"Circuit Four", "Bottoms Up Clean", "Bottoms Up Clean and Press", 
                    "One Arm Row", "Squat Jumps", "Turkish Get-Ups"},
                
                {"Circuit Five", "Floor Press", "One Arm Push Press", "Military Press",
                    "Double Kettlebell Press", "Superman Squats"}};
         }
    }
    How do i link it to this code,

    Java Code:
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    
    /*
     * KettleCircuit.java
     *
     * Created on 12-Nov-2014, 09:03:53
     */
    
    package javaproject;
    
    /**
     *
     * @author User
     */
    public class KettleCircuit extends javax.swing.JFrame {
    
        /** Creates new form KettleCircuit */
        public KettleCircuit() {
            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() {
    
            jColorChooser1 = new javax.swing.JColorChooser();
            jColorChooser2 = new javax.swing.JColorChooser();
            jFrame1 = new javax.swing.JFrame();
            jPanel1 = new javax.swing.JPanel();
            jPanel2 = new javax.swing.JPanel();
            jPanel3 = new javax.swing.JPanel();
            jComboBox1 = new javax.swing.JComboBox();
            jComboBox3 = new javax.swing.JComboBox();
            jButton1 = new javax.swing.JButton();
            jLabel1 = new javax.swing.JLabel();
            jLabel2 = new javax.swing.JLabel();
            jTextField1 = new javax.swing.JTextField();
    
            javax.swing.GroupLayout jFrame1Layout = new javax.swing.GroupLayout(jFrame1.getContentPane());
            jFrame1.getContentPane().setLayout(jFrame1Layout);
            jFrame1Layout.setHorizontalGroup(
                jFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 400, Short.MAX_VALUE)
            );
            jFrame1Layout.setVerticalGroup(
                jFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 300, Short.MAX_VALUE)
            );
    
            javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
            jPanel1.setLayout(jPanel1Layout);
            jPanel1Layout.setHorizontalGroup(
                jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 100, Short.MAX_VALUE)
            );
            jPanel1Layout.setVerticalGroup(
                jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 100, Short.MAX_VALUE)
            );
    
            javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
            jPanel2.setLayout(jPanel2Layout);
            jPanel2Layout.setHorizontalGroup(
                jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 100, Short.MAX_VALUE)
            );
            jPanel2Layout.setVerticalGroup(
                jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 100, Short.MAX_VALUE)
            );
    
            javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
            jPanel3.setLayout(jPanel3Layout);
            jPanel3Layout.setHorizontalGroup(
                jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 100, Short.MAX_VALUE)
            );
            jPanel3Layout.setVerticalGroup(
                jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 100, Short.MAX_VALUE)
            );
    
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    
            jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Circuits", "Circuit One (Beginner)", "Circuit Two (Novice)", "Circuit Three (Amateur)", "Circuit Four (Intermediate", "Circuit Five (Expert)" }));
            jComboBox1.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jComboBox1ActionPerformed(evt);
                }
            });
    
            jComboBox3.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Minutes", "5 Minutes", "8 Minutes ", "10 Minutes ", "12 Minutes ", "15 Minutes", "20 Minutes " }));
    
            jButton1.setText("GO");
    
            jLabel1.setText("Twitter");
    
            jLabel2.setText("Facebook");
    
            jTextField1.setText("Test Yourself Today");
            jTextField1.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jTextField1ActionPerformed(evt);
                }
            });
    
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(jButton1)
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel1)
                                .addGap(26, 26, 26)
                                .addComponent(jLabel2))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                .addGap(28, 28, 28)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(jComboBox3, javax.swing.GroupLayout.Alignment.TRAILING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jComboBox1, javax.swing.GroupLayout.Alignment.TRAILING, 0, 335, Short.MAX_VALUE)
                                    .addComponent(jTextField1)))))
                    .addContainerGap(37, Short.MAX_VALUE))
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addContainerGap()
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel1)
                        .addComponent(jLabel2))
                    .addGap(31, 31, 31)
                    .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(31, 31, 31)
                    .addComponent(jComboBox3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(35, 35, 35)
                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(32, 32, 32)
                    .addComponent(jButton1)
                    .addContainerGap(63, Short.MAX_VALUE))
            );
    
            pack();
        }// </editor-fold>                        
    
        private void jComboBox1ActionPerformed(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:
    
    
        }                                           
    
        /**
        * @param args the command line arguments
        */
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new KettleCircuit().setVisible(true);
    
    
                }
            });
        }
    
        // Variables declaration - do not modify                     
        private javax.swing.JButton jButton1;
        private javax.swing.JColorChooser jColorChooser1;
        private javax.swing.JColorChooser jColorChooser2;
        private javax.swing.JComboBox jComboBox1;
        private javax.swing.JComboBox jComboBox3;
        private javax.swing.JFrame jFrame1;
        private javax.swing.JLabel jLabel1;
        private javax.swing.JLabel jLabel2;
        private javax.swing.JPanel jPanel1;
        private javax.swing.JPanel jPanel2;
        private javax.swing.JPanel jPanel3;
        private javax.swing.JTextField jTextField1;
        // End of variables declaration                   
    
    }

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: Linking programs

    How do i link it to this code,
    Please explain what "link" means.
    What is the objective?

    Note: variables local to a method only exist when the method is executed. A variable in a method can be passed to another method or constructor as an arg.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    aboyse1990 is offline Member
    Join Date
    Nov 2014
    Posts
    61
    Rep Power
    0

    Default Re: Linking programs

    Call the first piece of java code from the other, or vice versa.

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: Linking programs

    Call the first piece of java code from the other, or vice versa.
    That sounds like that a technique for doing something, not the reason/objective for the code.
    There may be better technique to accomplish the objective.
    If you don't understand my response, don't ignore it, ask a question.

  5. #5
    aboyse1990 is offline Member
    Join Date
    Nov 2014
    Posts
    61
    Rep Power
    0

    Default Re: Linking programs

    I want the main code to call the String Array Code, any particular piece of code do that?

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: Linking programs

    Since the array is inside of a method, a way for a method in another class to access the array is for the method that contains the array to pass a reference to the array as an arg in a method call:
    Java Code:
      refToOtherClass.theMethodToGetTheArray(theArray); //  pass array to method
    If you don't understand my response, don't ignore it, ask a question.

  7. #7
    aboyse1990 is offline Member
    Join Date
    Nov 2014
    Posts
    61
    Rep Power
    0

    Default Re: Linking programs

    So like KettleCircuit.Circuits(Circuit);

  8. #8
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: Linking programs

    Did you try it? What happened?
    If you don't understand my response, don't ignore it, ask a question.

  9. #9
    aboyse1990 is offline Member
    Join Date
    Nov 2014
    Posts
    61
    Rep Power
    0

    Default Re: Linking programs

    It's saying it cannot find the variable Circuit

  10. #10
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: Linking programs

    Please copy the full text of the error message and paste it here. It has important info about the error.

    A suggestion: Change the class holding the array by moving the array to be a class instance variable. Add a getter method that returns a reference to the array.
    Or better yet add a family of methods to access different parts of the array so that users don't have to know that the data is being held in a 2Dim array.
    If you don't understand my response, don't ignore it, ask a question.

  11. #11
    aboyse1990 is offline Member
    Join Date
    Nov 2014
    Posts
    61
    Rep Power
    0

    Default Re: Linking programs

    Java Code:
    KettleCircuit.Circuits(Circuit);

  12. #12
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: Linking programs

    KettleCircuit.Circuits(Circuit);
    What is the purpose of post#11?
    If you don't understand my response, don't ignore it, ask a question.

  13. #13
    aboyse1990 is offline Member
    Join Date
    Nov 2014
    Posts
    61
    Rep Power
    0

    Default Re: Linking programs

    To link KettleCircuit and Circuit classes

  14. #14
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: Linking programs

    Ok. What happens when you compile and execute the code?

    Take a look at post#10 again.
    If you don't understand my response, don't ignore it, ask a question.

  15. #15
    aboyse1990 is offline Member
    Join Date
    Nov 2014
    Posts
    61
    Rep Power
    0

    Default Re: Linking programs

    What sort of code could i use...

  16. #16
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: Linking programs

    The methods would be getters for the different types of access you want to the contents of the 2Dim array.

    Make a list of how the code would want to access the data. Then write a method to do each of them.
    If you don't understand my response, don't ignore it, ask a question.

  17. #17
    aboyse1990 is offline Member
    Join Date
    Nov 2014
    Posts
    61
    Rep Power
    0

    Default Re: Linking programs

    Quote Originally Posted by Norm View Post
    The methods would be getters for the different types of access you want to the contents of the 2Dim array.

    Make a list of how the code would want to access the data. Then write a method to do each of them.
    Whenever the Circuits drop-down menu is accessed with Circuit One to Five, the values in Circuit One should show up with Circuit One is clicked. Do I need a get method there...

  18. #18
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: Linking programs

    That would be one place for a method. Pass the Circuit name as an arg to the getter method and have it return a list of the exercises.
    If you don't understand my response, don't ignore it, ask a question.

  19. #19
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,423
    Blog Entries
    7
    Rep Power
    27

    Default Re: Linking programs

    You can't just glue together two objects from two classes A and B; one object should at least have a reference to the other object; this is Java 101 however and if you don't know how to do it, it's time to hit the books again.

    kind regards,

    Jos
    Build a wall around Donald Trump; I'll pay for it.

Similar Threads

  1. linking jframe
    By vinodpatole in forum NetBeans
    Replies: 4
    Last Post: 01-20-2012, 11:15 PM
  2. Linking two classes together
    By JonniBravo in forum New To Java
    Replies: 6
    Last Post: 09-11-2010, 10:53 PM
  3. Linking constructors
    By willemien in forum New To Java
    Replies: 3
    Last Post: 05-04-2010, 11:31 PM
  4. need help linking the array
    By nobody58 in forum Advanced Java
    Replies: 1
    Last Post: 03-22-2010, 01:05 PM
  5. linking to a web page
    By Juuno in forum Advanced Java
    Replies: 7
    Last Post: 05-01-2009, 02:47 PM

Tags for this Thread

Posting Permissions

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