Slide 1Slide 2Slide 3Slide 4Slide 5Slide 6Slide 7Slide 8Slide 9Slide 10Slide 11Slide 12Slide 13Slide 14Slide 15Creating GUIs10-25-2010Opening DiscussionNo IcP today.Questions on the assignment?Minute essay comments:Difference between Source and Scanner.MotivationWhile text based programs still play a very big role in computing, it is mostly behind the scenes.You are far more used to working with Graphical User Interfaces (GUIs).It is time that we learn how to write GUIs in Scala.LibrariesThere are three libraries that will wind up being relevant to our discussion.java.awt – The Abstract Windowing Toolkit. Original Java GUI library.javax.swing – Swing was built on top of AWT to be more flexible.scala.swing – Scala code wrapped around Java Swing to aid Scala GUI programming.Making a WindowIn order to write a GUI we need to start by popping up a window.For the main window of a GUI, we will make a MainFrame. For other windows there are Frame and Dialog types.We can set the title and size fields of the MainFrame when we create it.Set visible to true to bring up the window.Oddly, we have to prevent the script from stopping.Active ComponentsGUIs are made from components. Use scala.swing package.Button(text:String)(action : => Unit).new CheckBox(label:String)selected:Booleannew ComboBox(items:Seq[A])selection.index to get the index of the current selectionnew EditorPane(contentType:String,text:String)More Componentsnew FormattedTextField(format:String)text:String that will tell you the textnew Label(text:String)new ListView(items:Seq[A]) Use collection selection.indices to interact with the index values that are selected.new PasswordField or new PasswordField(text:String)text:String will tell you the textMore Componentsnew ProgressBarmin:Int, max:Int, and value:Intnew RadioButton(text:String)selected:Booleannew ScrollBarminimum, maximum, and value are all IntsGenerally use ScrollPanenew Slidermin, max, valueorientationStill More Componentsnew Table(rowData: Array[Array[Any]], columnNames: Seq[Any])new TextArea(text:String)text:Stringnew TextField(text:String)text:StringPanes and PanelsWe build complex GUIs by nesting panels and panes.BorderPanelCan hold up to five different components in the north, south, east, west, and center positions. Add to the layout as a tuple of (Component, Position).BoxPanelCan hold a number of components either vertically or horizontally, each takes the space it needs. Use new BoxPanel(Orientation.Vertical). Use contents+=Button(“text”)(action).More PanelsFlowPanelComponents are laid out from left to right wrapping like text in a word processor. You can pass a variable length list of components as an argument at construction or add the components to contents.GridBagPanelThis panel is more complex.GridPanelHolds a regular grid of components. You specify how many rows and columns the grid has at creation.PanesScrollPaneHolds a single component passed in as an argument at construction. Scroll bars automatic. SplitPaneTwo components separated by a moveable bar.new SplitPane(Orientation.Horizontal, leftComp,rightComp)TabbedPaneOne component shown at a time. Tabs are always shown. Add components by adding Pages to the page object. pages += new Page(“A Tab”,tabComponent)MenusWindows can set the MenuBar.Add Menu objects to the contents of the MenuBar.Add MenuItems to the contents of the Menus.new MenuItem(Action(“Exit”){ exit(0) })GUI for PokemonLet's spend the rest of class laying out and coding up a GUI we could use to edit our Pokemon.Minute EssayIs there some type of GUI you would like to have as assignment #5.Turn in assignment #4 today.Interclass problem:Create a GUI for a calculator or something else you think is
View Full Document