A
arunsivaprakash
Dear All,
I have a problem in the following code.....I was unit testing the code
from main(). I have the FaMain base class for creating the window with
certain features. So I need all my child windows to inherit FaMain
class. Similarly, I need FaButton as base class instead of JButton.
But even after creating two buttons but1 & but2 only the second button
but2 is getting appeared......Please help me.......
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2006</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/
public class FaButton extends JPanel {
JButton jButton1;
FaMain fa;
static JFrame jf;
public FaButton() {
jf = new FaMain().jfFaMain;
jButton1.setText("Sample");
jButton1.setBounds(new Rectangle(229, 122, 59, 25));
jButton1.setOpaque(true);
jButton1.setVisible(true);
jf.getContentPane().add(jButton1);
}
public FaButton(JFrame jf, String title, char Mnemonic, String
ToolTipText )throws Exception {
this.jf = (jf == null)? new JFrame(Console.title(fa)) : jf;
jButton1 = new JButton();
jButton1.setText(title);
jButton1.setMnemonic(Mnemonic);
jButton1.setToolTipText(ToolTipText);
jButton1.setBounds(new Rectangle(0, 0, 100, 100));
jButton1.setOpaque(true);
jButton1.setEnabled(true);
add(jButton1);
jf.getContentPane().add(this);
}
public FaButton(JFrame jf, int x, int y, int width, int height, String
title, char Mnemonic, String ToolTipText )throws Exception {
this.jf = (jf == null)? new JFrame(Console.title(fa)) : jf;
jButton1 = new JButton();
jButton1.setText(title);
jButton1.setMnemonic(Mnemonic);
jButton1.setToolTipText(ToolTipText);
jButton1.setBounds(new Rectangle(x, y, width, height));
jButton1.setAlignmentX(x);
jButton1.setAlignmentY(y);
jButton1.setOpaque(true);
jButton1.setEnabled(true);
jButton1.setVisible(true);
add(jButton1, null);
jf.getContentPane().add(this);
jButton1.setVisible(true);
jButton1.revalidate();
jButton1.repaint();
}
public static void main(String[] args) {
try {
FaMain faMain = new FaMain();
JFrame jj= faMain.jfFaMain;
FaButton but1 = new FaButton(jj, 500, 500, 100, 100, "My
Button1", 'M', "This is a button");
FaButton but2 = new FaButton(jj, 200, 200, 100, 100, "My
Button2", 'M', "This is a button");
Component[] comp =
jf.getRootPane().getContentPane().getComponents();
System.out.println(jf.getRootPane().getContentPane().getComponentCount());
for (int i = 0; i < comp.length; i++) {
System.out.println(comp.getClass().getName());
}
}
catch (Exception ex) {
}
}
}
I have a problem in the following code.....I was unit testing the code
from main(). I have the FaMain base class for creating the window with
certain features. So I need all my child windows to inherit FaMain
class. Similarly, I need FaButton as base class instead of JButton.
But even after creating two buttons but1 & but2 only the second button
but2 is getting appeared......Please help me.......
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2006</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/
public class FaButton extends JPanel {
JButton jButton1;
FaMain fa;
static JFrame jf;
public FaButton() {
jf = new FaMain().jfFaMain;
jButton1.setText("Sample");
jButton1.setBounds(new Rectangle(229, 122, 59, 25));
jButton1.setOpaque(true);
jButton1.setVisible(true);
jf.getContentPane().add(jButton1);
}
public FaButton(JFrame jf, String title, char Mnemonic, String
ToolTipText )throws Exception {
this.jf = (jf == null)? new JFrame(Console.title(fa)) : jf;
jButton1 = new JButton();
jButton1.setText(title);
jButton1.setMnemonic(Mnemonic);
jButton1.setToolTipText(ToolTipText);
jButton1.setBounds(new Rectangle(0, 0, 100, 100));
jButton1.setOpaque(true);
jButton1.setEnabled(true);
add(jButton1);
jf.getContentPane().add(this);
}
public FaButton(JFrame jf, int x, int y, int width, int height, String
title, char Mnemonic, String ToolTipText )throws Exception {
this.jf = (jf == null)? new JFrame(Console.title(fa)) : jf;
jButton1 = new JButton();
jButton1.setText(title);
jButton1.setMnemonic(Mnemonic);
jButton1.setToolTipText(ToolTipText);
jButton1.setBounds(new Rectangle(x, y, width, height));
jButton1.setAlignmentX(x);
jButton1.setAlignmentY(y);
jButton1.setOpaque(true);
jButton1.setEnabled(true);
jButton1.setVisible(true);
add(jButton1, null);
jf.getContentPane().add(this);
jButton1.setVisible(true);
jButton1.revalidate();
jButton1.repaint();
}
public static void main(String[] args) {
try {
FaMain faMain = new FaMain();
JFrame jj= faMain.jfFaMain;
FaButton but1 = new FaButton(jj, 500, 500, 100, 100, "My
Button1", 'M', "This is a button");
FaButton but2 = new FaButton(jj, 200, 200, 100, 100, "My
Button2", 'M', "This is a button");
Component[] comp =
jf.getRootPane().getContentPane().getComponents();
System.out.println(jf.getRootPane().getContentPane().getComponentCount());
for (int i = 0; i < comp.length; i++) {
System.out.println(comp.getClass().getName());
}
}
catch (Exception ex) {
}
}
}