Heya guys, i'm a newbie at java gui and trying to make a calculator using swing. Although i have made the calculator previously but this time i'm trying to add a menu bar also. The problem with the code is whenever i try to add menu bar without making the mainframe's layout as borderlayout it does not get visible i.e. with layout set as null. and also if the layout of main frame is set to borderlayout and with menu properly visible then it becomes impossible to insert the other jtextarea and buttons on the rest of the frame..i'm posting my code plz help me if u can!!
class main
{
public static void main(String args[])
{
JFrame main = new JFrame("Calc");
main.setLocationByPlatform(true);
main.setLocation(400,80);
main.setLayout(new BorderLayout());
JMenuBar menu = new JMenuBar();
JPanel TextPanel = new JPanel();
JPanel ButtonPanel = new JPanel();
JMenu File = new JMenu("File");
JMenu Edit = new JMenu("Edit");
JMenu Help = new JMenu("Help");
JMenuItem New = new JMenuItem("New");
JMenuItem Save = new JMenuItem("Save");
JMenuItem SaveAs = new JMenuItem("SaveAs");
menu.add(File);
menu.add(Edit);
menu.add(Help);
File.add(New);
File.add(Save);
File.add(SaveAs);
//Text panel--------------------------------------------
JTextField t = new JTextField();
t.setBackground(Color.yellow);
t.setForeground(Color.BLACK);
Font f = t.getFont();
Font new_f = new Font(f.getFontName(),f.getStyle(),f.getSize()+10);
t.setFont(new_f);
//t.setSize(400, 100);
TextPanel.setLayout(new BorderLayout());
TextPanel.add(t);
//--------------------------------------------------------------
main.add(menu, BorderLayout.PAGE_START);
main.add(TextPanel,BorderLayout.CENTER);
main.add(ButtonPanel);
main.setSize(400,600);
main.setVisible(true);
}
}
class handler implements ActionListener
{
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
}
}