Board index » jbuilder » how to passing value from one Class to another Class

how to passing value from one Class to another Class


2005-07-14 07:42:59 AM
jbuilder7
Hi,
I want to be able to pass values from one class to another class.
I have the following classes
FCO_dataDisplay_Panel1
FCO_graphDisplay_Panel1 ...
Passing the following values Sensor_ID,Date_time, Run_time from
FCO_dataDisplay_Panel1
To
FCO_graphDisplay_Panel1, so that it can to use the same values.
Here's what I have so far...
In FCO_graphDisplay_Panel1 source code, I added the following code.
how would I assign each of the values to the a variable in
FCO_graphDisplay_Panel1, so that it can use the same values as in
FCO_dataDisplay_Panel1 ?
//--get data from database--------------
private XYDataset readData() {
JDBCXYDataset data = null;
String beginDate, endDate = null;
int sensorID = null;
FCO_dataDisplay_Panel1 dataDisplay = new FCO_dataDisplay_Panel1();
//--test to see if the value passed successfully...
beginDate = dataEntry.jdbTextField1.getText();
System.out.println("The sensorID is" + beginDate);
try {
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
Connection conn = DriverManager.getConnection(
"jdbc:oracle:thin:@dummy.company.com:1521:cdecdb02", "oradba",
"oradba");
String sql ="Select date_time, value as Candidate from ressim_hourly
where sensor_Id =" + sensorID +
" date_time>=" + beginDate + "and run_time =" + endDate;
Statement stmt = conn.createStatement();
ResultSet rset = stmt.executeQuery(sql);
data = new JDBCXYDataset(conn);
data.executeQuery(sql);
/*
while (rset.next()) {
System.out.println(rset.getString(1) + " " + (rset.getString(2)));
//System.out.println(rset.getString(1));
//System.out.println(rset.getString(2));
}
stmt.close(); */
} catch (SQLException ex) {
System.err.print(ex.getMessage());
}
return data;
}
Thanks,
Tom
 
 

Re:how to passing value from one Class to another Class

tom wrote:
Quote
I want to be able to pass values from one class to another class.

I have the following classes

FCO_dataDisplay_Panel1
FCO_graphDisplay_Panel1 ...


Passing the following values Sensor_ID,Date_time, Run_time from
FCO_dataDisplay_Panel1
First of all, what you're asking her is a very basic Java question. It
is not dbSwing related and so doesn't belong in this group; I've set
the follow up to the java.language group.
In general, sharing values is pretty straightforward; my preferred
approach would be to have a data class of some kind that both share:
public class Panel1 extends JPanel {
private MyData data;
public void setMyData(MyData data) {
this.data = data;
// Do something with the data (e.g. update graph).
}
...
}
Do the same for Panel2, then in some central routine:
MyData data = getMyDataFromSomewhere();
panel1.setMyData(data);
panel2.setMyData(data);
Both panels will now share the same data object.
--
Kevin Dean [TeamB]
Dolphin Data Development Ltd.
www.datadevelopment.com/
NEW WHITEPAPERS
Team Development with JBuilder and Borland Enterprise Server
Securing Borland Enterprise Server
www.datadevelopment.com/papers/index.html
Please see Borland's newsgroup guidelines at
info.borland.com/newsgroups/guide.html
 

Re:how to passing value from one Class to another Class

Hi There,
In my stituation, it's a little different. I'm developing a MDI application
that contains multiple internal frames.
Each internal frame is a JPanel and can access to database for both data
entry and editing.
Initially, the user open the Main JInternalFrame JPanel , which contains
data entry and data display.
I want to be able to pass certain key data entry fields to other
JInternalFrame JPanels.
The problem is that the other JInternalFrame JPanels is not active or
running at the moment when the Main JInternalFrame JPanel is running. If
the user decided to run the graphing module (a JInternalFrame JPanel), it
should get the input values from the Main JInternalFrame JPanel and use that
as input parameters to query the database.
Also, how can I disable the menu_item for certain JInternalFrame B if
JInternalFram B requires JInternalFrame A to be running first so that A can
supply the necessary input values for B.
Thanks,
Tom
"tom" < XXXX@XXXXX.COM >wrote in message
Quote
Hi,

I want to be able to pass values from one class to another class.

I have the following classes

FCO_dataDisplay_Panel1
FCO_graphDisplay_Panel1 ...


Passing the following values Sensor_ID,Date_time, Run_time from
FCO_dataDisplay_Panel1

To

FCO_graphDisplay_Panel1, so that it can to use the same values.


Here's what I have so far...
In FCO_graphDisplay_Panel1 source code, I added the following code.


how would I assign each of the values to the a variable in
FCO_graphDisplay_Panel1, so that it can use the same values as in
FCO_dataDisplay_Panel1 ?

//--get data from database--------------
private XYDataset readData() {

JDBCXYDataset data = null;
String beginDate, endDate = null;
int sensorID = null;

FCO_dataDisplay_Panel1 dataDisplay = new FCO_dataDisplay_Panel1();
//--test to see if the value passed successfully...
beginDate = dataEntry.jdbTextField1.getText();
System.out.println("The sensorID is" + beginDate);



try {
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
Connection conn = DriverManager.getConnection(
"jdbc:oracle:thin:@dummy.company.com:1521:cdecdb02", "oradba",
"oradba");

String sql ="Select date_time, value as Candidate from ressim_hourly
where sensor_Id =" + sensorID +
" date_time>=" + beginDate + "and run_time =" + endDate;
Statement stmt = conn.createStatement();
ResultSet rset = stmt.executeQuery(sql);
data = new JDBCXYDataset(conn);
data.executeQuery(sql);


/*
while (rset.next()) {
System.out.println(rset.getString(1) + " " + (rset.getString(2)));
//System.out.println(rset.getString(1));
//System.out.println(rset.getString(2));

}
stmt.close(); */

} catch (SQLException ex) {
System.err.print(ex.getMessage());
}

return data;

}








Thanks,

Tom



 

{smallsort}

Re:how to passing value from one Class to another Class

tom wrote:
Quote
In my stituation, it's a little different. I'm developing a MDI
application that contains multiple internal frames. Each internal
frame is a JPanel and can access to database for both data entry and
editing.

Initially, the user open the Main JInternalFrame JPanel , which
contains data entry and data display. I want to be able to pass
certain key data entry fields to other JInternalFrame JPanels.

The problem is that the other JInternalFrame JPanels is not active or
running at the moment when the Main JInternalFrame JPanel is running.
If the user decided to run the graphing module (a JInternalFrame
JPanel), it should get the input values from the Main JInternalFrame
JPanel and use that as input parameters to query the database.

Also, how can I disable the menu_item for certain JInternalFrame B if
JInternalFram B requires JInternalFrame A to be running first so that
A can supply the necessary input values for B.
It sounds very much like you need to setup some kind of listener, one
that will be called whenever input values or data change. Here's a
tutorial on writing event listeners:
java.sun.com/docs/books/tutorial/uiswing/events/
--
Kevin Dean [TeamB]
Dolphin Data Development Ltd.
www.datadevelopment.com/
NEW WHITEPAPERS
Team Development with JBuilder and Borland Enterprise Server
Securing Borland Enterprise Server
www.datadevelopment.com/papers/index.html
Please see Borland's newsgroup guidelines at
info.borland.com/newsgroups/guide.html
 

Re:how to passing value from one Class to another Class

Hi Kevin,
Your initial response was correct. I just over analyzed the problem.
It turns out that solution it's quite trivial. I just need to pass the
values from the parent MDI frame and save the data for subsquential child
frames.
Thanks,
Tom
"Kevin Dean [TeamB]" < XXXX@XXXXX.COM >wrote in message
Quote
tom wrote:

>In my stituation, it's a little different. I'm developing a MDI
>application that contains multiple internal frames. Each internal
>frame is a JPanel and can access to database for both data entry and
>editing.
>
>Initially, the user open the Main JInternalFrame JPanel , which
>contains data entry and data display. I want to be able to pass
>certain key data entry fields to other JInternalFrame JPanels.
>
>The problem is that the other JInternalFrame JPanels is not active or
>running at the moment when the Main JInternalFrame JPanel is running.
>If the user decided to run the graphing module (a JInternalFrame
>JPanel), it should get the input values from the Main JInternalFrame
>JPanel and use that as input parameters to query the database.
>
>Also, how can I disable the menu_item for certain JInternalFrame B if
>JInternalFram B requires JInternalFrame A to be running first so that
>A can supply the necessary input values for B.

It sounds very much like you need to setup some kind of listener, one
that will be called whenever input values or data change. Here's a
tutorial on writing event listeners:

java.sun.com/docs/books/tutorial/uiswing/events/

--
Kevin Dean [TeamB]
Dolphin Data Development Ltd.
www.datadevelopment.com/

NEW WHITEPAPERS
Team Development with JBuilder and Borland Enterprise Server
Securing Borland Enterprise Server
www.datadevelopment.com/papers/index.html

Please see Borland's newsgroup guidelines at
info.borland.com/newsgroups/guide.html