How to make flowlayout available in its caller?
Dear friends:
Good weekends.
I met a problem when I tried to call a Flowlayout Program from another program.
I have a Flowlayout Program called FlowLayoutPane.java, it can display 20 buttons in FlowLayout, run successes, I write another program called FlowLayoutPaneCall.java to call FlowLayoutPane, these 20 icons display also, but not what I want, I need these 20 buttons display in FlowLayoutPaneCall exactly as same as they display in FlowLayoutPane.java, How can I do that?
[1]. FlowLayoutPane.java
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
publicclass FlowLayoutPaneextends JPanel{
public FlowLayoutPane(){
this.setLayout(new FlowLayout(FlowLayout.LEFT, 10, 10));
String spaces ="";
for (int i = 1; i <= 20; i++){
this.add(new JButton("Button #" + i + spaces));
spaces +=" ";
}
}
publicstaticvoid main(String[] args){
JFrame frame =new JFrame();
frame.addWindowListener(new WindowAdapter(){
publicvoid windowClosing(WindowEvent e){
System.exit(0);
}
});
frame.getContentPane().add(new FlowLayoutPane(), BorderLayout.CENTER);
frame.setSize(600, 400);
frame.setVisible(true);
}
}
[2]. FlowLayoutPaneCall.java
import java.awt.*;
import javax.swing.*;
publicclass FlowLayoutPaneCallextends JPanel
{
FlowLayoutPane sftp =new FlowLayoutPane();
public FlowLayoutPaneCall()
{
add(sftp);
}
publicstaticvoid main(String[] args){
FlowLayoutPaneCall dm =new FlowLayoutPaneCall();
JFrame f =new JFrame();
f.setSize(400,400);
f.setLocation(200,200);
f.setVisible(true);
f.getContentPane().add(dm, BorderLayout.CENTER);
f.pack();
f.setVisible(true);
}
}
Thanks so much!!!

