Presentation is loading. Please wait.

Presentation is loading. Please wait.

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.

Similar presentations


Presentation on theme: "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."— Presentation transcript:

1 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

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.


Download ppt "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."

Similar presentations


Ads by Google