0% found this document useful (0 votes)
43 views3 pages

Oop Visual Contoh 1: Menampilkan Visual Messagedialog

The document contains 4 examples of creating simple visual/graphical user interface (GUI) forms using Java Swing. The first example displays a simple message dialog. The second example creates a basic JFrame window. The third example adds a label to the JFrame. The fourth example demonstrates adding multiple GUI components like labels, text fields, and buttons to the JFrame and arranging them in a grid layout.

Uploaded by

Aulia Ulkhairi
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views3 pages

Oop Visual Contoh 1: Menampilkan Visual Messagedialog

The document contains 4 examples of creating simple visual/graphical user interface (GUI) forms using Java Swing. The first example displays a simple message dialog. The second example creates a basic JFrame window. The third example adds a label to the JFrame. The fourth example demonstrates adding multiple GUI components like labels, text fields, and buttons to the JFrame and arranging them in a grid layout.

Uploaded by

Aulia Ulkhairi
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

OOP VISUAL Contoh 1 : Menampilkan Visual MessageDialog

import javax.swing.*; public class WelcomeSToy { /** Creates a new instance of HelloWorldSToy */ public WelcomeSToy() { } public static void main(String args[]) { JOptionPane.showMessageDialog(null,"Hello World!"); System.exit(0); } }

Contoh 2 : Merancang Form sederhana


import javax.swing.*; import java.awt.*; class visual { public static void main(String args[]) { JFrame.setDefaultLookAndFeelDecorated(true); JFrame GUIku = new JFrame("Tampilan Form Utama"); GUIku.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); GUIku.setSize(500,500); GUIku.setLocation(200,150); GUIku.setVisible(true); } }

Contoh 3 : Merancang Form sederhana dengan Label


import javax.swing.*; import java.awt.*; class LatihanGUI extends JFrame { private Container ctn = new Container(); LatihanGUI() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize(500,500); setLocation(200,150); setTitle("Tampilan Form Utama"); ctn = getContentPane(); ctn.setLayout(new FlowLayout()); ctn.add(new JLabel("Tampilan GUI Pertama")); setVisible(true); } public static void main(String args[]) { new LatihanGUI(); } }

Contoh 4 : Merancang Form sederhana dengan beberapa Komponen


import javax.swing.*; import java.awt.*; import java.awt.event.*; public class Komponen{ public static void main(String[ ] args){ JFrame frame = new JFrame("Komponen Sederhana"); JLabel label = new JLabel("Pemrograman Berorientasi Obyek"); label.setForeground(Color.yellow); label.setBackground(Color.blue); label.setOpaque(true); label.setFont(new Font("SansSerif", Font.BOLD, 14)); frame.getContentPane().setLayout(new FlowLayout()); frame.getContentPane().add(label); JLabel label2 = new JLabel(""); frame.getContentPane().add(label2); JLabel label3 = new JLabel(""); frame.getContentPane().add(label3); JLabel label4 = new JLabel(""); frame.getContentPane().add(label4); frame.getContentPane().setLayout(new GridLayout(0,2)); JLabel label5 = new JLabel("Nama :"); JTextField textField = new JTextField(20); frame.getContentPane().add(label5); frame.getContentPane().add(textField); JLabel label6 = new JLabel(""); frame.getContentPane().add(label6); JLabel label7 = new JLabel(""); frame.getContentPane().add(label7); JButton b1 = new JButton("Tombol"); frame.getContentPane().add(b1); frame.pack(); frame.setVisible(true); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLocation(300,150); } }

You might also like