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
31 2414 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 - 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
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: - void PutPointerData(byte [] ChIn, int ChNumb)
-
{
-
try
-
{
-
OutStream.write(ChIn,0,ChNumb);
-
OutStream.flush();
-
} catch (IOException ex)
-
{
-
ex.printStackTrace();
-
}
-
}
-
And now i have a concrete problem: - public static void WriteParamToPic(String ParamIn)
-
{
-
char [] WriteParam = new char[4];
-
WriteParam =ParamIn.toCharArray();
-
for(int i=0; i<4; i++){
-
Comm.PutData((byte) WriteParam[i]) ;
-
}
-
}
-
-
// to send induvidual character
-
void PutData (byte ChIn)
-
{
-
try {
-
OutStream.write((byte) ChIn);
-
OutStream.flush();
-
} catch (IOException ex)
-
{
-
ex.printStackTrace();
-
}
-
}
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. - public static void WriteParamToPic(String ParamIn)
-
{
-
char [] WriteParam = new char[4];
-
WriteParam =ParamIn.toCharArray();
-
for(int i=0; i<4; i++){
-
Comm.charTimer(); //eror:create a metod charTimer() in testcomm.TwoWaySerialComm
-
Comm.PutData((byte) WriteParam[i]) ;
-
}
-
-
}
-
-
private void charTimer()
-
{
-
charTmr = new Timer();
-
charTmr.schedule(doNothing,1000); //error:create fild doNothing
-
}
And now i have a concrete problem: - public static void WriteParamToPic(String ParamIn)
-
{
-
char [] WriteParam = new char[4];
-
WriteParam =ParamIn.toCharArray();
-
for(int i=0; i<4; i++){
-
Comm.PutData((byte) WriteParam[i]) ;
-
}
-
}
-
-
// to send induvidual character
-
void PutData (byte ChIn)
-
{
-
try {
-
OutStream.write((byte) ChIn);
-
OutStream.flush();
-
} catch (IOException ex)
-
{
-
ex.printStackTrace();
-
}
-
}
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. - public static void WriteParamToPic(String ParamIn)
-
{
-
char [] WriteParam = new char[4];
-
WriteParam =ParamIn.toCharArray();
-
for(int i=0; i<4; i++){
-
Comm.charTimer(); //eror:create a metod charTimer() in testcomm.TwoWaySerialComm
-
Comm.PutData((byte) WriteParam[i]) ;
-
}
-
-
}
-
-
private void charTimer()
-
{
-
charTmr = new Timer();
-
charTmr.schedule(doNothing,1000); //error:create fild doNothing
-
}
You can use the Thread.sleep method
- public static void WriteParamToPic(String ParamIn)
-
{
-
char [] WriteParam = new char[4];
-
WriteParam =ParamIn.toCharArray();
-
for(int i=0; i<4; i++){
-
Comm.PutData((byte) WriteParam[i]) ;
-
try {
-
Thread.sleep (3);
-
}
-
catch ( Exception ex ) {
-
ex.printStackTrace();
-
}
-
}
-
-
}
In this way it works.
Thank you wery much.
- public static void WriteParamToPic(String ParamIn)
-
{
-
char [] WriteParam = new char[4];
-
WriteParam =ParamIn.toCharArray();
-
for(int i=0; i<4; i++){
-
Comm.PutData((byte) WriteParam[i]) ;
-
try {
-
Thread.sleep (3);
-
}
-
catch ( Exception ex ) {
-
ex.printStackTrace();
-
}
-
}
-
-
}
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.
- private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
-
-
-
if(testcomm.TestForm.mainTmr != null)
-
testcomm.TestForm.mainTmr.cancel();
-
-
//other code
-
-
testcomm.TestForm.startTimer() ;
-
// non static metod cannot be referenced from static contrxt
-
}
And timer: - public void startTimer()
-
{
-
mainTmr = new Timer();
-
mainTmr.schedule((new TimerChhRunCls()),1000,timeSampleLong);
-
}
-
class TimerChhRunCls extends TimerTask
-
{
-
public void run()
-
{
-
ReadTemperatureFromRS232();
-
}
-
-
}
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.
- private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
-
-
-
if(testcomm.TestForm.mainTmr != null)
-
testcomm.TestForm.mainTmr.cancel();
-
-
//other code
-
-
testcomm.TestForm.startTimer() ;
-
// non static metod cannot be referenced from static contrxt
-
}
And timer: - public void startTimer()
-
{
-
mainTmr = new Timer();
-
mainTmr.schedule((new TimerChhRunCls()),1000,timeSampleLong);
-
}
-
class TimerChhRunCls extends TimerTask
-
{
-
public void run()
-
{
-
ReadTemperatureFromRS232();
-
}
-
-
}
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.
// 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
// 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?
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);
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?
It's split in two:
First: -
package testcomm;
-
import java.awt.BorderLayout;
-
import java.util.Date;
-
import java.util.concurrent.locks.Lock;
-
import java.util.concurrent.locks.ReentrantLock;
-
import java.util.Timer;
-
import java.util.TimerTask;
-
import javax.swing.JButton;
-
import javax.swing.JFrame;
-
import javax.swing.JPanel;
-
import org.jfree.chart.ChartPanel;
-
import org.jfree.chart.JFreeChart;
-
import org.jfree.chart.JFreeChart;
-
import org.jfree.chart.demo.TimeSeriesChartDemo1;
-
import org.jfree.data.time.Second;
-
import org.jfree.data.time.TimeSeries;
-
import org.jfree.data.time.TimeSeriesCollection;
-
import org.jfree.ui.RefineryUtilities;
-
-
-
public class TestForm extends javax.swing.JFrame {
-
-
private Lock SendLock = new ReentrantLock();
-
private static String ComPort = "COM4";
-
-
-
TChartWrite TCh;
-
JFreeChart MainChrt;
-
ChartPanel MainChartPnl;
-
TimeSeriesCollection dataset;
-
TimeSeries tseries;
-
-
public static Timer mainTmr;
-
String timeSample;
-
static long timeSampleLong ;
-
public static TwoWaySerialComm Comm;
-
public static int Jajca = 0;
-
public static byte [] GenBuffer = new byte[1024];
-
public static int GenBuffCnt = 0;
-
public int GenCount=0;
-
-
/** Creates new form TestForm */
-
public TestForm() {
-
initComponents();
-
DrawGraph();
-
}
-
-
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">
-
private void initComponents() {
-
jFrame1 = new javax.swing.JFrame();
-
jButton1 = new javax.swing.JButton();
-
jButton2 = new javax.swing.JButton();
-
jPanel1 = new javax.swing.JPanel();
-
jLabel1 = new javax.swing.JLabel();
-
jTextField1 = new javax.swing.JTextField();
-
jLabel2 = new javax.swing.JLabel();
-
jTextField2 = new javax.swing.JTextField();
-
jButton4 = new javax.swing.JButton();
-
jButton5 = new javax.swing.JButton();
-
jButton6 = new javax.swing.JButton();
-
jTextField3 = new javax.swing.JTextField();
-
jTextField4 = new javax.swing.JTextField();
-
jTextField5 = new javax.swing.JTextField();
-
jComboBox1 = new javax.swing.JComboBox();
-
-
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)
-
);
-
-
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
-
setMinimumSize(new java.awt.Dimension(900, 600));
-
addWindowListener(new java.awt.event.WindowAdapter() {
-
public void windowActivated(java.awt.event.WindowEvent evt) {
-
formWindowActivated(evt);
-
}
-
});
-
-
jButton1.setText("OPEN");
-
jButton1.addActionListener(new java.awt.event.ActionListener() {
-
public void actionPerformed(java.awt.event.ActionEvent evt) {
-
jButton1ActionPerformed(evt);
-
}
-
});
-
-
jButton2.setText("Run Timer");
-
jButton2.addActionListener(new java.awt.event.ActionListener() {
-
public void actionPerformed(java.awt.event.ActionEvent evt) {
-
jButton2ActionPerformed(evt);
-
}
-
});
-
-
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
-
jPanel1.setLayout(jPanel1Layout);
-
jPanel1Layout.setHorizontalGroup(
-
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
-
.addGap(0, 404, Short.MAX_VALUE)
-
);
-
jPanel1Layout.setVerticalGroup(
-
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
-
.addGap(0, 246, Short.MAX_VALUE)
-
);
-
-
jLabel1.setText("Temperatura");
-
-
jTextField1.setText("25.55");
-
-
jLabel2.setText("\u0160tevec");
-
-
jTextField2.setText("10000");
-
-
jButton4.setText("Stop Timer");
-
jButton4.addActionListener(new java.awt.event.ActionListener() {
-
public void actionPerformed(java.awt.event.ActionEvent evt) {
-
jButton4ActionPerformed(evt);
-
}
-
});
-
-
jButton5.setText("Params");
-
jButton5.addActionListener(new java.awt.event.ActionListener() {
-
public void actionPerformed(java.awt.event.ActionEvent evt) {
-
jButton5ActionPerformed(evt);
-
}
-
});
-
-
jButton6.setText("Read");
-
jButton6.addActionListener(new java.awt.event.ActionListener() {
-
public void actionPerformed(java.awt.event.ActionEvent evt) {
-
jButton6ActionPerformed(evt);
-
}
-
});
-
-
jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1000", "10000", "100000", "1000000" }));
-
jComboBox1.addActionListener(new java.awt.event.ActionListener() {
-
public void actionPerformed(java.awt.event.ActionEvent evt) {
-
jComboBox1ActionPerformed(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()
-
.addContainerGap()
-
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
-
.addGroup(layout.createSequentialGroup()
-
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
-
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
-
.addGroup(layout.createSequentialGroup()
-
.addComponent(jLabel1)
-
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
-
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
-
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
-
.addComponent(jLabel2)
-
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
-
.addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
-
.addGap(22, 22, 22)
-
.addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
-
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
-
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
-
.addComponent(jButton6, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
-
.addComponent(jTextField3)
-
.addComponent(jTextField4)
-
.addComponent(jTextField5)))
-
.addGroup(layout.createSequentialGroup()
-
.addComponent(jButton1)
-
.addGap(119, 119, 119)
-
.addComponent(jButton2)
-
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
-
.addComponent(jButton4)
-
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
-
.addComponent(jButton5)
-
.addContainerGap())))
-
);
-
layout.setVerticalGroup(
-
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
-
.addGroup(layout.createSequentialGroup()
-
.addContainerGap()
-
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
-
.addComponent(jButton1)
-
.addComponent(jButton2)
-
.addComponent(jButton4)
-
.addComponent(jButton5))
-
and second: - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
-
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
-
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
-
.addComponent(jLabel1)
-
.addComponent(jLabel2)
-
.addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
-
.addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
-
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
-
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
-
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
-
.addGroup(layout.createSequentialGroup()
-
.addComponent(jButton6)
-
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
-
.addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
-
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
-
.addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
-
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
-
.addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
-
.addContainerGap())
-
);
-
pack();
-
}// </editor-fold>
-
-
private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {
-
-
timeSample = jComboBox1.getSelectedItem().toString();
-
timeSampleLong= Long.parseLong(timeSample);
-
}
-
-
private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {
-
String ZelTemp = ReadParamFromPIC('W');
-
String Histereza = ReadParamFromPIC('H');
-
String CritTemp = ReadParamFromPIC('C');
-
-
jTextField3.setText(ZelTemp);
-
jTextField4.setText(Histereza);
-
jTextField5.setText(CritTemp);
-
}
-
-
private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {
-
// if(mainTmr != null)
-
// mainTmr.cancel();
-
Setting Stng = new Setting();
-
Stng.setDefaultCloseOperation ( JFrame.EXIT_ON_CLOSE ) ;
-
Stng.setLocation ( 300 , 300 ) ;
-
Stng.setVisible ( true ) ;
-
}
-
-
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {
-
mainTmr.cancel();
-
}
-
-
private void formWindowActivated(java.awt.event.WindowEvent evt) {
-
// TODO add your handling code here:
-
}
-
private void DrawGraph()
-
{
-
dataset = createDataset();
-
TCh = new TChartWrite();
-
MainChrt = TCh.createChart(dataset);
-
MainChartPnl = new ChartPanel(MainChrt);
-
MainChartPnl.setBounds(0,0,640,480);
-
jPanel1.add(MainChartPnl);
-
jPanel1.setVisible( true );
-
MainChartPnl.validate();
-
tseries = dataset.getSeries(0);
-
}
-
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
-
// TODO add your handling code here:
-
startTimer();
-
}
-
-
//Branje in pisanje ComPorta!
-
public String ReadParamFromPIC(char ParamIn)
-
{
-
GenBuffCnt = 0;
-
Comm.PutData((byte)ParamIn);
-
if(GenBuffCnt > 5)
-
{
-
GenBuffCnt = 0;
-
return null;
-
}
-
while(GenBuffCnt!=5);
-
byte [] WriteBuff = ReturnNewBytes(GenBuffer);
-
String Data = new String(WriteBuff,0,4);
-
GenBuffCnt = 0;
-
return Data;
-
}
-
public static void WriteParamToPic(String ParamIn)
-
{
-
char [] WriteParam = new char[4];
-
WriteParam =ParamIn.toCharArray();
-
for(int i=0; i<4; i++){
-
Comm.PutData((byte) WriteParam[i]) ;
-
try {
-
Thread.sleep (3);
-
}
-
catch ( Exception ex ) {
-
ex.printStackTrace();
-
}
-
}
-
-
}
-
private void ReadTemperatureFromRS232()
-
{
-
String Data = ReadParamFromPIC('R');
-
jTextField1.setText(Data);
-
GenCount++;
-
jTextField2.setText(Integer.toString(GenCount));
-
float Dat = Float.parseFloat(Data);
-
tseries.addOrUpdate(new Second(new Date()),Dat);
-
}
-
private byte [] ReturnNewBytes(byte [] DataIn)
-
{
-
byte [] DataOut = new byte[5];
-
DataOut[0] = DataIn[1];
-
DataOut[1] = DataIn[2];
-
DataOut[2] = '.';
-
DataOut[3] = DataIn[4];
-
-
return DataOut;
-
}
-
public static void startTimer()
-
{
-
mainTmr = new Timer();
-
mainTmr.schedule((new TimerChhRunCls()),1000,timeSampleLong);
-
}
-
class TimerChhRunCls extends TimerTask
-
{
-
public void run()
-
{
-
ReadTemperatureFromRS232();
-
}
-
-
}
-
-
class TimerTestRun extends TimerTask
-
{
-
public void run()
-
{
-
UpdateBoxAndGraph();
-
}
-
-
}
-
private void UpdateBoxAndGraph()
-
{
-
GenCount++;
-
jTextField2.setText(Integer.toString(GenCount));
-
float Dat = Float.parseFloat("13.4");
-
Dat = Dat + GenCount;
-
tseries.addOrUpdate(new Second(new Date()),Dat);
-
-
-
}
-
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
-
-
try
-
{
-
Comm = new TwoWaySerialComm();
-
Comm.connect(ComPort);
-
}
-
catch ( Exception e )
-
{
-
-
e.printStackTrace();
-
}
-
-
}
-
private TimeSeriesCollection createDataset()
-
{
-
TimeSeries ts = new TimeSeries("T", Second.class);
-
TimeSeriesCollection dataset = new TimeSeriesCollection();
-
dataset.addSeries(ts);
-
ts.setMaximumItemAge(30*60);
-
return dataset;
-
}
-
-
public static void main(String args[]) {
-
java.awt.EventQueue.invokeLater(new Runnable() {
-
public void run() {
-
new TestForm().setVisible(true);
-
}
-
});
-
}
-
-
// Variables declaration - do not modify
-
private javax.swing.JButton jButton1;
-
private javax.swing.JButton jButton2;
-
private javax.swing.JButton jButton4;
-
private javax.swing.JButton jButton5;
-
private javax.swing.JButton jButton6;
-
private javax.swing.JComboBox jComboBox1;
-
private javax.swing.JFrame jFrame1;
-
private javax.swing.JLabel jLabel1;
-
private javax.swing.JLabel jLabel2;
-
private javax.swing.JPanel jPanel1;
-
public static javax.swing.JTextField jTextField1;
-
private javax.swing.JTextField jTextField2;
-
private javax.swing.JTextField jTextField3;
-
private javax.swing.JTextField jTextField4;
-
private javax.swing.JTextField jTextField5;
-
// End of variables declaration
-
-
-
}
-
- testcomm.TestForm.startTimer() ;
You are trying to call a .startTimer() method from the TestForm class, but it should be called from a Timer. Try - testcomm.TestForm.mainTmr.startTimer();
or just
and second: - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
-
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
-
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
-
.addComponent(jLabel1)
-
.addComponent(jLabel2)
-
.addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
-
.addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
-
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
-
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
-
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
-
.addGroup(layout.createSequentialGroup()
-
.addComponent(jButton6)
-
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
-
.addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
-
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
-
.addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
-
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
-
.addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
-
.addContainerGap())
-
);
-
pack();
-
}// </editor-fold>
-
-
private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {
-
-
timeSample = jComboBox1.getSelectedItem().toString();
-
timeSampleLong= Long.parseLong(timeSample);
-
}
-
-
private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {
-
String ZelTemp = ReadParamFromPIC('W');
-
String Histereza = ReadParamFromPIC('H');
-
String CritTemp = ReadParamFromPIC('C');
-
-
jTextField3.setText(ZelTemp);
-
jTextField4.setText(Histereza);
-
jTextField5.setText(CritTemp);
-
}
-
-
private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {
-
// if(mainTmr != null)
-
// mainTmr.cancel();
-
Setting Stng = new Setting();
-
Stng.setDefaultCloseOperation ( JFrame.EXIT_ON_CLOSE ) ;
-
Stng.setLocation ( 300 , 300 ) ;
-
Stng.setVisible ( true ) ;
-
}
-
-
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {
-
mainTmr.cancel();
-
}
-
-
private void formWindowActivated(java.awt.event.WindowEvent evt) {
-
// TODO add your handling code here:
-
}
-
private void DrawGraph()
-
{
-
dataset = createDataset();
-
TCh = new TChartWrite();
-
MainChrt = TCh.createChart(dataset);
-
MainChartPnl = new ChartPanel(MainChrt);
-
MainChartPnl.setBounds(0,0,640,480);
-
jPanel1.add(MainChartPnl);
-
jPanel1.setVisible( true );
-
MainChartPnl.validate();
-
tseries = dataset.getSeries(0);
-
}
-
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
-
// TODO add your handling code here:
-
startTimer();
-
}
-
-
//Branje in pisanje ComPorta!
-
public String ReadParamFromPIC(char ParamIn)
-
{
-
GenBuffCnt = 0;
-
Comm.PutData((byte)ParamIn);
-
if(GenBuffCnt > 5)
-
{
-
GenBuffCnt = 0;
-
return null;
-
}
-
while(GenBuffCnt!=5);
-
byte [] WriteBuff = ReturnNewBytes(GenBuffer);
-
String Data = new String(WriteBuff,0,4);
-
GenBuffCnt = 0;
-
return Data;
-
}
-
public static void WriteParamToPic(String ParamIn)
-
{
-
char [] WriteParam = new char[4];
-
WriteParam =ParamIn.toCharArray();
-
for(int i=0; i<4; i++){
-
Comm.PutData((byte) WriteParam[i]) ;
-
try {
-
Thread.sleep (3);
-
}
-
catch ( Exception ex ) {
-
ex.printStackTrace();
-
}
-
}
-
-
}
-
private void ReadTemperatureFromRS232()
-
{
-
String Data = ReadParamFromPIC('R');
-
jTextField1.setText(Data);
-
GenCount++;
-
jTextField2.setText(Integer.toString(GenCount));
-
float Dat = Float.parseFloat(Data);
-
tseries.addOrUpdate(new Second(new Date()),Dat);
-
}
-
private byte [] ReturnNewBytes(byte [] DataIn)
-
{
-
byte [] DataOut = new byte[5];
-
DataOut[0] = DataIn[1];
-
DataOut[1] = DataIn[2];
-
DataOut[2] = '.';
-
DataOut[3] = DataIn[4];
-
-
return DataOut;
-
}
-
public static void startTimer()
-
{
-
mainTmr = new Timer();
-
mainTmr.schedule((new TimerChhRunCls()),1000,timeSampleLong);
-
}
-
class TimerChhRunCls extends TimerTask
-
{
-
public void run()
-
{
-
ReadTemperatureFromRS232();
-
}
-
-
}
-
-
class TimerTestRun extends TimerTask
-
{
-
public void run()
-
{
-
UpdateBoxAndGraph();
-
}
-
-
}
-
private void UpdateBoxAndGraph()
-
{
-
GenCount++;
-
jTextField2.setText(Integer.toString(GenCount));
-
float Dat = Float.parseFloat("13.4");
-
Dat = Dat + GenCount;
-
tseries.addOrUpdate(new Second(new Date()),Dat);
-
-
-
}
-
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
-
-
try
-
{
-
Comm = new TwoWaySerialComm();
-
Comm.connect(ComPort);
-
}
-
catch ( Exception e )
-
{
-
-
e.printStackTrace();
-
}
-
-
}
-
private TimeSeriesCollection createDataset()
-
{
-
TimeSeries ts = new TimeSeries("T", Second.class);
-
TimeSeriesCollection dataset = new TimeSeriesCollection();
-
dataset.addSeries(ts);
-
ts.setMaximumItemAge(30*60);
-
return dataset;
-
}
-
-
public static void main(String args[]) {
-
java.awt.EventQueue.invokeLater(new Runnable() {
-
public void run() {
-
new TestForm().setVisible(true);
-
}
-
});
-
}
-
-
// Variables declaration - do not modify
-
private javax.swing.JButton jButton1;
-
private javax.swing.JButton jButton2;
-
private javax.swing.JButton jButton4;
-
private javax.swing.JButton jButton5;
-
private javax.swing.JButton jButton6;
-
private javax.swing.JComboBox jComboBox1;
-
private javax.swing.JFrame jFrame1;
-
private javax.swing.JLabel jLabel1;
-
private javax.swing.JLabel jLabel2;
-
private javax.swing.JPanel jPanel1;
-
public static javax.swing.JTextField jTextField1;
-
private javax.swing.JTextField jTextField2;
-
private javax.swing.JTextField jTextField3;
-
private javax.swing.JTextField jTextField4;
-
private javax.swing.JTextField jTextField5;
-
// End of variables declaration
-
-
-
}
-
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.
- testcomm.TestForm.startTimer() ;
You are trying to call a .startTimer() method from the TestForm class, but it should be called from a Timer. Try - testcomm.TestForm.mainTmr.startTimer();
or just
Yes. Try this with both startTimer and timeSampleLong declared as non-static.
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 - package testcomm;
-
-
public class Setting extends javax.swing.JFrame {
-
-
/** Creates new form Setting */
-
public Setting() {
-
initComponents();
-
}
-
-
-
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">
-
private void initComponents() {
-
jLabel1 = new javax.swing.JLabel();
-
jComboBox1 = new javax.swing.JComboBox();
-
jLabel2 = new javax.swing.JLabel();
-
jComboBox2 = new javax.swing.JComboBox();
-
jLabel3 = new javax.swing.JLabel();
-
jComboBox3 = new javax.swing.JComboBox();
-
jButton1 = new javax.swing.JButton();
-
-
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
-
getAccessibleContext().setAccessibleName("Params");
-
jLabel1.setFont(new java.awt.Font("Tahoma", 0, 14));
-
jLabel1.setText("Zeljena Temperatura");
-
-
jComboBox1.setFont(new java.awt.Font("Tahoma", 0, 14));
-
jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "213", "251", "302" }));
-
-
jLabel2.setFont(new java.awt.Font("Tahoma", 0, 14));
-
jLabel2.setText("Dov. Odstopanje");
-
-
jComboBox2.setFont(new java.awt.Font("Tahoma", 0, 14));
-
jComboBox2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "002", "003", "005", "008", "001" }));
-
-
jLabel3.setFont(new java.awt.Font("Tahoma", 0, 14));
-
jLabel3.setText("Kriti\u010dna Temperatura");
-
-
jComboBox3.setFont(new java.awt.Font("Tahoma", 0, 14));
-
jComboBox3.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "400", "450", "500" }));
-
-
jButton1.setText("Set Parameters");
-
jButton1.addActionListener(new java.awt.event.ActionListener() {
-
public void actionPerformed(java.awt.event.ActionEvent evt) {
-
jButton1ActionPerformed(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()
-
.addGap(33, 33, 33)
-
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
-
.addComponent(jButton1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
-
.addComponent(jComboBox1, javax.swing.GroupLayout.Alignment.LEADING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
-
.addComponent(jLabel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
-
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
-
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
-
.addComponent(jComboBox2, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
-
.addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
-
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
-
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
-
.addComponent(jComboBox3, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
-
.addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
-
.addContainerGap(45, Short.MAX_VALUE))
-
);
-
layout.setVerticalGroup(
-
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
-
.addGroup(layout.createSequentialGroup()
-
.addGap(27, 27, 27)
-
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
-
.addComponent(jLabel3)
-
.addComponent(jLabel2)
-
.addGroup(layout.createSequentialGroup()
-
.addComponent(jLabel1)
-
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
-
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
-
.addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
-
.addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
-
.addComponent(jComboBox3, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE))))
-
.addGap(26, 26, 26)
-
.addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
-
.addContainerGap(25, Short.MAX_VALUE))
-
);
-
pack();
-
}// </editor-fold>
-
-
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
-
-
String ZelTemp = jComboBox1.getSelectedItem().toString();
-
String HistTemp = jComboBox2.getSelectedItem().toString();
-
String KritTemp = jComboBox3.getSelectedItem().toString();
-
-
if(testcomm.TestForm.mainTmr != null)
-
testcomm.TestForm.mainTmr.cancel();
-
-
testcomm.TestForm.WriteParamToPic("w"+ZelTemp);
-
try {
-
Thread.sleep (15);
-
}
-
catch ( Exception ex ) {
-
ex.printStackTrace();
-
}
-
testcomm.TestForm.WriteParamToPic("h"+HistTemp);
-
try {
-
Thread.sleep (15);
-
}
-
catch ( Exception ex ) {
-
ex.printStackTrace();
-
}
-
testcomm.TestForm.WriteParamToPic("c"+KritTemp);
-
-
testcomm.TestForm.mainTmr.startTimer();
-
// non static metod cannot be referenced from static contrxt
-
}
-
-
-
public static void main(String args[]) {
-
java.awt.EventQueue.invokeLater(new Runnable() {
-
public void run() {
-
new Setting().setVisible(true);
-
}
-
});
-
}
-
-
// Variables declaration - do not modify
-
private javax.swing.JButton jButton1;
-
private javax.swing.JComboBox jComboBox1;
-
private javax.swing.JComboBox jComboBox2;
-
private javax.swing.JComboBox jComboBox3;
-
private javax.swing.JLabel jLabel1;
-
private javax.swing.JLabel jLabel2;
-
private javax.swing.JLabel jLabel3;
-
// End of variables declaration
-
-
}
-
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 - package testcomm;
-
-
public class Setting extends javax.swing.JFrame {
-
-
/** Creates new form Setting */
-
public Setting() {
-
initComponents();
-
}
-
-
-
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">
-
private void initComponents() {
-
jLabel1 = new javax.swing.JLabel();
-
jComboBox1 = new javax.swing.JComboBox();
-
jLabel2 = new javax.swing.JLabel();
-
jComboBox2 = new javax.swing.JComboBox();
-
jLabel3 = new javax.swing.JLabel();
-
jComboBox3 = new javax.swing.JComboBox();
-
jButton1 = new javax.swing.JButton();
-
-
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
-
getAccessibleContext().setAccessibleName("Params");
-
jLabel1.setFont(new java.awt.Font("Tahoma", 0, 14));
-
jLabel1.setText("Zeljena Temperatura");
-
-
jComboBox1.setFont(new java.awt.Font("Tahoma", 0, 14));
-
jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "213", "251", "302" }));
-
-
jLabel2.setFont(new java.awt.Font("Tahoma", 0, 14));
-
jLabel2.setText("Dov. Odstopanje");
-
-
jComboBox2.setFont(new java.awt.Font("Tahoma", 0, 14));
-
jComboBox2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "002", "003", "005", "008", "001" }));
-
-
jLabel3.setFont(new java.awt.Font("Tahoma", 0, 14));
-
jLabel3.setText("Kriti\u010dna Temperatura");
-
-
jComboBox3.setFont(new java.awt.Font("Tahoma", 0, 14));
-
jComboBox3.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "400", "450", "500" }));
-
-
jButton1.setText("Set Parameters");
-
jButton1.addActionListener(new java.awt.event.ActionListener() {
-
public void actionPerformed(java.awt.event.ActionEvent evt) {
-
jButton1ActionPerformed(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()
-
.addGap(33, 33, 33)
-
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
-
.addComponent(jButton1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
-
.addComponent(jComboBox1, javax.swing.GroupLayout.Alignment.LEADING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
-
.addComponent(jLabel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
-
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
-
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
-
.addComponent(jComboBox2, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
-
.addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
-
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
-
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
-
.addComponent(jComboBox3, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
-
.addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
-
.addContainerGap(45, Short.MAX_VALUE))
-
);
-
layout.setVerticalGroup(
-
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
-
.addGroup(layout.createSequentialGroup()
-
.addGap(27, 27, 27)
-
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
-
.addComponent(jLabel3)
-
.addComponent(jLabel2)
-
.addGroup(layout.createSequentialGroup()
-
.addComponent(jLabel1)
-
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
-
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
-
.addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
-
.addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
-
.addComponent(jComboBox3, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE))))
-
.addGap(26, 26, 26)
-
.addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
-
.addContainerGap(25, Short.MAX_VALUE))
-
);
-
pack();
-
}// </editor-fold>
-
-
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
-
-
String ZelTemp = jComboBox1.getSelectedItem().toString();
-
String HistTemp = jComboBox2.getSelectedItem().toString();
-
String KritTemp = jComboBox3.getSelectedItem().toString();
-
-
if(testcomm.TestForm.mainTmr != null)
-
testcomm.TestForm.mainTmr.cancel();
-
-
testcomm.TestForm.WriteParamToPic("w"+ZelTemp);
-
try {
-
Thread.sleep (15);
-
}
-
catch ( Exception ex ) {
-
ex.printStackTrace();
-
}
-
testcomm.TestForm.WriteParamToPic("h"+HistTemp);
-
try {
-
Thread.sleep (15);
-
}
-
catch ( Exception ex ) {
-
ex.printStackTrace();
-
}
-
testcomm.TestForm.WriteParamToPic("c"+KritTemp);
-
-
testcomm.TestForm.mainTmr.startTimer();
-
// non static metod cannot be referenced from static contrxt
-
}
-
-
-
public static void main(String args[]) {
-
java.awt.EventQueue.invokeLater(new Runnable() {
-
public void run() {
-
new Setting().setVisible(true);
-
}
-
});
-
}
-
-
// Variables declaration - do not modify
-
private javax.swing.JButton jButton1;
-
private javax.swing.JComboBox jComboBox1;
-
private javax.swing.JComboBox jComboBox2;
-
private javax.swing.JComboBox jComboBox3;
-
private javax.swing.JLabel jLabel1;
-
private javax.swing.JLabel jLabel2;
-
private javax.swing.JLabel jLabel3;
-
// End of variables declaration
-
-
}
-
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.
- public static void startTimer()
-
{
-
mainTmr = new Timer();
-
mainTmr.schedule((new TimerChhRunCls()),1000,timeSampleLong);
-
}
i got next error: non-static variable this cannot be refereced from a static context
and it refers for the las line of code.
- public static void startTimer()
-
{
-
mainTmr = new Timer();
-
mainTmr.schedule((new TimerChhRunCls()),1000,timeSampleLong);
-
}
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?
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.
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
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?
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.
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.
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.
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): -
a=1; // for initialization (first time)
-
private void formWindowStateChanged(java.awt.event.WindowEvent evt) {
-
if (a==1){
-
setTitle("hallo");
-
a=0;
-
}
-
else{
-
setTitle("");
-
a=1;
-
}
And laity (because I felt that it must be some way)I found out formWindowDeiconified and the problem was resolved :
Thank you -
private void formWindowIconified(java.awt.event.WindowEvent evt) {
-
setTitle("hallo");
-
}
-
-
private void formWindowDeiconified(java.awt.event.WindowEvent evt) {
-
setTitle("");
-
}
-
-
-
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): -
a=1; // for initialization (first time)
-
private void formWindowStateChanged(java.awt.event.WindowEvent evt) {
-
if (a==1){
-
setTitle("hallo");
-
a=0;
-
}
-
else{
-
setTitle("");
-
a=1;
-
}
And laity (because I felt that it must be some way)I found out formWindowDeiconified and the problem was resolved :
Thank you -
private void formWindowIconified(java.awt.event.WindowEvent evt) {
-
setTitle("hallo");
-
}
-
-
private void formWindowDeiconified(java.awt.event.WindowEvent evt) {
-
setTitle("");
-
}
-
-
-
Good work! You'll surely become a very good Java programmer if you keep at it.
Next metod gets data for graph: - private void ReadTemperatureFromRS232()
-
{
-
if(readReservated ==0){
-
timeReservated =1;
-
Data = ReadParamFromPIC('R');
-
timeReservated=0;
-
buckupData = Data ;
-
}
-
else {
-
Data = buckupData;
-
}
-
float Dat = Float.parseFloat(Data);
-
tseries.addOrUpdate(new Second(new Date()),Dat);
-
-
private TimeSeriesCollection createDataset()
-
{
-
TimeSeries ts = new TimeSeries("Actual Temperature", Second.class);
-
TimeSeriesCollection dataset = new TimeSeriesCollection();
-
dataset.addSeries(ts);
-
ts.setMaximumItemAge(30*60);
-
return dataset;
-
-
}
And in this way the graph is drowen: - private void DrawGraph()
-
{
-
dataset = createDataset();
-
TCh = new TChartWrite();
-
MainChrt = TCh.createChart(dataset);
-
MainChartPnl = new ChartPanel(MainChrt);
-
MainChartPnl.setBounds(0,0,640,480);
-
jPanel1.add(MainChartPnl);
-
jPanel1.setVisible( true );
-
MainChartPnl.validate();
-
tseries = dataset.getSeries(0);
-
}
-
-
-
}
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?
Sign in to post your reply or Sign up for a free account.
Similar topics
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
---------------------
|
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...
|
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:...
|
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...
|
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.* ;
...
|
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...
|
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...
|
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...
|
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 {
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
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,...
|
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...
| |