Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

adding and remoing components  RSS feed

 
Vinothini
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

while selecting values in the combobox.
some components has to be removed and has
to add some other components(comboboxes) in that exact place.
but, removing components is fine.
but, while adding the same it's adding components to the gui is not working.
because it's adding some where else.
i am using BoxLayout for it.
my combobox have some values "com1","com2"
when selecting "com1" it has to display "com1" related values
and selecting "com2" it has to diaplay "com2" related values to the components
in the gui.
But, u have may think why can't they use some components.
here i can't use it.b'cas same component reference i am passing for
two values "com1" and "com2".
Suppose i am changing "com1" related component values.
it has to change "com1" values.
but, mine when i press "ok" button it automatically
replace common values for "com1" and "com2".
hope now u will understand it.
It's very urgent
code
----
package incontrol.icgui.iogroup;
import org.opennms.protocols.snmp.*;
import incontrol.icdb.*;
import incontrol.icgui.wince.*;
import incontrol.icgui.*;
import incontrol.*;
import incontrol.icbean.icutilbean.*;//DataTableModel.*;
import incontrol.icbean.icguibean.*;
import incontrol.icdomain.*;
import incontrol.icdomain.snmp.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.border.*;
import java.lang.*;
import java.io.*;
import java.util.*;
/*
Lakshmi has to do ports.
*/
public class Vxl_Ic_PrinterPropCls extends Vxl_Ic_PropertyPanelCls implements ListSelectionListener,ActionListener,MouseListener{

JPanel ppCls_pnlmain,ppCls_pnltable,ppCls_pnlbutton;
JTable ppCls_tblprinter=null;
JScrollPaneppCls_slptable;
JButton ppCls_btnport,ppCls_btnadd,ppCls_btndelete;
Object[] tableTitles = {"Port","Name","Type","Default"};
Object[][] TableData ={{"LPT1:","","",""},{"COM1:","","",""},{"COM2:","","",""}};};
// for ports

JPanel portCls_pnlport,portCls_pnlrate1,portCls_pnldata1,portCls_pnlstop1,portCls_pnlparity1,portCls_pnlflow1,portCls_pnlfirst,portCls_pnlbefore,portCls_pnlafter,portCls_pnlwin,portCls_pn lmanual,portCls_pnlcancel,portCls_pnlwait,portCls_pnlcon,portCls_pnlcon1,portCls_pnlcon2,portCls_pnlsecond,portCls_pnlextra,portCls_pnlfinal,portCls_pnldown;
JPanel portCls_pnlrate2,portCls_pnldata2,portCls_pnlstop2,portCls_pnlparity2,portCls_pnlflow2;
JLabel portCls_lblport,portCls_lblrate1,portCls_lbldata1,portCls_lblstop1,portCls_lblparity1,portCls_lblflow1,portCls_lblcancel,portCls_lblwait,portCls_lblsec1,portCls_lblsec2,portCls_lbl extra;
JLabel portCls_lblrate2,portCls_lbldata2,portCls_lblstop2,portCls_lblparity2,portCls_lblflow2;
Object port[]={"Com1","Com2"};
Object rate[]={"110","300","600","1200","2400","4800","9600","14400","19200","38400","57600","115200"};
Object databits[]={"4","5","6","7","8"};
Object stop[]={"1","1.5","2"};
Object parity[]={"None","Odd","Even","Mark","Space"};
Object flow[]={"None","Hardware","Software"};
private JPanel portCls_pnlportcom1 = new JPanel();
private JPanel portCls_pnlportcom2 = new JPanel();
private JPanel portCls_pnlbut = new JPanel();
private JPanel portCls_pnlmain = new JPanel();
private JComboBox portCls_cbxport = new JComboBox(port);
private JComboBox portCls_cbxrate1 = new JComboBox(rate);
private JComboBox portCls_cbxdata1 = new JComboBox(databits);
private JComboBox portCls_cbxstop1 = new JComboBox(stop);
private JComboBox portCls_cbxparity1 = new JComboBox(parity);
private JComboBox portCls_cbxflow1 = new JComboBox(flow);
private JComboBox portCls_cbxrate2 = new JComboBox(rate);
private JComboBox portCls_cbxdata2 = new JComboBox(databits);
private JComboBox portCls_cbxstop2 = new JComboBox(stop);
private JComboBox portCls_cbxparity2 = new JComboBox(parity);
private JComboBox portCls_cbxflow2 = new JComboBox(flow);
JButton portCls_btnok,portCls_btncancel;
private JDialog portSettings = new JDialog();

String port1,port2,rate1,rate2,data1,data2,stop1,stop2,parity1,parity2,flow1,flow2;
Vxl_Ic_ClientCls portclient = null;


/*-------------------------CONSTRUCTORS-----------------------*/
public Vxl_Ic_PrinterPropCls(Vxl_Ic_ClientCls client) throws Exception {
super(client);
portCls_cbxport.addActionListener(this);
callingPort();
createDialog();
mapComponentsToDomain(this.client,this.propertyPanelCls_mapTable);
}

private void createDialog(){
//portSettings=new JDialog();
portSettings.getContentPane().add(portCls_pnlmain);
portSettings.setSize(275, 320);
portSettings.setLocation(150, 100);
portSettings.setTitle("Printer Port Settings");
//portSettings.show();
}

public void actionPerformed(ActionEvent ae){

//Lakshmi Starts
else if(ae.getSource().equals(portCls_btnok)){
portCls_pnlmain.removeAll();
portSettings.dispose();
}else if(ae.getSource().equals(portCls_btncancel)){
portCls_pnlmain.removeAll();
portSettings.dispose();
}else if(ae.getSource().equals(portCls_cbxport)){
portSelection();
}else if(ae.getSource().equals(ppCls_btnport)){
//portCls_pnlportcom1=new JPanel();
//remove(portCls_pnlmain); //.removeAll();
/* callingPort();
*/
portSettings.show();
}
//Lakshmi ends

}

/*********************************/
//here actually i am removing and adding components.
//Lakshmi Starts
public void portSelection() {
if(portCls_cbxport.getSelectedItem().equals("Com1")) {
if(portCls_pnlportcom2.getComponentCount() > 0 ) {
portCls_pnlportcom2.removeAll();
msg("removing com1 components...");
portCls_pnlbut.removeAll();
createcom1Panel();
createFinalPanel();
portCls_pnlmain.validate();
portCls_pnlmain.repaint();
}
portCls_cbxrate1.setSelectedItem(rate1);
portCls_cbxdata1.setSelectedItem(data1);
portCls_cbxstop1.setSelectedItem(stop1);
portCls_cbxparity1.setSelectedItem(parity1);
portCls_cbxflow1.setSelectedItem(flow1);
}else if(portCls_cbxport.getSelectedItem().equals("Com2")) {
msg("removing com2 components...");
if(portCls_pnlportcom1.getComponentCount() > 0 ) {
portCls_pnlportcom1.removeAll();
portCls_pnlbut.removeAll();
createFinalPanel();
portCls_pnlmain.validate();
portCls_pnlmain.repaint();
}
portCls_cbxrate2.setSelectedItem(rate2);
portCls_cbxdata2.setSelectedItem(data2);
portCls_cbxstop2.setSelectedItem(stop2);
portCls_cbxparity2.setSelectedItem(parity2);
portCls_cbxflow2.setSelectedItem(flow2);
}
} //end of portSelection
/*********************************/
protected void saveComponentSettings(Vxl_Ic_MibVariable mibVar,Object component) throws Exception{
if(component instanceof JComboBox){
if(mibVar.isMasterAvailable()){
mibVar.setVarValue((String)(((JComboBox)component).getSelectedItem()) );
if(mibVar.isMapAvailable()){
mibVar.setMapValue( mibVar.locateMapValue(mibVar.getMasterValue()) );
}
}else{
mibVar.setMapValue((String)(((JComboBox)component).getSelectedItem()) );
}
}else if(component instanceof JCheckBox){
if(((JCheckBox)printerSelectionCls_chxdefault).isSelected()){
mibVar.setMapValue("LPT1:");
}else if(((JCheckBox)printerSelectionCls_chxdefaultcom1).isSelected()){
mibVar.setMapValue("COM1:");
}else if(((JCheckBox)printerSelectionCls_chxdefaultcom2).isSelected()){
mibVar.setMapValue("COM2:");
}
mibVar.setVarValue( mibVar.locateMasterValue(mibVar.getMapValue()) );
}else if(component instanceof JTextField){
mibVar.setVarValue( ((JTextField)component).getText() );
}else if(component instanceof JTextArea){
mibVar.setVarValue( ((JTextArea)component).getText() );
}//end of if-else-if
//saving data:
msg("Save: varID:"+mibVar.getVarID()+" "+"master: "+mibVar.getMasterValue()+" "+"map: "+mibVar.getMapValue());

}//end of saveComponentSettings

public void mapComponentsToDomain(Vxl_Ic_ClientCls client,DataTableModel dtm) throws Exception{
propertyName = "ports";
presentVarID = "com1speedports";
variable = client.getMibVariable(propertyName,presentVarID);
if(variable == null)
throw new Exception("MibVariable not found for "+presentVarID);
rate1 = (String)variable.getMapValue();
presentComponent = portCls_cbxrate1;
rowData = new Object[]{presentVarID,propertyName,presentComponent,variable} ;
dtm.addRow(rowData);

presentVarID = "com1parityports";
variable = client.getMibVariable(propertyName,presentVarID);
if(variable == null)
throw new Exception("MibVariable not found for "+presentVarID);
parity1 = (String)variable.getMapValue();
presentComponent = portCls_cbxparity1;
rowData = new Object[]{presentVarID,propertyName,presentComponent,variable} ;
dtm.addRow(rowData);

presentVarID = "com1stopbitsports";
variable = client.getMibVariable(propertyName,presentVarID);
if(variable == null)
throw new Exception("MibVariable not found for "+presentVarID);
stop1 = (String)variable.getMapValue();
presentComponent = portCls_cbxstop1;
rowData = new Object[]{presentVarID,propertyName,presentComponent,variable} ;
dtm.addRow(rowData);

presentVarID = "com1wordwidthports";
variable = client.getMibVariable(propertyName,presentVarID);
if(variable == null)
throw new Exception("MibVariable not found for "+presentVarID);
data1 = (String)variable.getMapValue();
presentComponent = portCls_cbxdata1;
rowData = new Object[]{presentVarID,propertyName,presentComponent,variable} ;
dtm.addRow(rowData);

presentVarID = "com1flowcontrolports";
variable = client.getMibVariable(propertyName,presentVarID);
if(variable == null)
throw new Exception("MibVariable not found for "+presentVarID);
flow1 = (String)variable.getMapValue();
presentComponent = portCls_cbxflow1;
rowData = new Object[]{presentVarID,propertyName,presentComponent,variable} ;
dtm.addRow(rowData);

//-----------------------------com2--------------------------------------------
presentVarID = "com2speedports";
variable = client.getMibVariable(propertyName,presentVarID);
if(variable == null)
throw new Exception("MibVariable not found for "+presentVarID);
rate2 = (String)variable.getMapValue();
presentComponent = portCls_cbxrate2;
rowData = new Object[]{presentVarID,propertyName,presentComponent,variable} ;
dtm.addRow(rowData);

presentVarID = "com2parityports";
variable = client.getMibVariable(propertyName,presentVarID);
if(variable == null)
throw new Exception("MibVariable not found for "+presentVarID);
parity2 = (String)variable.getMapValue();
presentComponent = portCls_cbxparity2;
rowData = new Object[]{presentVarID,propertyName,presentComponent,variable} ;
dtm.addRow(rowData);

presentVarID = "com2stopbitsports";
variable = client.getMibVariable(propertyName,presentVarID);
if(variable == null)
throw new Exception("MibVariable not found for "+presentVarID);
stop2 = (String)variable.getMapValue();
presentComponent = portCls_cbxstop2;
rowData = new Object[]{presentVarID,propertyName,presentComponent,variable} ;
dtm.addRow(rowData);

presentVarID = "com2wordwidthports";
variable = client.getMibVariable(propertyName,presentVarID);
if(variable == null)
throw new Exception("MibVariable not found for "+presentVarID);
data2 = (String)variable.getMapValue();
presentComponent = portCls_cbxdata2;
rowData = new Object[]{presentVarID,propertyName,presentComponent,variable} ;
dtm.addRow(rowData);

presentVarID = "com2flowcontrolports";
variable = client.getMibVariable(propertyName,presentVarID);
if(variable == null)
throw new Exception("MibVariable not found for "+presentVarID);
flow2 = (String)variable.getMapValue();
presentComponent = portCls_cbxflow2;
rowData = new Object[]{presentVarID,propertyName,presentComponent,variable} ;
dtm.addRow(rowData);
//msg("noRows found: "+dtm.getNumberOfRows());
//Lakshmi ends

}//end of mapComponentsToDomain

private void msg(String message){
if(SysVar.isDebugMode()){
System.out.println("Vxl_Ic_PrinterPropCls: "+message);
}
}//end of msg

private void createMainPanel(){
ppCls_pnlmain=new JPanel();
ppCls_pnlmain.setLayout(new BoxLayout(ppCls_pnlmain, BoxLayout.Y_AXIS));
//ppCls_pnlmain.setAlignmentX(CENTER_ALIGNMENT);
//Cls_pnlmain.add(Box.createRigidArea(Vxl_Ic_SetupCls.getSizeOfFiller()));
ppCls_pnlmain.add(Box.createRigidArea(Vxl_Ic_SetupCls.getSizeOfFiller()));
ppCls_pnltable = new JPanel();
ppCls_pnltable.setLayout(new BoxLayout(ppCls_pnltable, BoxLayout.X_AXIS));

ppCls_tblprinter = new JTable(TableData,tableTitles);
ppCls_tblprinter.setBackground(Color.white);
ppCls_tblprinter.getTableHeader().setReorderingAllowed(false);
ppCls_tblprinter.getTableHeader().setResizingAllowed(false);
/*ppCls_tblModel=new Vxl_Ic_ClpTableModel(tableTitles,0);
ppCls_tblprinter.setModel(ppCls_tblModel);*/
//ppCls_tblprinter.setAlignmentX(CENTER_ALIGNMENT);
//ppCls_tblprinter.getSelectionModel().addListSelectionListener(this);
ppCls_slptable=new JScrollPane(ppCls_tblprinter);
Vxl_Ic_SetupCls.setComponentSize(ppCls_slptable, Vxl_Ic_SetupCls.getSizeOfTable());
ppCls_slptable.setBackground(Color.white);
ppCls_pnltable.add(ppCls_slptable);

ppCls_pnlmain.add(ppCls_pnltable);

ppCls_pnlmain.add(Box.createRigidArea(Vxl_Ic_SetupCls.getSizeOfFiller()));

ppCls_pnlbutton=new JPanel();
ppCls_pnlbutton.setLayout(new BoxLayout(ppCls_pnlbutton, BoxLayout.X_AXIS));
//Vxl_Ic_SetupCls.setComponentSize(mtsCls_pnltitle, Vxl_Ic_SetupCls.getSizeOfList());
//mtsCls_pnltitle.setAlignmentX(CENTER_ALIGNMENT);

//ppCls_pnlmain.add(Box.createRigidArea(Vxl_Ic_SetupCls.getSizeOfFiller()));


ppCls_btnport= new JButton("Port/Properties");
Vxl_Ic_SetupCls.setComponentSize(ppCls_btnport, Vxl_Ic_SetupCls.getSizeOfRadioBtn());
ppCls_btnport.setAlignmentX(CENTER_ALIGNMENT);
ppCls_pnlbutton.add(ppCls_btnport);

ppCls_pnlbutton.add(Box.createRigidArea(Vxl_Ic_SetupCls.getSizeOfFiller()));
ppCls_pnlbutton.add(Box.createRigidArea(Vxl_Ic_SetupCls.getSizeOfFiller()));

ppCls_btnadd= new JButton("Add/Properties");
Vxl_Ic_SetupCls.setComponentSize(ppCls_btnadd, Vxl_Ic_SetupCls.getSizeOfRadioBtn());
ppCls_btnadd.setAlignmentX(CENTER_ALIGNMENT);
ppCls_pnlbutton.add(ppCls_btnadd);

ppCls_pnlbutton.add(Box.createRigidArea(Vxl_Ic_SetupCls.getSizeOfFiller()));
ppCls_pnlbutton.add(Box.createRigidArea(Vxl_Ic_SetupCls.getSizeOfFiller()));

ppCls_btndelete= new JButton("Delete");
Vxl_Ic_SetupCls.setComponentSize(ppCls_btndelete, Vxl_Ic_SetupCls.getSizeOfSmallText());
ppCls_btndelete.setAlignmentX(CENTER_ALIGNMENT);
ppCls_pnlbutton.add(ppCls_btndelete);

ppCls_pnlmain.add(ppCls_pnlbutton);

//Cls_pnlmain.add(Box.createRigidArea(Vxl_Ic_SetupCls.getSizeOfFiller()));
ppCls_pnlmain.add(Box.createRigidArea(Vxl_Ic_SetupCls.getSizeOfFiller()));
setLayout(new BoxLayout(this,BoxLayout.Y_AXIS));
add(Box.createVerticalGlue());
add(ppCls_pnlmain);
add(Box.createVerticalGlue());


}


/*-------------------------CONSTRUCTORS-----------------------*/
public void callingPort() {
createFirstPanel();
createcom2Panel();
createFinalPanel();
}

private void createFirstPanel(){
portCls_pnlmain=new JPanel();
portCls_pnlmain.setLayout(new BoxLayout(portCls_pnlmain, BoxLayout.Y_AXIS));

portCls_pnlfirst=new JPanel();
portCls_pnlfirst.setLayout(new BoxLayout(portCls_pnlfirst, BoxLayout.Y_AXIS));

portCls_pnlport=new JPanel();
portCls_pnlport.setLayout(new BoxLayout(portCls_pnlport, BoxLayout.X_AXIS));
portCls_pnlport.add(Box.createRigidArea(Vxl_Ic_SetupCls.getSizeOfFiller()));

portCls_lblport=new JLabel("Port");
Vxl_Ic_SetupCls.setComponentSize(portCls_lblport, Vxl_Ic_SetupCls.getSizeOfSmallText());
portCls_pnlport.add(portCls_lblport);

Vxl_Ic_SetupCls.setComponentSize(portCls_cbxport, Vxl_Ic_SetupCls.getSizeOfButton());
portCls_pnlport.add(portCls_cbxport);
portCls_pnlport.add(Box.createRigidArea(Vxl_Ic_SetupCls.getSizeOfFiller()));
portCls_pnlfirst.add(portCls_pnlport);

portCls_pnlmain.add(Box.createRigidArea(Vxl_Ic_SetupCls.getSizeOfFiller()));
portCls_pnlmain.add(portCls_pnlfirst);
portCls_cbxport.setSelectedItem("Com2");
} //end of createFirstPanel

private void createcom1Panel() {
//Laksmi Starts
portCls_pnlportcom1=new JPanel();
portCls_pnlportcom1.setLayout(new BoxLayout(portCls_pnlportcom1, BoxLayout.Y_AXIS));
portCls_pnlportcom1.add(Box.createRigidArea(Vxl_Ic_SetupCls.getSizeOfFiller()));
//Lakshmi ends

portCls_pnlrate1=new JPanel();
portCls_pnlrate1.setLayout(new BoxLayout(portCls_pnlrate1, BoxLayout.X_AXIS));
portCls_pnlrate1.add(Box.createRigidArea(Vxl_Ic_SetupCls.getSizeOfFiller()));

portCls_lblrate1=new JLabel("Baud Rate");
Vxl_Ic_SetupCls.setComponentSize(portCls_lblrate1, Vxl_Ic_SetupCls.getSizeOfSmallText());
portCls_pnlrate1.add(portCls_lblrate1);


Vxl_Ic_SetupCls.setComponentSize(portCls_cbxrate1, Vxl_Ic_SetupCls.getSizeOfButton());
portCls_pnlrate1.add(portCls_cbxrate1);

portCls_pnlrate1.add(Box.createRigidArea(Vxl_Ic_SetupCls.getSizeOfFiller()));
Vxl_Ic_SetupCls.setContainerFont(portCls_pnlrate1);
portCls_pnlportcom1.add(portCls_pnlrate1);
portCls_pnlportcom1.add(Box.createRigidArea(Vxl_Ic_SetupCls.getSizeOfFiller()));

portCls_pnldata1=new JPanel();
portCls_pnldata1.setLayout(new BoxLayout(portCls_pnldata1, BoxLayout.X_AXIS));
portCls_pnldata1.add(Box.createRigidArea(Vxl_Ic_SetupCls.getSizeOfFiller()));

portCls_lbldata1=new JLabel("Data Bits");
Vxl_Ic_SetupCls.setComponentSize(portCls_lbldata1, Vxl_Ic_SetupCls.getSizeOfSmallText());
portCls_pnldata1.add(portCls_lbldata1);

Vxl_Ic_SetupCls.setComponentSize(portCls_cbxdata1, Vxl_Ic_SetupCls.getSizeOfButton());
portCls_pnldata1.add(portCls_cbxdata1);

portCls_pnldata1.add(Box.createRigidArea(Vxl_Ic_SetupCls.getSizeOfFiller()));
Vxl_Ic_SetupCls.setContainerFont(portCls_pnldata1);

portCls_pnlportcom1.add(portCls_pnldata1);
portCls_pnlportcom1.add(Box.createRigidArea(Vxl_Ic_SetupCls.getSizeOfFiller()));
portCls_pnlstop1=new JPanel();
portCls_pnlstop1.setLayout(new BoxLayout(portCls_pnlstop1, BoxLayout.X_AXIS));
portCls_pnlstop1.add(Box.createRigidArea(Vxl_Ic_SetupCls.getSizeOfFiller()));

portCls_lblstop1=new JLabel("Stop Bits");
Vxl_Ic_SetupCls.setComponentSize(portCls_lblstop1, Vxl_Ic_SetupCls.getSizeOfSmallText());
portCls_pnlstop1.add(portCls_lblstop1);

Vxl_Ic_SetupCls.setComponentSize(portCls_cbxstop1, Vxl_Ic_SetupCls.getSizeOfButton());
portCls_pnlstop1.add(portCls_cbxstop1);

portCls_pnlstop1.add(Box.createRigidArea(Vxl_Ic_SetupCls.getSizeOfFiller()));
Vxl_Ic_SetupCls.setContainerFont(portCls_pnlstop1);
portCls_pnlportcom1.add(portCls_pnlstop1);
portCls_pnlportcom1.add(Box.createRigidArea(Vxl_Ic_SetupCls.getSizeOfFiller()));

portCls_pnlparity1=new JPanel();
portCls_pnlparity1.setLayout(new BoxLayout(portCls_pnlparity1, BoxLayout.X_AXIS));
portCls_pnlparity1.add(Box.createRigidArea(Vxl_Ic_SetupCls.getSizeOfFiller()));

portCls_lblparity1=new JLabel("Parity ");
Vxl_Ic_SetupCls.setComponentSize(portCls_lblparity1, Vxl_Ic_SetupCls.getSizeOfSmallText());
portCls_pnlparity1.add(portCls_lblparity1);

Vxl_Ic_SetupCls.setComponentSize(portCls_cbxparity1, Vxl_Ic_SetupCls.getSizeOfButton());
portCls_pnlparity1.add(portCls_cbxparity1);

portCls_pnlparity1.add(Box.createRigidArea(Vxl_Ic_SetupCls.getSizeOfFiller()));
Vxl_Ic_SetupCls.setContainerFont(portCls_pnlparity1);

portCls_pnlportcom1.add(portCls_pnlparity1);
portCls_pnlportcom1.add(Box.createRigidArea(Vxl_Ic_SetupCls.getSizeOfFiller()));

portCls_pnlflow1=new JPanel();
portCls_pnlflow1.setLayout(new BoxLayout(portCls_pnlflow1, BoxLayout.X_AXIS));
portCls_pnlflow1.add(Box.createRigidArea(Vxl_Ic_SetupCls.getSizeOfFiller()));

portCls_lblflow1=new JLabel("Flow Control");
Vxl_Ic_SetupCls.setComponentSize(portCls_lblflow1, Vxl_Ic_SetupCls.getSizeOfSmallText());
portCls_pnlflow1.add(portCls_lblflow1);

Vxl_Ic_SetupCls.setComponentSize(portCls_cbxflow1, Vxl_Ic_SetupCls.getSizeOfButton());
portCls_pnlflow1.add(portCls_cbxflow1);

portCls_pnlflow1.add(Box.createRigidArea(Vxl_Ic_SetupCls.getSizeOfFiller()));
Vxl_Ic_SetupCls.setContainerFont(portCls_pnlflow1);
portCls_pnlportcom1.add(portCls_pnlflow1);
portCls_pnlportcom1.add(Box.createRigidArea(Vxl_Ic_SetupCls.getSizeOfFiller()));

portCls_pnlmain.add(portCls_pnlportcom1);

} //end of createcom1Panel

private void createcom2Panel() {
portCls_pnlportcom2=new JPanel();
portCls_pnlportcom2.setLayout(new BoxLayout(portCls_pnlportcom2, BoxLayout.Y_AXIS));
portCls_pnlportcom2.add(Box.createRigidArea(Vxl_Ic_SetupCls.getSizeOfFiller()));

portCls_pnlrate2=new JPanel();
portCls_pnlrate2.setLayout(new BoxLayout(portCls_pnlrate2, BoxLayout.X_AXIS));
portCls_pnlrate2.add(Box.createRigidArea(Vxl_Ic_SetupCls.getSizeOfFiller()));

portCls_lblrate2=new JLabel("Baud Rate");
Vxl_Ic_SetupCls.setComponentSize(portCls_lblrate2, Vxl_Ic_SetupCls.getSizeOfSmallText());
portCls_pnlrate2.add(portCls_lblrate2);

Vxl_Ic_SetupCls.setComponentSize(portCls_cbxrate2, Vxl_Ic_SetupCls.getSizeOfButton());
portCls_pnlrate2.add(portCls_cbxrate2);

portCls_pnlrate2.add(Box.createRigidArea(Vxl_Ic_SetupCls.getSizeOfFiller()));
Vxl_Ic_SetupCls.setContainerFont(portCls_pnlrate2);
portCls_pnlportcom2.add(portCls_pnlrate2);
portCls_pnlportcom2.add(Box.createRigidArea(Vxl_Ic_SetupCls.getSizeOfFiller()));

portCls_pnldata2=new JPanel();
portCls_pnldata2.setLayout(new BoxLayout(portCls_pnldata2, BoxLayout.X_AXIS));
portCls_pnldata2.add(Box.createRigidArea(Vxl_Ic_SetupCls.getSizeOfFiller()));

portCls_lbldata2=new JLabel("Data Bits");
Vxl_Ic_SetupCls.setComponentSize(portCls_lbldata2, Vxl_Ic_SetupCls.getSizeOfSmallText());
portCls_pnldata2.add(portCls_lbldata2);

Vxl_Ic_SetupCls.setComponentSize(portCls_cbxdata2, Vxl_Ic_SetupCls.getSizeOfButton());
portCls_pnldata2.add(portCls_cbxdata2);

portCls_pnldata2.add(Box.createRigidArea(Vxl_Ic_SetupCls.getSizeOfFiller()));
Vxl_Ic_SetupCls.setContainerFont(portCls_pnldata2);

portCls_pnlportcom2.add(portCls_pnldata2);
portCls_pnlportcom2.add(Box.createRigidArea(Vxl_Ic_SetupCls.getSizeOfFiller()));
portCls_pnlstop2=new JPanel();
portCls_pnlstop2.setLayout(new BoxLayout(portCls_pnlstop2, BoxLayout.X_AXIS));
portCls_pnlstop2.add(Box.createRigidArea(Vxl_Ic_SetupCls.getSizeOfFiller()));

portCls_lblstop2=new JLabel("Stop Bits");
Vxl_Ic_SetupCls.setComponentSize(portCls_lblstop2, Vxl_Ic_SetupCls.getSizeOfSmallText());
portCls_pnlstop2.add(portCls_lblstop2);

Vxl_Ic_SetupCls.setComponentSize(portCls_cbxstop2, Vxl_Ic_SetupCls.getSizeOfButton());
portCls_pnlstop2.add(portCls_cbxstop2);

portCls_pnlstop2.add(Box.createRigidArea(Vxl_Ic_SetupCls.getSizeOfFiller()));
Vxl_Ic_SetupCls.setContainerFont(portCls_pnlstop2);
portCls_pnlportcom2.add(portCls_pnlstop2);
portCls_pnlportcom2.add(Box.createRigidArea(Vxl_Ic_SetupCls.getSizeOfFiller()));

portCls_pnlparity2=new JPanel();
portCls_pnlparity2.setLayout(new BoxLayout(portCls_pnlparity2, BoxLayout.X_AXIS));
portCls_pnlparity2.add(Box.createRigidArea(Vxl_Ic_SetupCls.getSizeOfFiller()));

portCls_lblparity2=new JLabel("Parity ");
Vxl_Ic_SetupCls.setComponentSize(portCls_lblparity2, Vxl_Ic_SetupCls.getSizeOfSmallText());
portCls_pnlparity2.add(portCls_lblparity2);

Vxl_Ic_SetupCls.setComponentSize(portCls_cbxparity2, Vxl_Ic_SetupCls.getSizeOfButton());
portCls_pnlparity2.add(portCls_cbxparity2);

portCls_pnlparity2.add(Box.createRigidArea(Vxl_Ic_SetupCls.getSizeOfFiller()));
Vxl_Ic_SetupCls.setContainerFont(portCls_pnlparity2);

portCls_pnlportcom2.add(portCls_pnlparity2);
portCls_pnlportcom2.add(Box.createRigidArea(Vxl_Ic_SetupCls.getSizeOfFiller()));

portCls_pnlflow2=new JPanel();
portCls_pnlflow2.setLayout(new BoxLayout(portCls_pnlflow2, BoxLayout.X_AXIS));
portCls_pnlflow2.add(Box.createRigidArea(Vxl_Ic_SetupCls.getSizeOfFiller()));

portCls_lblflow2=new JLabel("Flow Control");
Vxl_Ic_SetupCls.setComponentSize(portCls_lblflow2, Vxl_Ic_SetupCls.getSizeOfSmallText());
portCls_pnlflow2.add(portCls_lblflow2);

Vxl_Ic_SetupCls.setComponentSize(portCls_cbxflow2, Vxl_Ic_SetupCls.getSizeOfButton());
portCls_pnlflow2.add(portCls_cbxflow2);

portCls_pnlflow2.add(Box.createRigidArea(Vxl_Ic_SetupCls.getSizeOfFiller()));
Vxl_Ic_SetupCls.setContainerFont(portCls_pnlflow2);
portCls_pnlportcom2.add(portCls_pnlflow2);
portCls_pnlportcom2.add(Box.createRigidArea(Vxl_Ic_SetupCls.getSizeOfFiller()));
portCls_pnlmain.add(portCls_pnlportcom2);
} //end of createcom2Panel

private void createFinalPanel(){
portCls_pnlbut=new JPanel();
portCls_pnlbut.setLayout(new BoxLayout(portCls_pnlbut, BoxLayout.X_AXIS));

portCls_btnok=new JButton("OK");
Vxl_Ic_SetupCls.setComponentSize(portCls_btnok, Vxl_Ic_SetupCls.getSizeOfSmallText());
portCls_btnok.setAlignmentX(CENTER_ALIGNMENT);
portCls_pnlbut.add(portCls_btnok);
portCls_pnlbut.add(Box.createRigidArea(Vxl_Ic_SetupCls.getSizeOfFiller()));
portCls_btnok.addActionListener(this);
portCls_btncancel=new JButton("Cancel");
Vxl_Ic_SetupCls.setComponentSize(portCls_btncancel, Vxl_Ic_SetupCls.getSizeOfSmallText());
portCls_btncancel.setAlignmentX(CENTER_ALIGNMENT);
portCls_pnlbut.add(portCls_btncancel);
//portCls_pnlbut.add(Box.createRigidArea(Vxl_Ic_SetupCls.getSizeOfFiller()));
//portCls_pnlbut.add(Box.createRigidArea(Vxl_Ic_SetupCls.getSizeOfSmallText()));
portCls_btncancel.addActionListener(this);
portCls_pnlmain.add(Box.createRigidArea(Vxl_Ic_SetupCls.getSizeOfFiller()));
portCls_pnlmain.add(portCls_pnlbut);
portCls_pnlmain.add(Box.createRigidArea(Vxl_Ic_SetupCls.getSizeOfFiller()));
setLayout(new BoxLayout(this,BoxLayout.Y_AXIS));
add(Box.createVerticalGlue());
add(portCls_pnlmain);
add(Box.createVerticalGlue());

/*portSettings = new JDialog();
portSettings.getContentPane().add(portCls_pnlmain);
portSettings.setSize(275, 320);
portSettings.setLocation(150, 100);
portSettings.setTitle("Printer Port Settings");
portSettings.show();*/
}
public void snmpReceivedPdu(SnmpSession session, int cmd, SnmpPduPacket pdu){
SnmpPduRequest req = null;
setOperationExceptionOccured(true);

req = (SnmpPduRequest)pdu;
if(req.getErrorStatus() != 0)
{
msg("snmpRecievedPdu Error: "+req.getErrorStatus());
synchronized(session){
session.notify();
}
setOperationException(new SnmpVariableRetrievalException(req.getErrorStatus(),"GeneralError exception"));
return;
}
SnmpVarBind vb = pdu.getVarBindAt(0);
if( vb.getValue().typeId() == SnmpEndOfMibView.ASNTYPE){
synchronized(session){
session.notify();
}
setOperationException(new SnmpVariableRetrievalException(SnmpVariableRetrievalException.ErrNoSuchName,new Exception("End of Mib")));
return;
}

respPacket = pdu;
setOperationException(null);
setOperationExceptionOccured(false);
synchronized(session){
session.notify();
}
return;
}//end of method snmpReceivedPdu

public void snmpInternalError(SnmpSession session,int error,SnmpSyntax pdu){
msg("internal error occured....."+error);
synchronized(session)
{
session.notify();
}
setOperationExceptionOccured(true);
setOperationException(new SnmpVariableRetrievalException(error,"unexpected internal error occured"));
}//end of method snmpInternalError

public void snmpTimeoutError(SnmpSession session,SnmpSyntax pdu){
msg("timeout error occured.....");
synchronized(session)
{
session.notify();
}
setOperationExceptionOccured(true);
setOperationException(new SnmpVariableRetrievalException(SnmpVariableRetrievalException.ErrTimeout,"host not reachable or timeout error occured"));
}//end of method snmpTimeoutError

}
 
Manfred Leonhardt
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
If you are removing multiple items think about placing them into a single panel for removal and addition. This should allow for cleaner coding ...
You name doesn't fit the JavaRanch naming policy. Read it
here. Then you can re-register using a valid name.
Thank you,
Manfred.
 
Vinothini
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am using panel for adding and removing components
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!