import java.awt.*; import javax.swing.*; public class MyPanel extends JPanel { public MyPanel() { setBackground(Color.RED); } }
import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.*; public class MyPanel extends JPanel implements ActionListener { private JButton whiteBtn; public MyPanel() { whiteBtn = new JButton("Set White"); whiteBtn.addActionListener(this); add(whiteBtn); } public void actionPerformed(ActionEvent e) { setBackground(Color.WHITE); } }In the above examples, we see that the package library used is java.awt.event.