1 / 8

Gui Interfaces a la Swing

Gui Interfaces a la Swing. Up to speed with Swing by Steven Gutz is a good source It don’t mean a thing if it ain’t got that swing Duke Ellington. Simple Gui layout Design. Four main decisions 1. User Interactions what to gather from user, what to show him

kert
Download Presentation

Gui Interfaces a la Swing

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. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Gui Interfacesa la Swing Up to speed with Swing by Steven Gutz is a good source It don’t mean a thing if it ain’t got that swing Duke Ellington

  2. Simple Gui layout Design Four main decisions 1. User Interactions what to gather from user, what to show him 2. Particular objects on screen JTextField, TextArea, JButton, JPanels, JLabels, JFrame... 3. General layout of Screen borderlayout, gridlayout, flowlayout,…. 4. Listeners connect user actions with program activities WindowListeners, ActionListeners, ItemListeners, ….

  3. Minimal Objects and methods • JFrame: where you start • Container mainPane = getContentPane() is where you add other components. • JPanels: • container for other objects including Jpanels • setLayoutManager(..) • JTextField(int size): setText, getText, addActionListener • TextArea(int row, int col): append • JButton(String s): named button, addActionListener • JLabel(String s): just a string • More: JTabbedPane, ScollBars, Lists, Checkboxes, Menus, Dialogs, PopUps, Sliders,Toolbars…..and on and on

  4. Layout Managers • FlowLayout() • right to left with wrap around • default manager for JPanel • BorderLayout() • north, south, east, west, center • default for contentPane • GridLayout(int row, int columns) • row and columns • GridBag Layout (..) • hurts my head • Layout Managers can be nested.

  5. Listeners are Interfaces • WindowListeners • respond to window events, such as miniminizing window, closing, moving, maximizing, etc. • Window will not Close! Need to add a listener. • Has 7 methods, I.e. obligations. • ActionListeners • For JButtons, responds to clicking on buttons • For JTextFields, responds to “enter” • Still need to define the activity • Only 1 method: actionPerformed(ActionEvent ae) • ItemListeners, MouseListeners, KeyListeners,…. • 11 listeners at last count.

  6. Events • ActionEvent • button pressed, text entered, …. • WindowEvent • windowIconified, windowClosed, windowOpened,… • Key Events: • keyTyped, keyPressed, keyReleased • MouseEvents: • mouseClicked, mousePressed, mouseReleased, mouseDragged, mouseMoved,... • TextEvent • textValue changed,.. • And on and on

  7. Closeable Hello World import javax.swing.*; // for J stuff import java.awt.event.*; // for listeners import java.awt.*; // for the layout managers class Driver extends JFrame { public static void main(String[] args) { Driver driver = new Driver(); driver.show() // without this, you get nothing } Driver() { addWindowListener(new WindowDestroyer()); //needed to close window Container mainPane = getContentPane(); // default border layout mainPane.add(new Jlabel(“Hello World”)); } }

  8. Window Destroyer import java.awt.event.*; class WindowDestroyer extends WindowAdapter { public void windowClosing(WindowEvent we) { System.exit(0); } } WindowListener has 7 methods to define. WindowAdapter defines them all to do nothing.

More Related