1 / 19

Graphical User Interface

Graphical User Interface. Tujuan. Mengetahui perbedaan AWT dan Swing Mengetahui kegunaan komponen-komponen aplikasi visual di Java Mampu menggunakan komponen-komponen Swing untuk membuat aplikasi visual Mampu membuat event handling di Java. AWT vs Swing. AWT. Swing.

ellema
Download Presentation

Graphical User Interface

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. Graphical User Interface

  2. Tujuan • Mengetahuiperbedaan AWT dan Swing • Mengetahuikegunaankomponen-komponenaplikasi visual di Java • Mampumenggunakankomponen-komponen Swing untukmembuataplikasivisual • Mampumembuat event handling di Java

  3. AWT vs Swing AWT Swing Pada package javax.swing Dikembangkansetelah AWT Look and feel not depend on OS Komponenlebihbervariasi Tidaksemua browser support applet dg Swing • Terdapatpada package java.awt • Dikembangkanlebihawal • Look and feel depend on OS • Komponenterbatas • Applet mudahdikenali browser

  4. Contoh program dg Swing

  5. Macam-macamkomponen Swing • JFrame • JLabel • JButton • JTextField • JTextArea • JCombobox • Jlist • JOptionPane • JFileChooser, • dll • Tiapkomponenmemilikiproperti yang digunakanuntukmengaturtampilan • Untukmenggunakansalahsatu, harusimpordarijavax.swing

  6. event handling (penanganankejadian)

  7. Event (kejadian) • Event : kejadian yang munculketika user berinteraksidenganaplikasi. • Contoh : • klik mouse • kliktombol • mouse bergerakdiatas form • memilihdari combo box/list • klikkanan/kiri mouse diataskomponen, • dll

  8. Event Handling • Prosesuntukmemberikanresponthd event. • Di Java, mekanisme event handling di Java dikenal dg delegation event model. • Istilah2 pd mekanismetsb : • event source • tempatterjadinya event • yaitu komponen2 visual • event listener : objekpenerima & pengolah event • event object : objekygterbentuksaattjd event

  9. Delegation Event Model

  10. Contoh Event Handling langkah 1 langkah 3 langkah 2

  11. Komponenpadaevent handling • Kelasuntukmenangani event harusmengimplementasikan (kelas/interface) event listener. Cara lain adlh dg membuatkelasturunandarikelas yang telahmengimplementasikansalahsatu event listener. • Kelas yang mengimplementasikan listener harusmengimplementasikanseluruh method yang adadikelas/interface listener. • Listener harusdidaftarkankedalamobjek yang akanberperansbg event source.

  12. Tipe-tipe event

  13. Macam-macamEvent Source

  14. Beberapa Interface Listener

  15. Contoh Event handling (2) import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JComboBox; import javax.swing.JFrame; import javax.swing.JLabel; public class Swing3 extends JFrame implements ActionListener{ JComboBoxcb; JLabel lb; String items[] = {"Acer", "Compaq", "Dell", "Fujitsu", "Sony", "Toshiba"}; public Swing3(String title){ super(title); setBounds(0, 0, 300, 170); getContentPane().setLayout(null); setResizable(false); setDefaultCloseOperation(EXIT_ON_CLOSE);

  16. cb = new JComboBox(); for (int i=0; i<items.length; i++) cb.addItem(items[i]); cb.setLocation(30, 50); cb.setSize(cb.getPreferredSize()); lb = new JLabel("Program dimulai."); lb.setLocation(150, 50); lb.setSize(lb.getPreferredSize()); cb.addActionListener(this); getContentPane().add(cb); getContentPane().add(lb); setVisible(true); setLocationRelativeTo(null); }

  17. public static void main(String[] args) { Swing3 frame = new Swing3("Demo JCombobox"); } @Override public void actionPerformed(ActionEvent e) { if (e.getSource() == cb){ String s = ""+ cb.getSelectedItem(); lb.setText(s); } } }

  18. Tugas

More Related