FAKULTAS TEKNIK UNIVERSITAS NEGERI YOGYAKARTA LAB SHEET PEMROGRAMAN JAVA 2

dokumen-dokumen yang mirip
FAKULTAS TEKNIK UNIVERSITAS NEGERI YOGYAKARTA LAB SHEET PEMROGRAMAN 2

FAKULTAS TEKNIK UNIVERSITAS NEGERI YOGYAKARTA LAB SHEET PEMROGRAMAN JAVA 2

FAKULTAS TEKNIK UNIVERSITAS NEGERI YOGYAKARTA LAB SHEET PEMROGRAMAN JAVA 2

FAKULTAS TEKNIK UNIVERSITAS NEGERI YOGYAKARTA LAB SHEET PEMROGRAMAN JAVA 2

FAKULTAS TEKNIK UNIVERSITAS NEGERI YOGYAKARTA LAB SHEET PEMROGRAMAN 2

FAKULTAS TEKNIK UNIVERSITAS NEGERI YOGYAKARTA LAB SHEET PEMROGRAMAN 2

Sendy Ferdian Sujadi

FAKULTAS TEKNIK UNIVERSITAS NEGERI YOGYAKARTA LAB SHEET PEMROGRAMAN JAVA 2

Materi : GUI AWT & SWING.

PEMROGRAMAN II. Materi : nursari2010.blogdetik.com String String Handling Java.util,Java.io. By : Sri Rezeki Candra Nursari

GUI (Grapichal User Interface)

FAKULTAS TEKNIK UNIVERSITAS NEGERI YOGYAKARTA LAB SHEET PEMROGRAMAN 2

Creating Graphical User Interfaces [1] with Java By: De Rosal Ignatius Moses Setiadi

Pemrograman Lanjut. Interface

FAKULTAS TEKNIK UNIVERSITAS NEGERI YOGYAKARTA LAB SHEET PEMROGRAMAN 2

Pemrograman Berorientasi Obyek. Ramos Somya

Modul Praktikum 9 BAB IX LAYOUTING. Departemen Teknologi Informasi Telkom Applied Science School H a l

GUI & Event Handling. Viska Mutiawani, M.Sc. 1 Viska Mutiawani - Informatika FMIPA Unsyiah

Pemrograman Berorientasi Objek Lanjut Lecture 3: Layout Manager

Pemrograman Lanjut. Intro to GUI (Graphical User Interface)

BAB IX MEMBUAT FORM 9.1 Membuat Form Secara Konvensional

FAKULTAS TEKNIK UNIVERSITAS NEGERI YOGYAKARTA LAB SHEET PEMROGRAMAN JAVA 2

Membangun GUI (dengan AWT & Swing) OOP Java

IF PEMROGRAMAN LANJUT GRAPHICAL USER INTERFACE (GUI) 11 DENGAN SWING. Oleh : Andri Heryandi, M.T.

Slide 6: Writing Classes

GUI & Event Handling. Viska Mutiawani, M.Sc

Membuat Menu Login Sederhana [Full Coding]

Modul Praktikum 8 Pemograman Berorientasi Objek

MODUL 7 - EXCEPTION HANDLING

MODUL PRAKTIKUM PEMROGRAMAN BERORIENTASI OBJEK

Pemrograman Java. Pertemuan VIII By: Augury

FAKULTAS TEKNIK UNIVERSITAS NEGERI YOGYAKARTA LAB SHEET PEMROGRAMAN 2

PEMROGRAMAN BERORIENTASI OBJEK

Graphics2D dan Geometry

Membuat User Interface dengan Swing. Program yang dibuat sebelumnya selalu berbasis console User lebih senang berinteraksi dengan

MODUL PRAKTIKUM STRUKTUR DATA DAN ALGORITMA STACK

GUI Event Handling. minggu 13. Wednesday, 16 May 12

ADDING RTGS BENEFICIARY FOR CHECKER MAKER SYSTEM

Membuat Kalkulator dengan Java

Dasar Perancangan Graphical User Interface

PENGOLAHAN CITRA Ch.4 M E N G O L A H C I T R A M E N J A D I N E G A T I V E Bayu Pratama RN [ ]

.NET Controls. Control Creation

GUI, Ev e Ev n e t n Handling, Ex ception Handling in Java

A. TUJUAN PEMBELAJARAN

Pemograman Swing. Netbeans:

2. Manakah diantara pilihan berikut ini yang merupakan bagian dari event delegation model? Sebuah komponen yang menampilkan message

Modul 2. [access specifier] [tipe data] [nama variabel];

Aplikasi Grafik Menggunakan Netbeans

BAB I PROJECT NETBEANS DAN GUI SEDERHANA

Pemrograman Web. Object Oriented Programming in PHP 5

Dwiny Meidelfi, M.Cs

PENGOLAHAN CITRA Ch.3 M E N G O L A H C I T R A M E N J A D I G R A Y S C A L E Bayu Pratama RN [ ]

MODUL 3. Classes and Objects (part I)

Modul Praktikum 7 Pemograman Berorientasi Objek

PEMROGRAMAN BERORIENTASI OBJEK

Abstract Window Toolkit

- Setiap pola yang menggambarkan permasalahan yang terjadi secara berulang, serta

Konsep Dasar Pemrograman Berorientasi Objek

MODUL III ARRAYLIST TUGAS PENDAHULUAN

BINA NUSANTARA UNIVERSITY NATA LASE

1. Soal Packet Tracer

IF PEMROGRAMAN LANJUT EVENT. Oleh : Andri Heryandi, M.T.

Modul 08. User Interface 01

PERTEMUAN VI AWT DAN SWING TUJUAN PRAKTIKUM. 1. Praktikan mengenal pembuatan GUI pada Java. 2. Praktikan memahami action pada objek dalam Java.

1/5. while and do Loops The remaining types of loops are while and do. As with for loops, while and do loops Praktikum Alpro Modul 3.

Pemrograman Berorientasi Objek Lanjut Lecture 01 - Introduction

Materi 3 Pemrograman Visual

5/24/2012. Pemograman Berorientasi Objek. Pembahasan. Abstract Windowing Toolkit & Swing. Pembahasan

PRAKTIKUM 4. Pemrograman Berorientasi Objek

BAB I PENDAHULUAN. Listing 1.1 menunjukkan program GUI Java sederhana menggunakan AWT. import java.awt.*; import java.awt.event.*;

Pemrograman Lanjut. Class : Deeper Look 2

Operator dan Assignment. Pertemuan 3 Pemrograman Berbasis Obyek

MODUL PRAKTIKUM KE 3 A.

A. TUJUAN PEMBELAJARAN

GUI Event Handling. 5. Mendiskusikan keuntungan-keuntungan dari menggunakan inner dan anonymous class

DIK-020 Pemograman Berorientasi Objek 5/24/2012

Materi 5 Pemrograman Visual

Pada praktikum ini, anda akan mengimplementasikan sebuah game sederhana, bernama Smiley Face.

BAB IX. USER INTERFACE

Membuat Frame, Label, TextField dan Button di Java [Full Coding]

INSTRUKSI PENCABANGAN

PEMROGRAMAN II. By : Sri Rezeki Candra Nursari

Tutorial A Menggambar Bendera Merah Putih Pada Frame

Overriding, Overloading, Polymorphism. Pertemuan 10 Pemrograman Berbasis Obyek Dr. Rodiah

GUI in Java. Presented by HCI Team Ali Ridho Barakbah Umi Sa adah Nur Rosyid Mubtada i. Supervised by Prof. Kohei Arai

MODUL PRAKTIKUM PEMROGRAMAN BERORIENTASI OBJEK

Materi 1 Pemrograman Visual

Pertemuan 8. Dasar query basis data dengan SQLite ARFIAN HIDAYAT, S.KOM

A. TUJUAN PEMBELAJARAN

JAVA SWING. Swing merupakan library pada java untuk membuat sebuah tampilan seperti

MODUL PRAKTIKUM STRUKTUR DATA DAN ALGORITMA QUEUE

Praktikum JTable. Gambar 1

OBJECT ORIENTED PROGRAMMING. Day 3 : Operator dan Assignment

Rahasia Cermat & Mahir Menguasai Akuntansi Keuangan Menengah (Indonesian Edition)

Object Oriented Pemrograman yang mendukung konsep objek. (inheritance, capsulation, polymorphism)

Prosedur dan Fungsi. Ciri prosedur pada java selalu dimulai dengan : private/public void namaprosedur ( tipedataparameter1 namaparameter1,

TUJUAN. Memahami Koneksi dan Pemrosesan Basis Data di Java Memahami JDBC Menggunakan MySQL pada program Java

Transkripsi:

No. LST/EKA/PTI208/10 Revisi : 01 Mei 2009 Hal 1 dari 9 A. Kompetensi Setelah mengikuti praktikum ini, mahasiswa diharapkan mampu menerapkan Jpanel dan BoxLayout dalam pembuatan program. B. Dasar Teori JPanel JPanel is a generic lightweight container: a generic Swing container object that can contain other Swing and AWT components. Components added to a container are tracked in a list. The order of the list will define the components' front-to-back stacking order within the container. If no index is specified when adding a component to a container, it will be added to the end of the list (and hence to the bottom of the stacking order). Common Public Constructors: JPanel () Constructs a new blank JPanel. Common Public Methods: ü void paint (Graphics g) Overrides the paint method of JPanel. ü void repaint () Repaints this component, and causes a call to the paint method. ü void setlayout (LayoutManager Manager) Sets the layout manager for the panel. ü Component add (Component Item) Appends the specified component to the end of this container. ü void add (Component Item, Object Constraints) Appends the specified component with the specified constraints. BoxLayout Class A layout manager that allows GUI components to be arranged left-to-right or top-tobottom in a container. Class Box declares a container with BoxLayout as its default layout manager and provides static methods to create a Box with a horizontal or vertical BoxLayout. Ø Constructor ü public BoxLayout (Container target, int axis) The only constructor for this layout manager; it takes as input the container to manage and how the components should be laid out: left to right (X_AXIS) or top to bottom (Y_AXIS). ü Box(int)

No. LST/EKA/PTI208/10 Revisi : 01 Mei 2009 Hal 2 dari 9 Creates a Box -- a lightweight container that uses a BoxLayout with the specified alignment (BoxLayout.X_AXIS or BoxLayout.Y_AXIS). Note that a Box is not a JComponent -- it's implemented as a subclass of Container. This makes it as lightweight as possible, but it lacks JComponent features such as borders. If you want a simple JComponent as a container, use JPanel. Ø Constants The BoxLayout class contains the two constants listed in Table 1. Constant Type X_AXIS Y_AXIS int int Table 1. BoxLayout constants Description Used with the constructor to create a manager that lays out components along a horizontal axis. This constant can also be used with the constructor for the Box class. Used with the constructor to create a manager that lays out components along a vertical axis. This constant can also be used with the constructor for the Box class. Ø Method Method Purpose createhorizontalbox() Creates a Box that lays out its components from left to right. createverticalbox() Creates a Box that lays out its components from top to bottom. createrigidarea(dimension) Create a rigid lightweight component. Create a glue lightweight component. Horizontal glue and vertical glue can be very useful. createhorizontalglue() createverticalglue() createglue() createhorizontalstrut() createverticalstrut() Box.Filler(Dimension, Dimension, Dimension) Create a "strut" lightweight component. We recommend using rigid areas instead of struts. Creates a lightweight component with the specified minimum, preferred, and maximum sizes (with the arguments specified in that order). See the custom Box.Filler discussion, earlier in this section, for details. The Box class defines a nested class, Box.Filler that provides invisible components. The Box class provides convenience methods to help you create

No. LST/EKA/PTI208/10 Revisi : 01 Mei 2009 Hal 3 dari 9 common kinds of filler. The following table gives details about creating invisible components with Box and Box.Filler. Type Size Constraints How to Create rigid area horizontal Box.createRigidArea(size) Box.createHorizontalGlue() glue vertical Box.createVerticalGlue() custom Box.Filler (as specified) new Box.Filler(minSize, prefsize, maxsize) Here's how you generally use each type of filler: Rigid area Use this when you want a fixed-size space between two components. For example, to put 5 pixels between two components in a left-to-right box, you can use this code: container.add(firstcomponent); container.add(box.createrigidarea(new Dimension(5,0))); container.add(secondcomponent); Glue Use this to specify where excess space in a layout should go. Think of it as semiwet glue -- stretchy and expandable, yet taking up no space unless you pull apart the components that it's sticking to. For example, by putting horizontal glue between two components in a left-to-right box, you make any extra space go between those components, instead of to the right of all the components. Here's an example of making the space in a left-to-right box go between two components, instead of to the right of the components: container.add(firstcomponent); container.add(box.createhorizontalglue()); container.add(secondcomponent);

No. LST/EKA/PTI208/10 Revisi : 01 Mei 2009 Hal 4 dari 9 Custom Box.Filler Use this to specify a component with whatever minimum, preferred, and maximum sizes you want. For example, to create some filler in a left-to-right layout that puts at least 5 pixels between two components and ensures that the container has a minimum height of 100 pixels, you could use this code: container.add(firstcomponent); Dimension minsize = new Dimension(5, 100); Dimension prefsize = new Dimension(5, 100); Dimension maxsize = new Dimension(Short.MAX_VALUE, 100); container.add(new Box.Filler(minSize, prefsize, maxsize)); container.add(secondcomponent); Figure 1 shows an example of a horizontal panel (A) and a vertical panel (B). To prove this BoxLayout is just a layout manager, we'll use regular AWT panels and buttons.

No. LST/EKA/PTI208/10 Revisi : 01 Mei 2009 Hal 5 dari 9 Here's a look at the code to generate the horizontal Box. (You need to change the axis you use in the constructor to get the vertical Box. That example is online as VBox.java.) import java.awt.*; import java.awt.event.*; import javax.swing.*; public class HBox extends JFrame { public HBox() { super("horizontal Box Test Frame"); setsize(200, 100); Panel box = new Panel( ); // Use BoxLayout.Y_AXIS if you want a vertical Box. box.setlayout(new BoxLayout(box, BoxLayout.X_AXIS)); setcontentpane(box); for (int i = 0; i < 3; i++) { Button b = new Button("B" + i); box.add(b); setdefaultcloseoperation(exit_on_close); setvisible(true); public static void main(string args[]) { HBox bt = new HBox( ); Demonstrating BoxLayout. import java.awt.*; import javax.swing.*; public class BoxLayoutFrame extends JFrame { // set up GUI public BoxLayoutFrame() { super( "Demonstrating BoxLayout" ); // create Box containers with BoxLayout Box horizontal1 = Box.createHorizontalBox(); Box vertical1 = Box.createVerticalBox(); Box horizontal2 = Box.createHorizontalBox(); Box vertical2 = Box.createVerticalBox(); final int SIZE = 3; // number of buttons on each Box // add buttons to Box horizontal1 horizontal1.add( new JButton("Button " + count)); // create strut and add buttons to Box vertical1 {

No. LST/EKA/PTI208/10 Revisi : 01 Mei 2009 Hal 6 dari 9 vertical1.add( Box.createVerticalStrut(25)); vertical1.add( new JButton("Button " + count )); // create horizontal glue and add buttons to Box horizontal2 { horizontal2.add( Box.createHorizontalGlue() ); horizontal2.add( new JButton( "Button " + count )); // create rigid area and add buttons to Box vertical2 { vertical2.add( Box.createRigidArea(new Dimension(12, 8))); vertical2.add( new JButton("Button " + count)); // create vertical glue and add buttons to panel JPanel panel = new JPanel(); panel.setlayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); { panel.add(box.createglue()); panel.add(new JButton("Button " + count)); // create a JTabbedPane JTabbedPane tabs = new JTabbedPane( JTabbedPane.TOP, JTabbedPane.SCROLL_TAB_LAYOUT ); // place each container on tabbed pane tabs.addtab( "Horizontal Box", horizontal1 ); tabs.addtab( "Vertical Box with Struts", vertical1 ); tabs.addtab( "Horizontal Box with Glue", horizontal2 ); tabs.addtab( "Vertical Box with Rigid Areas", vertical2 ); tabs.addtab( "Vertical Box with Glue", panel ); add( tabs ); // place tabbed pane on frame // end BoxLayoutFrame constructor public static void main(string args[]) { BoxLayoutFrame boxlayoutframe = new BoxLayoutFrame(); boxlayoutframe.setdefaultcloseoperation(jframe.exit_on_close); boxlayoutframe.setsize(400, 220); // set frame size boxlayoutframe.setvisible(true); // display frame // end main // end C. Alat/ Bahan 1. Lab. Sheet Pemrograman Java 10 2. PC / Laptop with OS installed 3. JDK 1.5 or latest 4. J-Creator or text editor

No. LST/EKA/PTI208/10 Revisi : 01 Mei 2009 Hal 7 dari 9 D. Langkah Kerja 1. Baca dan pahami dasar teori di atas. 2. Lakukan kompilasi dan eksekusi terhadap contoh-contoh source code atau program yang ada di dasar teori dan LAMPIRAN. 3. Kerjakan tugas individu di bawah. E. Tugas Individu Dengan menggunakan JPanel dan Box Layout, buatlah sebuah program yang menampilkan kumpulan JButton dengan tampilan sebagai berikut Ø Input Box (Joptionpane) yang meminta masukan untuk menentukan jumlah Button dalam arah vertikal. Ø Setelah di Enter (OK), kemudian muncul Input Box (Joptionpane) yang meminta masukan untuk menentukan jumlah Button dalam arah horisontal. Ø Kemudian muncul Frame yang menampilkan label, text, button dengan jumlah sesuai dengan input di atas. Contoh untuk jumlah button 8x5

No. LST/EKA/PTI208/10 Revisi : 01 Mei 2009 Hal 8 dari 9 Contoh untuk jumlah button 4x8 Contoh untuk jumlah button 0x0

No. LST/EKA/PTI208/10 Revisi : 01 Mei 2009 Hal 9 dari 9 Ø Tombol Exit untuk keluar (menutup frame) Ø Tinggi dan lebar Frame otomatis mengikuti jumlah Button yang dimasukkan F. Lampiran CH 62 (Introduction to Computer Science using Java, Java 5.0 version, January 2006, Bradley Kjell, Central Connecticut State University http://chortle.ccsu.edu/cs151/cs151java.html) Java Swing, 2nd Edition, Brian Cole, Robert Eckstein, James Elliott, Marc Loy, David Wood