473,396 Members | 1,804 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

ArrayIndexOutOfBoundsException


private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {

String Temp = jComboBox1.getSelectedItem().toString();

testcomm.TestForm.WriteParamToPic("c"+Temp);

}


public static void WriteParamToPic(String ParamIn)
{
char [] WriteParam = new char[4];
byte [] FinalWriteParam = new byte[4];
WriteParam = ParamIn.toCharArray();
for(int i=0; i<4; i++){
FinalWriteParam[i] = (byte) WriteParam[i];
Comm.PutPointerData(FinalWriteParam,4);
}
}







I have:
jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] {"30", "50" }));
i get nex error:
java.lang.ArrayIndexOutOfBoundsException


Hove must i configure argument for WriteParamToPic?
I have trayed to change number of arrays in WriteParamToPic, but it returns me other errors.

Thank you
Feb 13 '07 #1
31 2414
r035198x
13,262 8TB

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {



String Temp = jComboBox1.getSelectedItem().toString();



testcomm.TestForm.WriteParamToPic(\"c\"+Temp);



}



public static void WriteParamToPic(String ParamIn)

{

char [] WriteParam = new char[4];

byte [] FinalWriteParam = new byte[4];

WriteParam = ParamIn.toCharArray();

for(int i=0; i<4; i++){

FinalWriteParam[i] = (byte) WriteParam[i];

Comm.PutPointerData(FinalWriteParam,4);

}

}













I have:

jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] {\"30\", \"50\" }));

i get nex error:

java.lang.ArrayIndexOutOfBoundsException





Hove must i configure argument for WriteParamToPic?

I have trayed to change number of arrays in WriteParamToPic, but it returns me other errors.



Thank you


FinalWriteParam[i] = (byte) WriteParam[i];
At this point WriteParam is longer than FinalWriteParam because

Expand|Select|Wrap|Line Numbers
  1. WriteParam = ParamIn.toCharArray(); 


is returning an Array os size bigger than 4. You have to decide what you want to do with the surplus bits first to solve that problem
Feb 13 '07 #2
Thank you wery much.I don't get error any more.

But now, I’ll gone to tray to explain next problem. And if we well resolve it, I’ll
be much closer to my final faculty work.

I'm sending data (parameters) to the PIC microcontroller. I have made application for regulation of temperature. And to control and supervise it i need to use a graphic interface. So, from Hyper terminal i can do it wery well.
My PIC understands characters sent from keyboard one by one.

But in my Java work:...
my code doesn’t accurate me valid transmission. I have to press (activate transmission) on button several time to get result and much time the transferred data isn’t correct. I'll appreciate every suggestions because i assume that them well lead me to conclusion have to resolve communication problem.

Now when I think. I have programmed microcontroller to activate interrupt itch time it gets data (one character)on him input. So it could be resolution to include a delay between sending of
characters to give microcontroller time to elaborate data.
Yes , I think this could be wright way. So if I resume I have to send character by character and to include minimum delay between itch transmission.Wright?

To continue before sent code:
Expand|Select|Wrap|Line Numbers
  1.  void PutPointerData(byte [] ChIn, int ChNumb) 
  2. {
  3. try 
  4. {
  5. OutStream.write(ChIn,0,ChNumb);
  6. OutStream.flush();
  7. } catch (IOException ex) 
  8. {
  9. ex.printStackTrace();
  10. }
  11. }
  12.  
Feb 14 '07 #3
And now i have a concrete problem:

Expand|Select|Wrap|Line Numbers
  1. public static void WriteParamToPic(String ParamIn)
  2.     {
  3.         char [] WriteParam = new char[4];       
  4.         WriteParam =ParamIn.toCharArray();
  5.         for(int i=0; i<4; i++){            
  6.           Comm.PutData((byte) WriteParam[i]) ;
  7.         }
  8.     }
  9.  
  10.  //  to send induvidual character
  11.  void PutData (byte ChIn)        
  12.             {
  13.                 try {
  14.                     OutStream.write((byte) ChIn);
  15.                     OutStream.flush();
  16.                     } catch (IOException ex) 
  17.                     {
  18.                     ex.printStackTrace();
  19.                     }
  20.             }
I can't test my code because i need a delay between itch sending.
So I have tray at next way:
I think that from the code can be ungderstud that i would like to make a delay betwen induidual sending, but like you my see i realy need help.


Expand|Select|Wrap|Line Numbers
  1. public static void WriteParamToPic(String ParamIn)
  2.     {
  3.         char [] WriteParam = new char[4];       
  4.         WriteParam =ParamIn.toCharArray();
  5.         for(int i=0; i<4; i++){
  6.          Comm.charTimer();        //eror:create a metod charTimer() in     testcomm.TwoWaySerialComm
  7.          Comm.PutData((byte)  WriteParam[i]) ;
  8.         }
  9.  
  10.     }
  11.  
  12.     private  void charTimer() 
  13.     {
  14.      charTmr = new Timer();
  15.         charTmr.schedule(doNothing,1000);  //error:create fild doNothing
  16.     }
Feb 14 '07 #4
r035198x
13,262 8TB
And now i have a concrete problem:

Expand|Select|Wrap|Line Numbers
  1. public static void WriteParamToPic(String ParamIn)
  2. {
  3. char [] WriteParam = new char[4]; 
  4. WriteParam =ParamIn.toCharArray();
  5. for(int i=0; i<4; i++){ 
  6. Comm.PutData((byte) WriteParam[i]) ;
  7. }
  8. }
  9.  
  10. // to send induvidual character
  11. void PutData (byte ChIn)     
  12. {
  13. try {
  14. OutStream.write((byte) ChIn);
  15. OutStream.flush();
  16. } catch (IOException ex) 
  17. {
  18. ex.printStackTrace();
  19. }
  20. }
I can't test my code because i need a delay between itch sending.
So I have tray at next way:
I think that from the code can be ungderstud that i would like to make a delay betwen induidual sending, but like you my see i realy need help.


Expand|Select|Wrap|Line Numbers
  1. public static void WriteParamToPic(String ParamIn)
  2. {
  3. char [] WriteParam = new char[4]; 
  4. WriteParam =ParamIn.toCharArray();
  5. for(int i=0; i<4; i++){
  6. Comm.charTimer(); //eror:create a metod charTimer() in testcomm.TwoWaySerialComm
  7. Comm.PutData((byte) WriteParam[i]) ;
  8. }
  9.  
  10. }
  11.  
  12. private void charTimer() 
  13. {
  14.      charTmr = new Timer();
  15. charTmr.schedule(doNothing,1000); //error:create fild doNothing
  16. }
You can use the Thread.sleep method
Feb 14 '07 #5
Expand|Select|Wrap|Line Numbers
  1. public static void WriteParamToPic(String ParamIn)
  2.     {
  3.         char [] WriteParam = new char[4];       
  4.         WriteParam =ParamIn.toCharArray();
  5.         for(int i=0; i<4; i++){       
  6.          Comm.PutData((byte) WriteParam[i]) ;
  7.           try {
  8.               Thread.sleep (3);
  9.               }
  10.           catch ( Exception ex ) {
  11.                      ex.printStackTrace();
  12.                }
  13.         }
  14.  
  15.     }


In this way it works.
Thank you wery much.
Feb 14 '07 #6
r035198x
13,262 8TB
Expand|Select|Wrap|Line Numbers
  1. public static void WriteParamToPic(String ParamIn)
  2. {
  3. char [] WriteParam = new char[4]; 
  4. WriteParam =ParamIn.toCharArray();
  5. for(int i=0; i<4; i++){ 
  6. Comm.PutData((byte) WriteParam[i]) ;
  7. try {
  8. Thread.sleep (3);
  9. }
  10. catch ( Exception ex ) {
  11. ex.printStackTrace();
  12. }
  13. }
  14.  
  15. }


In this way it works.
Thank you wery much.
Anytime. Notice also that I did not really give you much help here. Just a few comments and you managed to fix the problem yourself. It's always a pleasure assisting those who prefer to write their own code themselves.
Feb 15 '07 #7
Expand|Select|Wrap|Line Numbers
  1.    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
  2.  
  3.  
  4.         if(testcomm.TestForm.mainTmr != null)
  5.            testcomm.TestForm.mainTmr.cancel();      
  6.  
  7.      //other code  
  8.  
  9.         testcomm.TestForm.startTimer() ;
  10.         // non static metod cannot be referenced from static contrxt
  11.     }                         

And timer:
Expand|Select|Wrap|Line Numbers
  1. public  void startTimer() 
  2.     {
  3.     mainTmr = new Timer();
  4.         mainTmr.schedule((new TimerChhRunCls()),1000,timeSampleLong);
  5.     }
  6.     class TimerChhRunCls extends TimerTask 
  7.     {
  8.         public void run() 
  9.         {
  10.             ReadTemperatureFromRS232();
  11.         }
  12.  
  13.     }
Sure, that with yours help it can do more.



My school work is done, but I wont to improve(make beater) it, that it can be used in technical application

for real. So, there is some more work to do.

I have to stop timer and activate it again after other code (data transmission) has been done.



But I get error (comment). What must i do to resolve it? A must admit that theory about static and non static isn't steal clear to me.
Feb 15 '07 #8
r035198x
13,262 8TB
Expand|Select|Wrap|Line Numbers
  1.  private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { 
  2.  
  3.  
  4. if(testcomm.TestForm.mainTmr != null)
  5. testcomm.TestForm.mainTmr.cancel(); 
  6.  
  7. //other code 
  8.  
  9. testcomm.TestForm.startTimer() ;
  10. // non static metod cannot be referenced from static contrxt

And timer:
Expand|Select|Wrap|Line Numbers
  1. public void startTimer() 
  2. {
  3.     mainTmr = new Timer();
  4. mainTmr.schedule((new TimerChhRunCls()),1000,timeSampleLong);
  5. }
  6. class TimerChhRunCls extends TimerTask 
  7. {
  8. public void run() 
  9. {
  10. ReadTemperatureFromRS232();
  11. }
  12.  
  13. }
Sure, that with yours help it can do more.



My school work is done, but I wont to improve(make beater) it, that it can be used in technical application

for real. So, there is some more work to do.

I have to stop timer and activate it again after other code (data transmission) has been done.



But I get error (comment). What must i do to resolve it? A must admit that theory about static and non static isn't steal clear to me.
What error(comment) are you getting.
Feb 15 '07 #9
// non static metod cannot be referenced from static context

and it referes to next line of code:
testcomm.TestForm.startTimer() ;


it is part of first block of code in previous post.

Thank you
Feb 15 '07 #10
r035198x
13,262 8TB
// non static metod cannot be referenced from static context

and it referes to next line of code:
testcomm.TestForm.startTimer() ;


it is part of first block of code in previous post.

Thank you
This may really depend on how you designed your classes, but
what happens if you make the startTimer method static?
Feb 15 '07 #11
First i have changed metod to static and then variable timeSampleLong too.
But i could not resolve next error :
"non-static variable this couldnot be referenced from a static context"
which refers to:
mainTmr.schedule((new TimerChhRunCls()),1000,timeSampleLong);
Feb 15 '07 #12
r035198x
13,262 8TB
First i have changed metod to static and then variable timeSampleLong too.
But i could not resolve next error :
"non-static variable this couldnot be referenced from a static context"
which refers to:
mainTmr.schedule((new TimerChhRunCls()),1000,timeSampleLong);
Can you post the code for the TestForm class?
Feb 15 '07 #13
It's split in two:
First:

Expand|Select|Wrap|Line Numbers
  1. package testcomm;
  2. import java.awt.BorderLayout;
  3. import java.util.Date;
  4. import java.util.concurrent.locks.Lock;
  5. import java.util.concurrent.locks.ReentrantLock;
  6. import java.util.Timer;
  7. import java.util.TimerTask;
  8. import javax.swing.JButton;
  9. import javax.swing.JFrame;
  10. import javax.swing.JPanel;
  11. import org.jfree.chart.ChartPanel;
  12. import org.jfree.chart.JFreeChart;
  13. import org.jfree.chart.JFreeChart;
  14. import org.jfree.chart.demo.TimeSeriesChartDemo1;
  15. import org.jfree.data.time.Second;
  16. import org.jfree.data.time.TimeSeries;
  17. import org.jfree.data.time.TimeSeriesCollection;
  18. import org.jfree.ui.RefineryUtilities;
  19.  
  20.  
  21. public class TestForm extends javax.swing.JFrame {
  22.  
  23.     private Lock SendLock = new ReentrantLock();
  24.     private static String ComPort = "COM4";
  25.  
  26.  
  27.     TChartWrite TCh;
  28.     JFreeChart MainChrt;
  29.     ChartPanel MainChartPnl;
  30.     TimeSeriesCollection dataset;
  31.     TimeSeries tseries;
  32.  
  33.   public static   Timer mainTmr;    
  34. String timeSample;
  35. static long timeSampleLong ;
  36.     public static TwoWaySerialComm Comm;
  37.     public static int Jajca = 0;
  38.     public static byte [] GenBuffer = new byte[1024];
  39.     public static int GenBuffCnt = 0;
  40.     public int GenCount=0;
  41.  
  42.     /** Creates new form TestForm */
  43.     public TestForm() {
  44.         initComponents();
  45.         DrawGraph();
  46.     }
  47.  
  48.     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">                          
  49.     private void initComponents() {
  50.         jFrame1 = new javax.swing.JFrame();
  51.         jButton1 = new javax.swing.JButton();
  52.         jButton2 = new javax.swing.JButton();
  53.         jPanel1 = new javax.swing.JPanel();
  54.         jLabel1 = new javax.swing.JLabel();
  55.         jTextField1 = new javax.swing.JTextField();
  56.         jLabel2 = new javax.swing.JLabel();
  57.         jTextField2 = new javax.swing.JTextField();
  58.         jButton4 = new javax.swing.JButton();
  59.         jButton5 = new javax.swing.JButton();
  60.         jButton6 = new javax.swing.JButton();
  61.         jTextField3 = new javax.swing.JTextField();
  62.         jTextField4 = new javax.swing.JTextField();
  63.         jTextField5 = new javax.swing.JTextField();
  64.         jComboBox1 = new javax.swing.JComboBox();
  65.  
  66.         javax.swing.GroupLayout jFrame1Layout = new javax.swing.GroupLayout(jFrame1.getContentPane());
  67.         jFrame1.getContentPane().setLayout(jFrame1Layout);
  68.         jFrame1Layout.setHorizontalGroup(
  69.             jFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  70.             .addGap(0, 400, Short.MAX_VALUE)
  71.         );
  72.         jFrame1Layout.setVerticalGroup(
  73.             jFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  74.             .addGap(0, 300, Short.MAX_VALUE)
  75.         );
  76.  
  77.         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  78.         setMinimumSize(new java.awt.Dimension(900, 600));
  79.         addWindowListener(new java.awt.event.WindowAdapter() {
  80.             public void windowActivated(java.awt.event.WindowEvent evt) {
  81.                 formWindowActivated(evt);
  82.             }
  83.         });
  84.  
  85.         jButton1.setText("OPEN");
  86.         jButton1.addActionListener(new java.awt.event.ActionListener() {
  87.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  88.                 jButton1ActionPerformed(evt);
  89.             }
  90.         });
  91.  
  92.         jButton2.setText("Run Timer");
  93.         jButton2.addActionListener(new java.awt.event.ActionListener() {
  94.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  95.                 jButton2ActionPerformed(evt);
  96.             }
  97.         });
  98.  
  99.         javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
  100.         jPanel1.setLayout(jPanel1Layout);
  101.         jPanel1Layout.setHorizontalGroup(
  102.             jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  103.             .addGap(0, 404, Short.MAX_VALUE)
  104.         );
  105.         jPanel1Layout.setVerticalGroup(
  106.             jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  107.             .addGap(0, 246, Short.MAX_VALUE)
  108.         );
  109.  
  110.         jLabel1.setText("Temperatura");
  111.  
  112.         jTextField1.setText("25.55");
  113.  
  114.         jLabel2.setText("\u0160tevec");
  115.  
  116.         jTextField2.setText("10000");
  117.  
  118.         jButton4.setText("Stop Timer");
  119.         jButton4.addActionListener(new java.awt.event.ActionListener() {
  120.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  121.                 jButton4ActionPerformed(evt);
  122.             }
  123.         });
  124.  
  125.         jButton5.setText("Params");
  126.         jButton5.addActionListener(new java.awt.event.ActionListener() {
  127.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  128.                 jButton5ActionPerformed(evt);
  129.             }
  130.         });
  131.  
  132.         jButton6.setText("Read");
  133.         jButton6.addActionListener(new java.awt.event.ActionListener() {
  134.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  135.                 jButton6ActionPerformed(evt);
  136.             }
  137.         });
  138.  
  139.         jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1000", "10000", "100000", "1000000" }));
  140.         jComboBox1.addActionListener(new java.awt.event.ActionListener() {
  141.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  142.                 jComboBox1ActionPerformed(evt);
  143.             }
  144.         });
  145.  
  146.         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  147.         getContentPane().setLayout(layout);
  148.         layout.setHorizontalGroup(
  149.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  150.             .addGroup(layout.createSequentialGroup()
  151.                 .addContainerGap()
  152.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  153.                     .addGroup(layout.createSequentialGroup()
  154.                         .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  155.                             .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  156.                             .addGroup(layout.createSequentialGroup()
  157.                                 .addComponent(jLabel1)
  158.                                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  159.                                 .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  160.                                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  161.                                 .addComponent(jLabel2)
  162.                                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  163.                                 .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  164.                                 .addGap(22, 22, 22)
  165.                                 .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
  166.                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  167.                         .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
  168.                             .addComponent(jButton6, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  169.                             .addComponent(jTextField3)
  170.                             .addComponent(jTextField4)
  171.                             .addComponent(jTextField5)))
  172.                     .addGroup(layout.createSequentialGroup()
  173.                         .addComponent(jButton1)
  174.                         .addGap(119, 119, 119)
  175.                         .addComponent(jButton2)
  176.                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  177.                         .addComponent(jButton4)
  178.                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  179.                         .addComponent(jButton5)
  180.                         .addContainerGap())))
  181.         );
  182.         layout.setVerticalGroup(
  183.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  184.             .addGroup(layout.createSequentialGroup()
  185.                 .addContainerGap()
  186.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  187.                     .addComponent(jButton1)
  188.                     .addComponent(jButton2)
  189.                     .addComponent(jButton4)
  190.                     .addComponent(jButton5))
  191.  
Feb 15 '07 #14
and second:
Expand|Select|Wrap|Line Numbers
  1. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  2.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  3.                     .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  4.                     .addComponent(jLabel1)
  5.                     .addComponent(jLabel2)
  6.                     .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  7.                     .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  8.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  9.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  10.                     .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  11.                     .addGroup(layout.createSequentialGroup()
  12.                         .addComponent(jButton6)
  13.                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  14.                         .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  15.                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  16.                         .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  17.                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  18.                         .addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
  19.                 .addContainerGap())
  20.         );
  21.         pack();
  22.     }// </editor-fold>                        
  23.  
  24.     private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {                                           
  25.  
  26.       timeSample = jComboBox1.getSelectedItem().toString();
  27.       timeSampleLong= Long.parseLong(timeSample);
  28.     }                                          
  29.  
  30.     private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {                                         
  31.         String ZelTemp = ReadParamFromPIC('W');
  32.         String Histereza = ReadParamFromPIC('H');
  33.         String CritTemp = ReadParamFromPIC('C');
  34.  
  35.         jTextField3.setText(ZelTemp);
  36.         jTextField4.setText(Histereza);
  37.         jTextField5.setText(CritTemp);
  38.     }                                        
  39.  
  40.     private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {                                         
  41.       //  if(mainTmr != null)
  42.       //      mainTmr.cancel();             
  43.         Setting Stng = new Setting();
  44.         Stng.setDefaultCloseOperation ( JFrame.EXIT_ON_CLOSE ) ;
  45.         Stng.setLocation ( 300 , 300 ) ;
  46.         Stng.setVisible ( true ) ;
  47.     }                                        
  48.  
  49.     private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {                                         
  50.             mainTmr.cancel();
  51.     }                                        
  52.  
  53.     private void formWindowActivated(java.awt.event.WindowEvent evt) {                                     
  54. // TODO add your handling code here:
  55.     }                                    
  56.     private void DrawGraph()
  57.     {
  58.         dataset = createDataset();
  59.         TCh = new TChartWrite();
  60.         MainChrt = TCh.createChart(dataset);
  61.         MainChartPnl = new ChartPanel(MainChrt);
  62.         MainChartPnl.setBounds(0,0,640,480);
  63.         jPanel1.add(MainChartPnl);
  64.         jPanel1.setVisible( true );
  65.         MainChartPnl.validate();
  66.         tseries = dataset.getSeries(0);
  67.     }
  68.     private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                         
  69. // TODO add your handling code here:
  70.         startTimer();
  71.     }                                        
  72.  
  73.     //Branje in pisanje ComPorta!
  74.     public String ReadParamFromPIC(char ParamIn)
  75.     {
  76.         GenBuffCnt = 0;
  77.         Comm.PutData((byte)ParamIn);
  78.         if(GenBuffCnt > 5)
  79.         {
  80.             GenBuffCnt = 0;
  81.             return null;
  82.         }
  83.         while(GenBuffCnt!=5);
  84.         byte [] WriteBuff = ReturnNewBytes(GenBuffer);
  85.         String Data = new String(WriteBuff,0,4);        
  86.         GenBuffCnt = 0;
  87.         return Data;
  88.     }
  89.     public static void WriteParamToPic(String ParamIn)
  90.     {
  91.         char [] WriteParam = new char[4];       
  92.         WriteParam =ParamIn.toCharArray();
  93.         for(int i=0; i<4; i++){       
  94.          Comm.PutData((byte) WriteParam[i]) ;
  95.           try {
  96.               Thread.sleep (3);
  97.               }
  98.           catch ( Exception ex ) {
  99.                      ex.printStackTrace();
  100.                }
  101.         }
  102.  
  103.     }
  104.     private void ReadTemperatureFromRS232()
  105.     {
  106.         String Data = ReadParamFromPIC('R');
  107.         jTextField1.setText(Data);
  108.         GenCount++;
  109.         jTextField2.setText(Integer.toString(GenCount));
  110.         float Dat = Float.parseFloat(Data);
  111.         tseries.addOrUpdate(new Second(new Date()),Dat);
  112.     }
  113.     private byte [] ReturnNewBytes(byte [] DataIn)
  114.     {
  115.         byte [] DataOut = new byte[5];
  116.         DataOut[0] = DataIn[1];
  117.         DataOut[1] = DataIn[2];
  118.         DataOut[2] = '.';
  119.         DataOut[3] = DataIn[4];
  120.  
  121.         return DataOut;
  122.     }
  123.     public static void startTimer() 
  124.     {
  125.     mainTmr = new Timer();
  126.         mainTmr.schedule((new TimerChhRunCls()),1000,timeSampleLong);
  127.     }
  128.     class TimerChhRunCls extends TimerTask 
  129.     {
  130.         public void run() 
  131.         {
  132.             ReadTemperatureFromRS232();
  133.         }
  134.  
  135.     }
  136.  
  137.     class TimerTestRun extends TimerTask 
  138.     {
  139.         public void run() 
  140.         {
  141.             UpdateBoxAndGraph();
  142.         }
  143.  
  144.     }
  145.     private void UpdateBoxAndGraph()
  146.     {
  147.         GenCount++;
  148.         jTextField2.setText(Integer.toString(GenCount));
  149.         float Dat = Float.parseFloat("13.4");
  150.         Dat = Dat + GenCount;
  151.         tseries.addOrUpdate(new Second(new Date()),Dat);
  152.  
  153.  
  154.     }
  155.     private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
  156.  
  157.                 try
  158.                 {
  159.                 Comm = new TwoWaySerialComm();
  160.                     Comm.connect(ComPort);
  161.             }
  162.             catch ( Exception e )
  163.             {
  164.  
  165.                 e.printStackTrace();
  166.             }
  167.  
  168.     }                                        
  169.     private TimeSeriesCollection createDataset() 
  170.     {
  171.         TimeSeries ts = new TimeSeries("T", Second.class);
  172.         TimeSeriesCollection dataset = new TimeSeriesCollection();
  173.         dataset.addSeries(ts);
  174.         ts.setMaximumItemAge(30*60);
  175.         return dataset;
  176.     }
  177.  
  178.     public static void main(String args[]) {
  179.         java.awt.EventQueue.invokeLater(new Runnable() {
  180.             public void run() {
  181.                 new TestForm().setVisible(true);
  182.             }
  183.         });
  184.     }
  185.  
  186.     // Variables declaration - do not modify                     
  187.     private javax.swing.JButton jButton1;
  188.     private javax.swing.JButton jButton2;
  189.     private javax.swing.JButton jButton4;
  190.     private javax.swing.JButton jButton5;
  191.     private javax.swing.JButton jButton6;
  192.     private javax.swing.JComboBox jComboBox1;
  193.     private javax.swing.JFrame jFrame1;
  194.     private javax.swing.JLabel jLabel1;
  195.     private javax.swing.JLabel jLabel2;
  196.     private javax.swing.JPanel jPanel1;
  197.     public static javax.swing.JTextField jTextField1;
  198.     private javax.swing.JTextField jTextField2;
  199.     private javax.swing.JTextField jTextField3;
  200.     private javax.swing.JTextField jTextField4;
  201.     private javax.swing.JTextField jTextField5;
  202.     // End of variables declaration                   
  203.  
  204.  
  205. }
  206.  
Feb 15 '07 #15
Ganon11
3,652 Expert 2GB
Expand|Select|Wrap|Line Numbers
  1. testcomm.TestForm.startTimer() ;
You are trying to call a .startTimer() method from the TestForm class, but it should be called from a Timer. Try

Expand|Select|Wrap|Line Numbers
  1. testcomm.TestForm.mainTmr.startTimer();
or just

Expand|Select|Wrap|Line Numbers
  1. mainTmr.startTimer();
Feb 15 '07 #16
r035198x
13,262 8TB
and second:
Expand|Select|Wrap|Line Numbers
  1. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  2. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  3. .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  4. .addComponent(jLabel1)
  5. .addComponent(jLabel2)
  6. .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  7. .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  8. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  9. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  10. .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  11. .addGroup(layout.createSequentialGroup()
  12. .addComponent(jButton6)
  13. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  14. .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  15. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  16. .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  17. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  18. .addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
  19. .addContainerGap())
  20. );
  21. pack();
  22. }// </editor-fold> 
  23.  
  24. private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) { 
  25.  
  26. timeSample = jComboBox1.getSelectedItem().toString();
  27. timeSampleLong= Long.parseLong(timeSample);
  28.  
  29. private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) { 
  30. String ZelTemp = ReadParamFromPIC('W');
  31. String Histereza = ReadParamFromPIC('H');
  32. String CritTemp = ReadParamFromPIC('C');
  33.  
  34. jTextField3.setText(ZelTemp);
  35. jTextField4.setText(Histereza);
  36. jTextField5.setText(CritTemp);
  37.  
  38. private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) { 
  39. // if(mainTmr != null)
  40. // mainTmr.cancel(); 
  41. Setting Stng = new Setting();
  42. Stng.setDefaultCloseOperation ( JFrame.EXIT_ON_CLOSE ) ;
  43. Stng.setLocation ( 300 , 300 ) ;
  44. Stng.setVisible ( true ) ;
  45.  
  46. private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) { 
  47. mainTmr.cancel();
  48.  
  49. private void formWindowActivated(java.awt.event.WindowEvent evt) { 
  50. // TODO add your handling code here:
  51. private void DrawGraph()
  52. {
  53. dataset = createDataset();
  54. TCh = new TChartWrite();
  55. MainChrt = TCh.createChart(dataset);
  56. MainChartPnl = new ChartPanel(MainChrt);
  57. MainChartPnl.setBounds(0,0,640,480);
  58. jPanel1.add(MainChartPnl);
  59. jPanel1.setVisible( true );
  60. MainChartPnl.validate();
  61. tseries = dataset.getSeries(0);
  62. }
  63. private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) { 
  64. // TODO add your handling code here:
  65. startTimer();
  66.  
  67. //Branje in pisanje ComPorta!
  68. public String ReadParamFromPIC(char ParamIn)
  69. {
  70. GenBuffCnt = 0;
  71. Comm.PutData((byte)ParamIn);
  72. if(GenBuffCnt > 5)
  73. {
  74. GenBuffCnt = 0;
  75. return null;
  76. }
  77. while(GenBuffCnt!=5);
  78. byte [] WriteBuff = ReturnNewBytes(GenBuffer);
  79. String Data = new String(WriteBuff,0,4); 
  80. GenBuffCnt = 0;
  81. return Data;
  82. }
  83. public static void WriteParamToPic(String ParamIn)
  84. {
  85. char [] WriteParam = new char[4]; 
  86. WriteParam =ParamIn.toCharArray();
  87. for(int i=0; i<4; i++){ 
  88. Comm.PutData((byte) WriteParam[i]) ;
  89. try {
  90. Thread.sleep (3);
  91. }
  92. catch ( Exception ex ) {
  93. ex.printStackTrace();
  94. }
  95. }
  96.  
  97. }
  98. private void ReadTemperatureFromRS232()
  99. {
  100. String Data = ReadParamFromPIC('R');
  101. jTextField1.setText(Data);
  102. GenCount++;
  103. jTextField2.setText(Integer.toString(GenCount));
  104. float Dat = Float.parseFloat(Data);
  105. tseries.addOrUpdate(new Second(new Date()),Dat);
  106. }
  107. private byte [] ReturnNewBytes(byte [] DataIn)
  108. {
  109. byte [] DataOut = new byte[5];
  110. DataOut[0] = DataIn[1];
  111. DataOut[1] = DataIn[2];
  112. DataOut[2] = '.';
  113. DataOut[3] = DataIn[4];
  114.  
  115. return DataOut;
  116. }
  117. public static void startTimer() 
  118. {
  119.     mainTmr = new Timer();
  120. mainTmr.schedule((new TimerChhRunCls()),1000,timeSampleLong);
  121. }
  122. class TimerChhRunCls extends TimerTask 
  123. {
  124. public void run() 
  125. {
  126. ReadTemperatureFromRS232();
  127. }
  128.  
  129. }
  130.  
  131. class TimerTestRun extends TimerTask 
  132. {
  133. public void run() 
  134. {
  135. UpdateBoxAndGraph();
  136. }
  137.  
  138. }
  139. private void UpdateBoxAndGraph()
  140. {
  141. GenCount++;
  142. jTextField2.setText(Integer.toString(GenCount));
  143. float Dat = Float.parseFloat("13.4");
  144. Dat = Dat + GenCount;
  145. tseries.addOrUpdate(new Second(new Date()),Dat);
  146.  
  147.  
  148. }
  149. private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { 
  150.  
  151. try
  152. {
  153.      Comm = new TwoWaySerialComm();
  154. Comm.connect(ComPort);
  155.      }
  156.      catch ( Exception e )
  157.      {
  158.  
  159.      e.printStackTrace();
  160.      }
  161.  
  162. private TimeSeriesCollection createDataset() 
  163. {
  164. TimeSeries ts = new TimeSeries("T", Second.class);
  165. TimeSeriesCollection dataset = new TimeSeriesCollection();
  166. dataset.addSeries(ts);
  167. ts.setMaximumItemAge(30*60);
  168. return dataset;
  169. }
  170.  
  171. public static void main(String args[]) {
  172. java.awt.EventQueue.invokeLater(new Runnable() {
  173. public void run() {
  174. new TestForm().setVisible(true);
  175. }
  176. });
  177. }
  178.  
  179. // Variables declaration - do not modify 
  180. private javax.swing.JButton jButton1;
  181. private javax.swing.JButton jButton2;
  182. private javax.swing.JButton jButton4;
  183. private javax.swing.JButton jButton5;
  184. private javax.swing.JButton jButton6;
  185. private javax.swing.JComboBox jComboBox1;
  186. private javax.swing.JFrame jFrame1;
  187. private javax.swing.JLabel jLabel1;
  188. private javax.swing.JLabel jLabel2;
  189. private javax.swing.JPanel jPanel1;
  190. public static javax.swing.JTextField jTextField1;
  191. private javax.swing.JTextField jTextField2;
  192. private javax.swing.JTextField jTextField3;
  193. private javax.swing.JTextField jTextField4;
  194. private javax.swing.JTextField jTextField5;
  195. // End of variables declaration 
  196.  
  197.  
  198. }
  199.  
No that cannot be the line with the error this time. Check again with both startTimer and timeSampleLong declared as static and check the line number for the error and error method.

I have to go in about 30mins or so, so please try to respond soon.
Feb 15 '07 #17
r035198x
13,262 8TB
Expand|Select|Wrap|Line Numbers
  1. testcomm.TestForm.startTimer() ;
You are trying to call a .startTimer() method from the TestForm class, but it should be called from a Timer. Try

Expand|Select|Wrap|Line Numbers
  1. testcomm.TestForm.mainTmr.startTimer();
or just

Expand|Select|Wrap|Line Numbers
  1. mainTmr.startTimer();
Yes. Try this with both startTimer and timeSampleLong declared as non-static.
Feb 15 '07 #18
Now this appeares:
cannot find symbol.
symbol: metod startTimer()
location: class java.util.Timer
when i go with mouse on the error line:
testcomm.TestForm.mainTmr.startTimer();

and when i write "." after:
testcomm.TestForm.mainTmr
there are no startTimer metod to choise it.

If i try with:
mainTimer.startTimer();
it look after only in Setting class


I'm sending class Setting; it's another JFrame from where am i maneging parameters

Expand|Select|Wrap|Line Numbers
  1. package testcomm;
  2.  
  3. public class Setting extends javax.swing.JFrame {
  4.  
  5.     /** Creates new form Setting */
  6.     public Setting() {
  7.         initComponents();
  8.     }
  9.  
  10.  
  11.     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">                          
  12.     private void initComponents() {
  13.         jLabel1 = new javax.swing.JLabel();
  14.         jComboBox1 = new javax.swing.JComboBox();
  15.         jLabel2 = new javax.swing.JLabel();
  16.         jComboBox2 = new javax.swing.JComboBox();
  17.         jLabel3 = new javax.swing.JLabel();
  18.         jComboBox3 = new javax.swing.JComboBox();
  19.         jButton1 = new javax.swing.JButton();
  20.  
  21.         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  22.         getAccessibleContext().setAccessibleName("Params");
  23.         jLabel1.setFont(new java.awt.Font("Tahoma", 0, 14));
  24.         jLabel1.setText("Zeljena Temperatura");
  25.  
  26.         jComboBox1.setFont(new java.awt.Font("Tahoma", 0, 14));
  27.         jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "213", "251", "302" }));
  28.  
  29.         jLabel2.setFont(new java.awt.Font("Tahoma", 0, 14));
  30.         jLabel2.setText("Dov. Odstopanje");
  31.  
  32.         jComboBox2.setFont(new java.awt.Font("Tahoma", 0, 14));
  33.         jComboBox2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "002", "003", "005", "008", "001" }));
  34.  
  35.         jLabel3.setFont(new java.awt.Font("Tahoma", 0, 14));
  36.         jLabel3.setText("Kriti\u010dna Temperatura");
  37.  
  38.         jComboBox3.setFont(new java.awt.Font("Tahoma", 0, 14));
  39.         jComboBox3.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "400", "450", "500" }));
  40.  
  41.         jButton1.setText("Set Parameters");
  42.         jButton1.addActionListener(new java.awt.event.ActionListener() {
  43.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  44.                 jButton1ActionPerformed(evt);
  45.             }
  46.         });
  47.  
  48.         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  49.         getContentPane().setLayout(layout);
  50.         layout.setHorizontalGroup(
  51.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  52.             .addGroup(layout.createSequentialGroup()
  53.                 .addGap(33, 33, 33)
  54.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
  55.                     .addComponent(jButton1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  56.                     .addComponent(jComboBox1, javax.swing.GroupLayout.Alignment.LEADING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  57.                     .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  58.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  59.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
  60.                     .addComponent(jComboBox2, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  61.                     .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  62.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  63.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
  64.                     .addComponent(jComboBox3, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  65.                     .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  66.                 .addContainerGap(45, Short.MAX_VALUE))
  67.         );
  68.         layout.setVerticalGroup(
  69.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  70.             .addGroup(layout.createSequentialGroup()
  71.                 .addGap(27, 27, 27)
  72.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  73.                     .addComponent(jLabel3)
  74.                     .addComponent(jLabel2)
  75.                     .addGroup(layout.createSequentialGroup()
  76.                         .addComponent(jLabel1)
  77.                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  78.                         .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  79.                             .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
  80.                             .addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
  81.                             .addComponent(jComboBox3, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE))))
  82.                 .addGap(26, 26, 26)
  83.                 .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
  84.                 .addContainerGap(25, Short.MAX_VALUE))
  85.         );
  86.         pack();
  87.     }// </editor-fold>                        
  88.  
  89.     private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
  90.  
  91.         String ZelTemp = jComboBox1.getSelectedItem().toString();
  92.         String HistTemp = jComboBox2.getSelectedItem().toString();
  93.         String KritTemp = jComboBox3.getSelectedItem().toString();
  94.  
  95.         if(testcomm.TestForm.mainTmr != null)
  96.            testcomm.TestForm.mainTmr.cancel();      
  97.  
  98.         testcomm.TestForm.WriteParamToPic("w"+ZelTemp);
  99.        try {
  100.               Thread.sleep (15);
  101.               }
  102.           catch ( Exception ex ) {
  103.                      ex.printStackTrace();
  104.                }
  105.        testcomm.TestForm.WriteParamToPic("h"+HistTemp);
  106.        try {
  107.               Thread.sleep (15);
  108.               }
  109.           catch ( Exception ex ) {
  110.                      ex.printStackTrace();
  111.                }
  112.        testcomm.TestForm.WriteParamToPic("c"+KritTemp);
  113.  
  114.       testcomm.TestForm.mainTmr.startTimer();
  115.         // non static metod cannot be referenced from static contrxt
  116.     }                                        
  117.  
  118.  
  119.     public static void main(String args[]) {
  120.         java.awt.EventQueue.invokeLater(new Runnable() {
  121.             public void run() {
  122.                 new Setting().setVisible(true);
  123.             }
  124.         });
  125.     }
  126.  
  127.     // Variables declaration - do not modify                     
  128.     private javax.swing.JButton jButton1;
  129.     private javax.swing.JComboBox jComboBox1;
  130.     private javax.swing.JComboBox jComboBox2;
  131.     private javax.swing.JComboBox jComboBox3;
  132.     private javax.swing.JLabel jLabel1;
  133.     private javax.swing.JLabel jLabel2;
  134.     private javax.swing.JLabel jLabel3;
  135.     // End of variables declaration                   
  136.  
  137. }
  138.  
Feb 15 '07 #19
r035198x
13,262 8TB
Now this appeares:
cannot find symbol.
symbol: metod startTimer()
location: class java.util.Timer
when i go with mouse on the error line:
testcomm.TestForm.mainTmr.startTimer();

and when i write "." after:
testcomm.TestForm.mainTmr
there are no startTimer metod to choise it.

If i try with:
mainTimer.startTimer();
it look after only in Setting class


I'm sending class Setting; it's another JFrame from where am i maneging parameters

Expand|Select|Wrap|Line Numbers
  1. package testcomm;
  2.  
  3. public class Setting extends javax.swing.JFrame {
  4.  
  5. /** Creates new form Setting */
  6. public Setting() {
  7. initComponents();
  8. }
  9.  
  10.  
  11. // <editor-fold defaultstate="collapsed" desc=" Generated Code "> 
  12. private void initComponents() {
  13. jLabel1 = new javax.swing.JLabel();
  14. jComboBox1 = new javax.swing.JComboBox();
  15. jLabel2 = new javax.swing.JLabel();
  16. jComboBox2 = new javax.swing.JComboBox();
  17. jLabel3 = new javax.swing.JLabel();
  18. jComboBox3 = new javax.swing.JComboBox();
  19. jButton1 = new javax.swing.JButton();
  20.  
  21. setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  22. getAccessibleContext().setAccessibleName("Params");
  23. jLabel1.setFont(new java.awt.Font("Tahoma", 0, 14));
  24. jLabel1.setText("Zeljena Temperatura");
  25.  
  26. jComboBox1.setFont(new java.awt.Font("Tahoma", 0, 14));
  27. jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "213", "251", "302" }));
  28.  
  29. jLabel2.setFont(new java.awt.Font("Tahoma", 0, 14));
  30. jLabel2.setText("Dov. Odstopanje");
  31.  
  32. jComboBox2.setFont(new java.awt.Font("Tahoma", 0, 14));
  33. jComboBox2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "002", "003", "005", "008", "001" }));
  34.  
  35. jLabel3.setFont(new java.awt.Font("Tahoma", 0, 14));
  36. jLabel3.setText("Kriti\u010dna Temperatura");
  37.  
  38. jComboBox3.setFont(new java.awt.Font("Tahoma", 0, 14));
  39. jComboBox3.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "400", "450", "500" }));
  40.  
  41. jButton1.setText("Set Parameters");
  42. jButton1.addActionListener(new java.awt.event.ActionListener() {
  43. public void actionPerformed(java.awt.event.ActionEvent evt) {
  44. jButton1ActionPerformed(evt);
  45. }
  46. });
  47.  
  48. javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  49. getContentPane().setLayout(layout);
  50. layout.setHorizontalGroup(
  51. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  52. .addGroup(layout.createSequentialGroup()
  53. .addGap(33, 33, 33)
  54. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
  55. .addComponent(jButton1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  56. .addComponent(jComboBox1, javax.swing.GroupLayout.Alignment.LEADING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  57. .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  58. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  59. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
  60. .addComponent(jComboBox2, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  61. .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  62. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  63. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
  64. .addComponent(jComboBox3, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  65. .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  66. .addContainerGap(45, Short.MAX_VALUE))
  67. );
  68. layout.setVerticalGroup(
  69. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  70. .addGroup(layout.createSequentialGroup()
  71. .addGap(27, 27, 27)
  72. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  73. .addComponent(jLabel3)
  74. .addComponent(jLabel2)
  75. .addGroup(layout.createSequentialGroup()
  76. .addComponent(jLabel1)
  77. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  78. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  79. .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
  80. .addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
  81. .addComponent(jComboBox3, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE))))
  82. .addGap(26, 26, 26)
  83. .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
  84. .addContainerGap(25, Short.MAX_VALUE))
  85. );
  86. pack();
  87. }// </editor-fold> 
  88.  
  89. private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { 
  90.  
  91. String ZelTemp = jComboBox1.getSelectedItem().toString();
  92. String HistTemp = jComboBox2.getSelectedItem().toString();
  93. String KritTemp = jComboBox3.getSelectedItem().toString();
  94.  
  95. if(testcomm.TestForm.mainTmr != null)
  96. testcomm.TestForm.mainTmr.cancel(); 
  97.  
  98. testcomm.TestForm.WriteParamToPic("w"+ZelTemp);
  99. try {
  100. Thread.sleep (15);
  101. }
  102. catch ( Exception ex ) {
  103. ex.printStackTrace();
  104. }
  105. testcomm.TestForm.WriteParamToPic("h"+HistTemp);
  106. try {
  107. Thread.sleep (15);
  108. }
  109. catch ( Exception ex ) {
  110. ex.printStackTrace();
  111. }
  112. testcomm.TestForm.WriteParamToPic("c"+KritTemp);
  113.  
  114. testcomm.TestForm.mainTmr.startTimer();
  115. // non static metod cannot be referenced from static contrxt
  116.  
  117.  
  118. public static void main(String args[]) {
  119. java.awt.EventQueue.invokeLater(new Runnable() {
  120. public void run() {
  121. new Setting().setVisible(true);
  122. }
  123. });
  124. }
  125.  
  126. // Variables declaration - do not modify 
  127. private javax.swing.JButton jButton1;
  128. private javax.swing.JComboBox jComboBox1;
  129. private javax.swing.JComboBox jComboBox2;
  130. private javax.swing.JComboBox jComboBox3;
  131. private javax.swing.JLabel jLabel1;
  132. private javax.swing.JLabel jLabel2;
  133. private javax.swing.JLabel jLabel3;
  134. // End of variables declaration 
  135.  
  136. }
  137.  
Ok then. I think we should get it back to having the timer as static. Make the neccessary adjustments to get it back to static and post the error that you are getting. It should be easier now that we have much of the code posted.
Feb 16 '07 #20
Expand|Select|Wrap|Line Numbers
  1. public static void  startTimer() 
  2.     {
  3.     mainTmr = new Timer();
  4.         mainTmr.schedule((new TimerChhRunCls()),1000,timeSampleLong);
  5.     }

i got next error:

non-static variable this cannot be refereced from a static context

and it refers for the las line of code.
Feb 16 '07 #21
r035198x
13,262 8TB
Expand|Select|Wrap|Line Numbers
  1. public static void startTimer() 
  2. {
  3.     mainTmr = new Timer();
  4. mainTmr.schedule((new TimerChhRunCls()),1000,timeSampleLong);
  5. }

i got next error:

non-static variable this cannot be refereced from a static context

and it refers for the las line of code.
But you did not use the variable this, in that method. Are you sure the error refers to that method? Which line does it specifically say has this error?
Feb 16 '07 #22
it's looks that it refers refers to the method TimerChhRunCls
because when i change it to static the error disappears.

but then i have to change other "things" to static; and so on until i get to the JTextField2, which can't be changed.

So i decided to move all from second class to first.
In that way i hope will exclude this problem.

Am working on it now. And in this way i think that it would be even beater.
I have to finish it today because tomorrow i plane to work on text of my thesis.

Probably lately i'll have to fix other things. I have in plan just another thing do do.
To make text of one variable (temperature) been visible near icon Java in task bar.

Thank you again.
Feb 16 '07 #23
For drawing of graph am reading data at specified time drove by timer.
So if i wont to communicate with microcontroler i have to stop timer and then i may read or write value of new parameters and then activate timer again.

I may stop timer but it doesn't mean that i have stop reading data for writing graph and if am trying to deal with parameters system goes in tilt.

I don't wont to complicate with parallel treads.
So if it it could be done in way to activate some flag when graph transmission is active, and make parameter transmission to control that flag. And wit of deactivation of the flag to proceed of parameter transmission.

Something like this:

a =1
read data for graph
a=0


do while( a=1){
wait
}
write or read parameters
Feb 17 '07 #24
I'll continue to work on my application until it well be as i like it.


I have connected the variable of measured temperature to title of JFrame..
So i me see the value of temperature into taskbar near the Java icon.
Maybe the resolution for next problem isn't so complicate.
Hove can i make the title of JFrame to be seen only in taskbar line and not as a title of JFrame window?
Feb 18 '07 #25
r035198x
13,262 8TB
I'll continue to work on my application until it well be as i like it.


I have connected the variable of measured temperature to title of JFrame..
So i me see the value of temperature into taskbar near the Java icon.
Maybe the resolution for next problem isn't so complicate.
Hove can i make the title of JFrame to be seen only in taskbar line and not as a title of JFrame window?
Strange requirement and interesting problem too. I'm not sure if it can be solved. stIconImage will set an image to be displayed on the title bar when minimized (depends on the platform). If you can somehow get your temperature into an image that would be it but probably not worth the work required for that.
Feb 19 '07 #26
Maybe it is more simple
to find out have it can be made that title of the frame is visible only when frame is minimized.
Feb 19 '07 #27
r035198x
13,262 8TB
Maybe it is more simple
to find out have it can be made that title of the frame is visible only when frame is minimized.
Yes this should be possible. Just look up the event for minimised I think it's windowIconified. Would then have to call repaint so the change is reflected and after that call setVisible(false) to minimize it.
Feb 19 '07 #28
I was not able to use repaint and setVisible(false).

But from yours suggestion to use windowIconified
I had got to the next funny code(which also works):


Expand|Select|Wrap|Line Numbers
  1.    a=1; // for initialization (first time)
  2. private void formWindowStateChanged(java.awt.event.WindowEvent evt) {                                        
  3. if (a==1){
  4.     setTitle("hallo");
  5.     a=0;
  6.        }
  7. else{
  8.     setTitle("");
  9.      a=1;
  10. }

And laity (because I felt that it must be some way)I found out formWindowDeiconified and the problem was resolved :
Thank you

Expand|Select|Wrap|Line Numbers
  1.     private void formWindowIconified(java.awt.event.WindowEvent evt) {                                     
  2. setTitle("hallo");
  3.     }                                    
  4.  
  5.     private void formWindowDeiconified(java.awt.event.WindowEvent evt) {                                       
  6. setTitle("");
  7.     }                                      
  8.  
  9.  
  10.  
Feb 19 '07 #29
r035198x
13,262 8TB
I was not able to use repaint and setVisible(false).

But from yours suggestion to use windowIconified
I had got to the next funny code(which also works):


Expand|Select|Wrap|Line Numbers
  1. a=1; // for initialization (first time)
  2. private void formWindowStateChanged(java.awt.event.WindowEvent evt) { 
  3. if (a==1){
  4. setTitle("hallo");
  5. a=0;
  6. }
  7. else{
  8. setTitle("");
  9. a=1;
  10. }

And laity (because I felt that it must be some way)I found out formWindowDeiconified and the problem was resolved :
Thank you

Expand|Select|Wrap|Line Numbers
  1. private void formWindowIconified(java.awt.event.WindowEvent evt) { 
  2. setTitle("hallo");
  3.  
  4. private void formWindowDeiconified(java.awt.event.WindowEvent evt) { 
  5. setTitle("");
  6.  
  7.  
  8.  

Good work! You'll surely become a very good Java programmer if you keep at it.
Feb 20 '07 #30
Next metod gets data for graph:

Expand|Select|Wrap|Line Numbers
  1. private void ReadTemperatureFromRS232()
  2.     {
  3.         if(readReservated ==0){
  4.         timeReservated =1;
  5.         Data = ReadParamFromPIC('R');
  6.         timeReservated=0;
  7.         buckupData = Data ;
  8.         }
  9.         else {
  10.             Data = buckupData;
  11.         }
  12.         float Dat = Float.parseFloat(Data);
  13.         tseries.addOrUpdate(new Second(new Date()),Dat);
  14.  
  15. private TimeSeriesCollection createDataset()
  16.     {
  17.         TimeSeries ts = new TimeSeries("Actual Temperature", Second.class); 
  18.         TimeSeriesCollection dataset = new TimeSeriesCollection();
  19.         dataset.addSeries(ts);      
  20.         ts.setMaximumItemAge(30*60);
  21.         return dataset;
  22.  
  23.     }
And in this way the graph is drowen:

Expand|Select|Wrap|Line Numbers
  1.  private void DrawGraph()
  2.     {
  3.         dataset = createDataset();
  4.         TCh = new TChartWrite();
  5.         MainChrt = TCh.createChart(dataset);
  6.         MainChartPnl = new ChartPanel(MainChrt);
  7.         MainChartPnl.setBounds(0,0,640,480);
  8.         jPanel1.add(MainChartPnl);
  9.         jPanel1.setVisible( true );
  10.         MainChartPnl.validate();
  11.         tseries = dataset.getSeries(0);
  12.     }
  13.  
  14.  
  15.     }
This code works good.
But i would like to draw another parameter in the same graph. Now i have "Actual" temperature, but i also need "Wished" temperature.
I can use first metod (ReadTemperatureFromRS232()) to get second parameter by line in code: Data2 = ReadParamFromPIC('W');
But then have to integrate it in dataset(tseris). Here is the point where i'm out.

What is the way to reselve this problem?
Mar 2 '07 #31
I have moved to new post:



Two parameters into graph
Mar 2 '07 #32

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: CM | last post by:
Hi, when i want connect me in my BD with a JSP (with this simple code), this exception is throw. Thank's for ur help Mathieu CODE of my JSP ---------------------
2
by: David Stevenson | last post by:
Programs from: Sheng Liang, The Java Native Interface, Programmer's Guide and Specification, The Java Series, (c) 1999, pp. 38-39. I thought I copied the program pretty exactly, but I don't know...
6
by: ganesh.m | last post by:
Hi, I am new to DB2. I am getting this error while loading the DB2Driver. I don't have any idea about where i might have gone wrong. please help me. Below is the stack trace. Stack Trace:...
2
oll3i
by: oll3i | last post by:
Hi! i just started learning java ;] i wanna write bank accounts program i get an error i know its in login method but i dont know where :\ cd u please help me with this one the code below...
5
by: cazconv2007 | last post by:
hi i need to catch and try exceptions , one for int and one for an array out of bounds i dont undertand how my code is'nt working for array out of bounds heres my code import java.util.* ; ...
22
oll3i
by: oll3i | last post by:
i get Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 2 at Producent.main(producent.java:605) when i run it from bat @start "Supply Chain Management-Producer to...
2
by: Richard Maher | last post by:
Hi, I would dearly love a server with a "self-signed certificate" to be accessible by my javax.net.ssl.startHandshake() but it seems to consistently crap-out with a failure :-( Look I've only...
0
RedSon
by: RedSon | last post by:
Chapter 2: How to handle Exceptions When you call a program, sometimes you get a message about an Unhandled exception type. This means, that something throws (or might throw) an Exception, but the...
6
by: Light | last post by:
Hi I m getting this error while i m trying to run my program and i don't understand why that happens. import java.util.*; public class Exercise6 {
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.