how to get reference of the jFrame object
hi all
this is arnab again and boggling with the reference problem..
i developed StartWindow, DispenseMain2 and MaintenanceMain three jFrame classes in three different file in the same package.
now i want to get reference of the object frame0 from DispenseMain2, how to do that?
here is the code (i used netbeans)
/*
* StartWindow.java
*
* Created on May 23, 2007, 12:33 PM
*/
package parcolorsoft;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.*;
import java.awt.event.*;
import javax.swing.event.*;
import javax.swing.border.*;
import javax.swing.*;
publicclass StartWindowextends javax.swing.JFrame{
class MachineTimerimplements ActionListener{
publicvoid actionPerformed(ActionEvent e){
readString = serialportControl.getResponsePacket();
if((readString.indexOf('r'))!= -1)
{
machine_connect_byte = machine_connect_byte +1;
if(machine_connect_byte ==10){
jLabel2.setBackground(new java.awt.Color(255,51,102));
jLabel2.setText("machine not Connected");
}else{}
}
else{
jLabel2.setBackground(new java.awt.Color(153,153,255));
jLabel2.setText("machine Connected");
machine_connect_byte = 0;
}
// jLabel3.setText(readString);
}
}
class TxTimerimplements ActionListener{
byte make_class_byte ;
publicvoid actionPerformed(ActionEvent e){
serialportControl.sendCommand(check_tx_data1);
serialportControl.sendCommand(check_tx_data2);
serialportControl.sendCommand(stepper_tx_byte);
serialportControl.sendCommand(break_tx_byte);
serialportControl.sendCommand(ttmotor_tx_byte);
serialportControl.sendCommand(nozzelmotor_tx_byte);
serialportControl.sendCommand(shakermotor_tx_byte);
serialportControl.sendCommand(check_tx_data3);
serialportControl.sendCommand(check_tx_data4);
}
}
public StartWindow(){
initComponents();
//init of other classes================================================
serialportControl =new SerialPortControl();
Timer transmit_timer =new Timer(200,new TxTimer());
transmit_timer.setInitialDelay(100);
transmit_timer.start();
Timermachine_connected_timer =new Timer(100,new MachineTimer());
machine_connected_timer.setInitialDelay(500);
machine_connected_timer.start();
Dimension screenSize1 = Toolkit.getDefaultToolkit().getScreenSize();
frame2 =new DispenseMain2();
frame2.setResizable(true);
frame2.setSize(new Dimension(screenSize1));
frame2.setVisible(false);
frame1 =new MaintenanceMain();
frame1.setResizable(true);
frame1.setSize(new Dimension(screenSize1));
frame1.setVisible(false);
//===========================end of init===============================
}
public String getReadString()
{
return(readString);
}
privatevoid jButton2MouseClicked(java.awt.event.MouseEvent evt){
//this.setVisible(false);
frame1.setVisible(true);
// TODO add your handling code here:
}
privatevoid jButton1MouseClicked(java.awt.event.MouseEvent evt){
// this.setVisible(false);
frame2.setVisible(true);
}
privatevoid jMenuItem7MousePressed(java.awt.event.MouseEvent evt){
System.exit(0);
}
privatevoid jMenuItem7MouseClicked(java.awt.event.MouseEvent evt){
}
privatevoid jButton3MouseClicked(java.awt.event.MouseEvent evt){
System.exit(0);
}
/**
* @param args the command line arguments
*/
publicstaticvoid main(String args[]){
java.awt.EventQueue.invokeLater(new Runnable(){
publicvoid run(){
StartWindow frame0 =new StartWindow();
frame0.setResizable(true);
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
frame0.setSize(new Dimension(screenSize));
frame0.setVisible(true);
}
});
}
public SerialPortControl serialportControl;
public MaintenanceMain frame1;
public DispenseMain2frame2;
publicbyte check_tx_data1 ='a';
publicbyte check_tx_data2 ='b' ;
publicbyte stepper_tx_byte ='n';
publicbyte break_tx_byte ='n';
publicbyte ttmotor_tx_byte='n';
publicbyte nozzelmotor_tx_byte ='n';
publicbyte shakermotor_tx_byte ='n';
publicbyte check_tx_data3 ='c';
publicbyte check_tx_data4 ='d';
public String readString;
publicint machine_connect_byte;
public StartWindow myStartFrame;
}
thakns i advance
arnab/vu2bpw
Message was edited by:
arnab.bhaumik

