mga master sa java tabangi ko ani beh
gusto nako bah mag ilis2x ang panel sulod sa akung frame taga click nko sa button sa lain panel
mao ni akong codes.. fillupi nlng palihug ang actionlistener.. salamat kaau mabuhay..
lahi lahi ni cla ug class lahi lahi pud ug file.
mao ni akong main frame
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class DynamicFrame extends JFrame{
private JButton jb = new JButton("Remove");
private JPanel jp = new JPanel();
public DynamicFrame(){
jp.add(jb);
add(jp);
setVisible(true);
pack();
jb.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
remove(jp);
add( new DynamicPanel1().getD1());
validateTree();
pack();
}
});
}
public static void main(String a[]){
new DynamicFrame();
}
}
mao ni akong 1st na panel
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class DynamicPanel1 extends JPanel{
private JPanel jp = new JPanel();
private JButton jb = new JButton("Dynamic Panel 2");
private JLabel jl= new JLabel("Dynamic Panel 1");
private JPanel center =new JPanel();
public DynamicPanel1(){
add(jl);
add(jb);
jb.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
removeAll();
// add(new DynamicPanel2()) = dili ni pwd ky mahulog ni xa ang iya i sulod c panel2 ni panel1
//unsa akong i butang
}
});
}
public JPanel getD1(){
return this;
}
}
mao ni akong ikaduha na panel
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class DynamicPanel2 extends JPanel{
private JPanel jp = new JPanel();
private JLabel jl = new JLabel("Dyanamic 2");
private JButton jb = new JButton("Dynamic Panel 1");
public DynamicPanel2(){
add(jl);
add(jb);
jb.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
removeAll();
// add(new DynamicPanel1()) = dili ni pwd ky mahulog ni xa ang iya i sulod c panel1 ni panel2
//what to put?
}
});
}
public JPanel getD2(){
return this;
}
}
gusto nko na inig click nko sa button na naa sulod sa panel1 nga si panel 1 naa sulod ni frame ma wala si panel 1 ug pulihan siya ni panel 2...