cs12420 lecture 02 menus
Download
Skip this Video
Download Presentation
CS12420 - Lecture 02 Menus

Loading in 2 Seconds...

play fullscreen
1 / 12

CS12420 - Lecture 02 Menus - PowerPoint PPT Presentation


  • 96 Views
  • Uploaded on

CS12420 - Lecture 02 Menus. Lynda Thomas [email protected] Menus are like Buttons. Use a Listener Classes involved are: JMenuBar JMenu JMenuItem Warning: you may use words slightly differently!. MenuBar. Menu. MenuItem. Look in menus directory for FirstMenuFrame.java. Alternatively.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about ' CS12420 - Lecture 02 Menus' - amora


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
menus are like buttons
Menus are like Buttons
  • Use a Listener
  • Classes involved are:
    • JMenuBar
    • JMenu
    • JMenuItem
  • Warning: you may use words slightly differently!
slide3

MenuBar

Menu

MenuItem

alternatively
Alternatively
  • You could use a separate MenuListener class
  • See SecondMenuFrame.java and MenuListener.java
  • Let’s step through code with debugger and see animation of what is happening...
slide7

1: new SecondMenuFrame()

JFrame

4: new

MenuListener(this)

MenuListener

SimpleFrame

smFrame

SecondMenuFrame

7: setPanelColor(Color.green)

3: new ColorPanel

JMenu

Colours

JMenu

Options

JMenuItem

Green

JMenuBar

JMenuItem

JMenuItem

JMenuItem

JMenuItem

2: new JMenu*

JPanel

ColorPanel

6: select green:

actionPerformed called

5: e.g. green.addActionListener(menuList)

layout managers
Layout Managers
  • BorderLayout is default for JFrame
  • FlowLayout is default for JPanel
  • GridLayout:

public TextPanel() {

setLayout(new GridLayout(2,2,5,5));

//2 rows, 2 cols, spaces

add (new JLabel("Amount: "));

inputField=new JTextField(8); add (inputField);

add (new JLabel("Balance: "));

balanceField=new JTextField(8); add (balanceField);

}

possible mistakes
Possible mistakes:
  • Misspelling javax.swing in import
  • Forgetting setVisible(true) (done for you in SimpleFrame)
  • Forgetting the JFrame.EXIT_ON_CLOSE
  • If buttons etc. don’t work:
    • Have you got something Listening to the button?
    • Is there an appropriate action in actionPerformed?
    • Try just printing ‘they hit button X’
more components
More components

Radio buttons and Combo boxes

ComboBoxDemo.java

and

RadioButtonDemo.java

in this lecture
In this lecture
  • We looked at menus

In the next lecture we look at drawing

ad