whats wrong with these code?
the buttons don't add or remove the panel..
someone help me!??plss..:S

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;

public class addremove extends JPanel implements ActionListener{
    private JButton addbut;
    private JButton revbut;
    private JPanel panel1;
    private JPanel panel2;

    public addremove() {

        addbut = new JButton ("Add");
        revbut = new JButton ("Remove");
        panel1 = new JPanel();
		panel2 = new JPanel();

		panel1.setBackground(Color.blue);
		panel2.setBackground(Color.red);

        setPreferredSize (new Dimension (218, 160));
        setLayout (null);


        add (addbut);
        add (revbut);
        add (panel2);


        addbut.setBounds (20, 120, 80, 25);
        revbut.setBounds (120, 120, 80, 25);
        panel1.setBounds (20,10,180,60);
        panel2.setBounds (20,10,180,60);
    }

    public void actionPerformed(ActionEvent e)
    {
		if(e.getSource() == addbut)
		{
			remove(panel2);

			add(panel1);

		}
		else if (e.getSource() == revbut)
		{
			remove(panel1);

			add(panel2);

		}
	}





    public static void main (String[] args) {
        JFrame frame = new JFrame ("addremove");
        frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
        frame.getContentPane().add (new addremove());
        frame.pack();
        frame.setVisible (true);
        frame.setLocation(450,280);
        frame.setResizable(false);
    }
}

,.,i've already found the solution..
sorry about this stupid question..hehe

Member Avatar for HerrLehmann

Hey!
greate you solved the problem. Could you tell us how? As I'm a starter in Java I need working code examples to solve problems not broken code.
hopeing you do still remember
Thank you!
Carl

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.