need Help with java GUI programming
my problem with this code is that after we compine
:>javac app1.java
and after runing
:>java app1
window pops up and after i press open menu item at the menu bar,
those number of buttons should appear on the frame.
and buttons simply doesnt appear on the frame.
in order to make the buttons appear, you have to resize the frame a lttle bit, then only you can see the active buttons;
this will be a very big issue when frames reSizable(false) occuers, if the frame is not resizable, then simply buttons wont pop up
is this a bug or a mistake by me? can somebody be kind enough to explain ? :)
*/
import java.awt.Frame;
import java.awt.Button;
import java.awt.FlowLayout;
import java.awt.MenuBar;
import java.awt.MenuItem;
import java.awt.Menu;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class app1 extends Frame{
public static void main(String argv[]){
app1 fa=new app1();
//Change from BorderLayout default
fa.setLayout(new FlowLayout());
fa.setSize(400,300);
fa.setVisible(true);
}
app1(){
MenuBar mb = new MenuBar();
Menu m = new Menu("File");
mb.add(m);
MenuItem open = new MenuItem("Open");
open.addActionListener(menuOpen);
m.add(open);
setMenuBar(mb);
}//End of constructor
public void addBtns(){
this.add(new Button("One"));
this.add(new Button("Two"));
this.add(new Button("Three"));
this.add(new Button("Four"));
this.add(new Button("Five"));
this.add(new Button("Six"));
this.add(new Button("Seven"));
this.add(new Button("Eight"));
this.add(new Button("Nine"));
this.add(new Button("Ten"));
this.update(this.getGraphics());
}
ActionListener menuOpen = new ActionListener(){
public void actionPerformed(ActionEvent e){
addBtns();
}
};//end of anonymous class to handle menu item "open"
}//End

