Sysout在功能完成之前出来

时间:2014-03-31 09:21:57

标签: java function system.out

我尝试做什么:

Call function1 => set values 
Call function2 => GetValues
Sysout => print the modified values

我的问题,sysout来了,我做了" Set Values"所以它向我展示了旧的价值观。

我做错了什么?

这是我的代码:

System.out.println("Cmd before SetParam : "+info1+"/"+info2+"/"+info3+"/"+info4+"/"+info5+"/"+info6+"/"+info7+"/"+info8);

TMSSA2_1.SetParam(info1,info2,info3,info4,info5,info6,info7,info8);

String[] cmd = new String[8];

cmd = TMSSA2_1.GetCmd();

System.out.println("New Cmd  => "+Arrays.toString(cmd));

所以我的输出看起来像:

cMD before SetParam : 45/128/128/128/128/128/0/0

New Cmd  => [null, null, null, null, null, null, null, null]
SetParam => ok
GetCmd => Ok

所以你可以看到我的2个函数在我的sysout之后调用。

编辑:

完整功能代码:

static int Check_jb1 = 0;
static int Check_jb2 = 0;

public static String[] Commande = new String[8];

public static void SetParam(final String info1,final String info2,final String info3,final String info4,
        final String info5,final String info6,final String info7,final String info8){

    String d1 = info1,d2 = info2,d3 = info3,d4 = info4,d5 = info5,d6 = info6,d7 = info7,d8 = info8;



    final String[] cmd = new String[8];
    cmd[0] = d1;        cmd[1] = d2;        cmd[2] = d3;        cmd[3] = d4;
    cmd[4] = d5;        cmd[5] = d6;        cmd[6] = d7;        cmd[7] = d8;


    //d1,d2,d3,d4,d5,d6,d7,d8; // valeur que l'on renvoie ds la cmd

    System.out.println("Debug : "+d1+"/"+d2+"/"+d3+"/"+d4+"/"+d5+"/"+d6+"/"+d7+"/"+d8);


    final JFrame fenetre = new JFrame();
    fenetre.setTitle("Set Value(s)");
    fenetre.setSize(375,450);
    fenetre.setLocationRelativeTo(null);
    fenetre.setResizable(true);

    JPanel jp1 = new JPanel();
    jp1.setBorder(BorderFactory.createTitledBorder("Set Parameters : "));
    jp1.setPreferredSize(new Dimension(325, 325));
    jp1.setBackground(Color.white);

    JLabel jl1 = new JLabel();
    jl1.setText("Installation Height : "+info1);
    jl1.setPreferredSize(new Dimension(175, 25));
    final JTextField jt1 = new JTextField();
    jt1.setPreferredSize(new Dimension(75, 25));

    JLabel jl2 = new JLabel();
    jl2.setText("Install Offset : "+info2);
    jl2.setPreferredSize(new Dimension(175, 25));
    final JTextField jt2 = new JTextField();
    jt2.setPreferredSize(new Dimension(75, 25));

    JLabel jl3 = new JLabel();
    jl3.setText("Speed Near Lane : "+info3);
    jl3.setPreferredSize(new Dimension(175, 25));
    final JTextField jt3 = new JTextField();
    jt3.setPreferredSize(new Dimension(75, 25));

    JLabel jl4 = new JLabel();
    jl4.setText("Speed Far Lane : "+info4);
    jl4.setPreferredSize(new Dimension(175, 25));
    final JTextField jt4 = new JTextField();
    jt4.setPreferredSize(new Dimension(75, 25));

    JLabel jl5 = new JLabel();
    jl5.setText("Lenght Near Lane : "+info5);
    jl5.setPreferredSize(new Dimension(175, 25));
    final JTextField jt5 = new JTextField();
    jt5.setPreferredSize(new Dimension(75, 25));

    JLabel jl6 = new JLabel();
    jl6.setText("Lenght Far Lane : "+info6);
    jl6.setPreferredSize(new Dimension(175, 25));
    final JTextField jt6 = new JTextField();
    jt6.setPreferredSize(new Dimension(75, 25));

    JLabel jl7 = new JLabel();
    jl7.setText("Angle Offset : "+info7);
    jl7.setPreferredSize(new Dimension(175, 25));
    final JTextField jt7 = new JTextField();
    jt7.setPreferredSize(new Dimension(75, 25));

    JLabel jl8 = new JLabel();
    jl8.setText("Detector Mode : "+info8);
    jl8.setPreferredSize(new Dimension(175, 25));
    final JTextField jt8 = new JTextField();
    jt8.setPreferredSize(new Dimension(75, 25));

    JPanel jp2 = new JPanel();
    jp2.setPreferredSize(new Dimension(325, 50));
    jp2.setBackground(Color.white);

    JButton jb1 = new JButton("Set with actual value");
    JButton jb2 = new JButton("Set with new value");


    fenetre.add(jp1);   
    jp1.add(jl1);jp1.add(jt1);      jp1.add(jl2);jp1.add(jt2);  jp1.add(jl3);jp1.add(jt3);  jp1.add(jl4);jp1.add(jt4);      
    jp1.add(jl5);jp1.add(jt5);      jp1.add(jl6);jp1.add(jt6);  jp1.add(jl7);jp1.add(jt7);  jp1.add(jl8);jp1.add(jt8);

    fenetre.add(jp2);
    jp2.add(jb1);
    jp2.add(jb2);


    fenetre.setVisible(true);

    jp1.setVisible(true);

    jl1.setVisible(true);   
    jl2.setVisible(true);
    jl3.setVisible(true);
    jl4.setVisible(true);
    jl5.setVisible(true);
    jl6.setVisible(true);
    jl7.setVisible(true);
    jl8.setVisible(true);

    //fenetre.getContentPane().add(JP_North, BorderLayout.NORTH);
    fenetre.getContentPane().add(jp1, BorderLayout.CENTER);
    fenetre.getContentPane().add(jp2, BorderLayout.SOUTH);

    //while ((Check_jb2 == 0) & (Check_jb1 == 0)){

    //Garder Ancien Value
    jb1.addActionListener(new ActionListener(){
        public void actionPerformed(ActionEvent arg0) {
            System.out.println("Dans le action jb1");
            fenetre.dispose();
            Check_jb1 = 1;  
            returnCmd(cmd);
            System.out.println("JB1 : Retour => "+Arrays.toString(cmd));
        }      
    });

    //Envoyer New value
    jb2.addActionListener(new ActionListener(){
        public void actionPerformed(ActionEvent arg0) {

            cmd[0] = jt1.getText();             cmd[1] = jt2.getText();             cmd[2] = jt3.getText();             cmd[3] = jt4.getText();
            cmd[4] = jt5.getText();             cmd[5] = jt6.getText();             cmd[6] = jt7.getText();             cmd[7] = jt8.getText();

            fenetre.dispose();                          
            Check_jb2 = 1;
            returnCmd(cmd);
            System.out.println("JB2 : Retour => "+ Arrays.toString(cmd));
        }      
    });
    //}
    //System.out.println("sortie du while");

}

public static String[] returnCmd (String[] Commande2){
    Commande = Commande2;
    return Commande;
}

public static String[] GetCmd(){
    return Commande;
}

以下是我打电话给他们的方式:

System.out.println("Cmd before SetParam : "+info1+"/"+info2+"/"+info3+"/"+info4+"/"+info5+"/"+info6+"/"+info7+"/"+info8);

TMSSA2_1.SetParam(info1,info2,info3,info4,info5,info6,info7,info8);

String[] cmd = new String[8];

cmd = TMSSA2_1.GetCmd();

System.out.println("New Cmd => "+Arrays.toString(cmd));

0 个答案:

没有答案