Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Creating menu in an applet?

 
Mark Joslin
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm having problems creating a menu in an applet. I saw it earlier and then deleted what was some useless code, and it stopped showing up? I figure I'm missing something? I tried adding a borderlayout then add(jBar, BorderLayout.NORTH) but that didn't work. Can you help me?

public void init()
{
Container contentPane = getContentPane();
contentPane.setLayout(new BorderLayout());

//background color: lightblue
float red = 0f;
float blue = .3f;
float green = .2f; // Java sees double, must specify a suffix of f to create float
float alpha = .05f;
Color lightBlue = new Color(red, green, blue, alpha); //float required for constructor
contentPane.setBackground(lightBlue);

//Menu
JMenuBar jBar = new JMenuBar();

JMenu bankMenu = new JMenu("Bank");
JMenuItem b;

b = new JMenuItem("New Account");
b.addActionListener(new menuListener());
bankMenu.add(b);

b = new JMenuItem("Open Account");
b.addActionListener(new menuListener());
bankMenu.add(b);

b = new JMenuItem("Delete Account");
b.addActionListener(new menuListener());
bankMenu.add(b);

b = new JMenuItem("Account transfer");
b.addActionListener(new menuListener());
bankMenu.add(b);

b = new JMenuItem("Overview of Accounts");
b.addActionListener(new menuListener());
bankMenu.add(b);

jBar.add(bankMenu);
setJMenuBar(jBar);

//Title JBankset
JLabel title = new JLabel("JBank - A Comp 285 Project");
contentPane.add(title);

}
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!