Results 1 to 5 of 5
  1. #1

    Default Mga master sa Java asa namo? mag GUI ta


    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...

  2. #2
    pg create lng og separate class that implements ActionListener nya dinhi i labay tanan nmo mga action performed from both panel1 og panel2 at the same time kani nga class naa reference ni DynamicFrame. ky basing sa imng scenario wla kaila ang panel1 og panel2 ni DynamicFrame..

  3. #3
    or another solution is each panel dapat naa reference ni DynamicFrame ex for DynamicPanel1:

    Code:
     //below modified constructor that receive a reference to your frame
       public DynamicPanel1(DynamicFrame dynamicFrame){
           frame = dynamicFrame;
           .
           .
           .
           jb.addActionListener(new ActionListener(){
             public void actionPerformed(ActionEvent e){
             frame.removeAll();
             frame.add(new DynamicPanel2());
             //call other frame methods to update the frame
    
             }
           });
      }
    try kono bro bacin d i mada

  4. #4
    Quote Originally Posted by josephG View Post
    or another solution is each panel dapat naa reference ni DynamicFrame ex for DynamicPanel1:

    Code:
     //below modified constructor that receive a reference to your frame
       public DynamicPanel1(DynamicFrame dynamicFrame){
           frame = dynamicFrame;
           .
           .
           .
           jb.addActionListener(new ActionListener(){
             public void actionPerformed(ActionEvent e){
             frame.removeAll();
             frame.add(new DynamicPanel2());
             //call other frame methods to update the frame
     
             }
           });
      }
    try kono bro bacin d i mada

    mao2x ra pud ang solution na aq ghimo imbis na frame ang ipasa ky panel lng aq....

  5. #5
    salamat master...

  6.    Advertisement

Similar Threads

 
  1. sa mga MASTERS sa mountain bike.. tabang..
    By Quilat in forum Hobbies & Crafts
    Replies: 16
    Last Post: 02-23-2013, 10:12 AM
  2. Replies: 3
    Last Post: 05-22-2012, 07:35 AM
  3. Pangutana sa mga Master sa PC..........
    By goats_eye in forum Computer Hardware
    Replies: 24
    Last Post: 12-19-2010, 11:03 AM
  4. Mga taga USC TC, asa mo mag kan.onan?
    By gino6680 in forum Campus Talk
    Replies: 87
    Last Post: 01-26-2010, 03:52 PM
  5. Mga Mahilig sa Humor asa pabor BRT or LRT?
    By JamSKAeneth in forum Humor
    Replies: 3
    Last Post: 01-04-2010, 04:45 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
about us
We are the first Cebu Online Media.

iSTORYA.NET is Cebu's Biggest, Southern Philippines' Most Active, and the Philippines' Strongest Online Community!
follow us
#top