java - Exception in thread "main" adding window to container -
i writing app select random numbers click on jbutton. when run app exception:
exception in thread "main" java.lang.illegalargumentexception: adding window container @ java.awt.container.checknotawindow(container.java:483) @ java.awt.container.addimpl(container.java:1084) @ java.awt.container.add(container.java:410) @ final.main(final.java:37)
here code:
import java.util.arraylist; import java.awt.*; import javax.swing.*; import java.awt.event.actionevent; import java.awt.event.actionlistener; public class final extends jpanel { public static void main(string[] args) { // random numbers have selected arraylist numbers = new arraylist(); numbers.add(40); numbers.add(500); numbers.add(90); numbers.add(10); numbers.add(50); numbers.add(25); // panel gui jpanel panel = new jpanel(); // , of course frame , characteristics jframe frame = new jframe(); frame.setdefaultcloseoperation(jframe.exit_on_close); frame.settitle("random numbers!"); frame.setvisible(true); frame.setsize(300,150); // button selecting random number arraylist jbutton button = new jbutton(); button.settext("click me!"); // add objects panel frame.add(button); panel.add(frame); } }
instead of:
// add objects panel frame.add(button); panel.add(frame);
try like:
// add objects panel frame.add(button, borderlayout.page_start); // top of frame frame.add(panel); // defaults center