FrameExample FrmExmp = new FrameExample();private void FourthActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: //FrameExample FrmExmp1 = new FrameExample(); //FrmExmp1.getContentPane().setBackground(Color.red); //FrmExmp.getContentPane().setBackground(Color.red); if (counter == 0) { this.getContentPane().setBackground(Color.blue); counter++; } else { if (counter == 1) { this.getContentPane().setBackground(Color.cyan); counter--; } } ShowText.setForeground(Color.red); ShowText.setText(inputtext.getText()); ShowText.setFont(new Font("",Font.BOLD, 24)); }
FrmExmp.setVisible(true);
FrmExmp.getContentPane().setBackground(Color.cyan) ;
these three lines are form the main.
oky the question is main methods works fine and set the backgound of the frame cyan perfectly. when i try to do this on the button press it does not work with the object created in main() method. if you can not use the object created in main() method outside the main method then i created new object in the function with the name of FrmExmp1. which still doesnt work. it works with only this.getContantPane().
i know this has the properities of previously created object.
this has the properties of previously created obj and works. so that means we are to allowed to create the obj in method or what?