I'm new java GUI developer and I have
a question.
Is possible to create a Jframe with
multiples Jpanels? My idea is create a class with the components added in the JPanel and
from another class create the JFrame adding multiples objects of the JPanel
Class.
At the moment I'm doing
test:
public class Principal
{
private JFrame window;
public
Principal(){
window = new JFrame("Principal");
}
/**
* @return the finestra
*/
public JFrame getFinestra() {
return window;
}
}`
Child
Class
public class
Childs {
private JPanel panel;
private JLabel
text1;
public Childs(){
panel = new
JPanel();
text1 = new JLabel();
text1.setText("TEXT");
panel.add(text1);
}
/**
* @return the panel
*/
public JPanel getPanel()
{
return panel;
}
}
TestFrame
Class
public class
TestFrame {
/**
* @param args the command line
arguments
*/
public static void main(String[] args)
{
Principal p = new Principal();
Childs c = new
Childs();
Childs c2 = new Childs();
p.getFinestra().add(c.getPanel());
p.getFinestra().add(c2.getPanel());
p.getFinestra().setVisible(true);
}
}
`
No comments:
Post a Comment