Hello could someone please help me as my program is generating some weird error" java.lang.IllegalArgumentException: adding a window to a container"
Could someone please look at it and tell me what I'm doing wrong. Im trying to add an object of fan to the panel it creates that error. whenever I remove the add(fan, BorderLayout.CENTER); the error goes away. Please someone help me come up with a
solution:(
I have attached my programs
import javax.swing.JPanel;
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class FanControl extends JPanel {
private RunFan fan = new RunFan();
private JButton jbtStart = new JButton("Start");
private JButton jbtStop = new JButton("Stop");
private JButton jbtReverse = new JButton("Reverse");
private JScrollBar jsbDelay = new JScrollBar();
public FanControl() {
// Group buttons in a panel
JPanel panel = new JPanel();
panel.add(jbtStart);
panel.add(jbtStop);
panel.add(jbtReverse);
panel.add(jsbDelay);
jsbDelay.setOrientation(JScrollBar.HORIZONTAL);
setLayout(new BorderLayout());
add(panel,BorderLayout.NORTH);
add(jsbDelay, BorderLayout.SOUTH);
add(fan, BorderLayout.CENTER);
jbtStart.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
fan.start();
}
});
jbtStop.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
fan.stop();
}
});
jbtReverse.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
fan.reverse();
}
});
}