JComponent. JPanel. JFrame. JFrame JDialog, JOptionPane. JPanel. JPanel

Similar documents
Swing UI. Powered by Pentalog. by Vlad Costel Ungureanu for Learn Stuff

DM550 / DM857 Introduction to Programming. Peter Schneider-Kamp

Java Swing. Lists Trees Tables Styled Text Components Progress Indicators Component Organizers

Administrivia. CSSS Movie Night: Zombieland & Iron Man Date: Thurs., Mar 11 Time: 6 10 pm Location: DMP 310 Free pop & popcorn for every attendee!

DM503 Programming B. Peter Schneider-Kamp.

Administrivia. CSSS Movie Night: Zombieland & Iron Man Date: Thurs., Mar 11 Time: 6 10 pm Location: DMP 310 Free pop & popcorn for every attendee!

Introduction to the JAVA UI classes Advanced HCI IAT351

Systems Programming Graphical User Interfaces

MIT AITI Swing Event Model Lecture 17

1.1 GUI. JFrame. import java.awt.*; import javax.swing.*; public class XXX extends JFrame { public XXX() { // XXX. init() main() public static

Graphic User Interfaces. - GUI concepts - Swing - AWT

Handout 14 Graphical User Interface (GUI) with Swing, Event Handling

DM503 Programming B. Peter Schneider-Kamp.

Window Interfaces Using Swing Objects

Introduction to Graphical User Interfaces (GUIs) Lecture 10 CS2110 Fall 2008

Learn Java Programming, Dr.Hashamdar. Getting Started with GUI Programming

Introduction. Introduction


Chapter 8. Java continued. CS Hugh Anderson s notes. Page number: 264 ALERT. MCQ test next week. This time. This place.

Java continued. Chapter 8 ALERT ALERT. Last week. MCQ test next week. This time. This place. Closed book. Assignment #2 is for groups of 3

Graphical User Interface (GUI) components in Java Applets. With Abstract Window Toolkit (AWT) we can build an applet that has the basic GUI

CSE 143. Event-driven Programming and Graphical User Interfaces (GUIs) with Swing/AWT

Basics of programming 3. Java GUI and SWING

Dr. Hikmat A. M. AbdelJaber

2110: GUIS: Graphical User Interfaces

Building Graphical User Interfaces. GUI Principles

Building Graphical User Interfaces. Overview

Using Several Components

Goals. Lecture 7 More GUI programming. The application. The application D&D 12. CompSci 230: Semester JFrame subclass: ListOWords

Window Interfaces Using Swing Objects

Object-Oriented Programming Design. Topic : User Interface Components with Swing GUI Part III

The JFrame Class Frame Windows GRAPHICAL USER INTERFACES. Five steps to displaying a frame: 1) Construct an object of the JFrame class

Building Java Programs Bonus Slides

Overview. Building Graphical User Interfaces. GUI Principles. AWT and Swing. Constructing GUIs Interface components GUI layout Event handling

Part 3: Graphical User Interface (GUI) & Java Applets

Datenbank-Praktikum. Universität zu Lübeck Sommersemester 2006 Lecture: Swing. Ho Ngoc Duc 1

Chapter 9 Designing Graphical User Interfaces (GUIs)

Lecture 5: Java Graphics

encompass a group of features for building Graphical User Interfaces (GUI).

Graphical User Interfaces. Swing. Jose Jesus García Rueda

Graphical User Interfaces in Java - SWING

Layouts and Components Exam

Chapter 13 Lab Advanced GUI Applications Lab Objectives. Introduction. Task #1 Creating a Menu with Submenus

CSIS 10A Assignment 7 SOLUTIONS

User interfaces and Swing

Together, the appearance and how user interacts with the program are known as the program look and feel.

CSEN401 Computer Programming Lab. Topics: Graphical User Interface Window Interfaces using Swing

Control Flow: Overview CSE3461. An Example of Sequential Control. Control Flow: Revisited. Control Flow Paradigms: Reacting to the User

Graphical interfaces & event-driven programming

17 GUI API: Container 18 Hello world with a GUI 19 GUI API: JLabel 20 GUI API: Container: add() 21 Hello world with a GUI 22 GUI API: JFrame: setdefau

Top-Level Containers

Java. GUI building with the AWT

JLayeredPane. Depth Constants in JLayeredPane

CSE 331. Event-driven Programming and Graphical User Interfaces (GUIs) with Swing/AWT

Programming Language Concepts: Lecture 8

class BankFilter implements Filter { public boolean accept(object x) { BankAccount ba = (BankAccount) x; return ba.getbalance() > 1000; } }

Chapter 13 GUI Basics. Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved.

Graphical User Interface

Java: Graphical User Interfaces (GUI)

Queen s University Faculty of Arts and Science School of Computing CISC 124 Final Examination December 2004 Instructor: M. Lamb

Attempt FOUR questions Marking Scheme Time: 120 mins

CS 251 Intermediate Programming GUIs: Components and Layout

core 2 Basic Swing GUI Controls in Java 2

core programming Basic Swing GUI Controls in Java Marty Hall, Larry Brown

Chapter 13 Lab Advanced GUI Applications

INTRODUCTION TO (GUIS)

Graphics programming. COM6516 Object Oriented Programming and Design Adam Funk (originally Kirill Bogdanov & Mark Stevenson)

Starting Out with Java: From Control Structures Through Objects Sixth Edition

Chapter 12 GUI Basics

Išdėstymai. Lekt. dr. Pijus Kasparaitis m. m. pavasario semestras.

2010 가을학기부산대학교정보컴퓨터공학부 OVERVIEW OF GUI PROGRAMMING

Charlie Garrod Bogdan Vasilescu

COSC 123 Computer Creativity. Graphics and Events. Dr. Ramon Lawrence University of British Columbia Okanagan

Chapter 12 GUI Basics. Motivations. The design of the API for Java GUI programming

Advanced Java Programming. Swing. Introduction to Swing. Swing libraries. Eran Werner, Tel-Aviv University Summer, 2005

KF5008 Program Design & Development. Lecture 1 Usability GUI Design and Implementation

H212 Introduction to Software Systems Honors

Swing from A to Z Some Simple Components. Preface

Sketchpad. Plan for Today. Class 22: Graphical User Interfaces IBM 705 (1954) Computer as Clerk : Augmenting Human Intellect

JRadioButton account_type_radio_button2 = new JRadioButton("Current"); ButtonGroup account_type_button_group = new ButtonGroup();

CSE 331. Event- driven Programming and Graphical User Interfaces (GUIs) with Swing/AWT

Command-Line Applications. GUI Libraries GUI-related classes are defined primarily in the java.awt and the javax.swing packages.

Java Graphical User Interfaces

import javax.swing.*; import java.awt.*; import java.awt.event.*;

!"# $ %&# %####' #&() % # # # #&* # ## +, # -

CSE 8B Intro to CS: Java

PROGRAMMING DESIGN USING JAVA (ITT 303) Unit 7

AP CS Unit 11: Graphics and Events

Packages: Putting Classes Together

Java Programming Lecture 6

CHAPTER 2. Java Overview

JAVA NOTES GRAPHICAL USER INTERFACES

Graphical User Interface Programming

More Swing. CS180 Recitation 12/(04,05)/08

Swing I CHAPTER EVENT-DRIVEN PROGRAMMING 921 Events and Listeners 921

CS Exam 3 - Spring 2010

GUI (Graphic User Interface) Programming. Part 2 (Chapter 8) Chapter Goals. Events, Event Sources, and Event Listeners. Listeners

JAVA NOTES GRAPHICAL USER INTERFACES

Swing I Event-Driven Programming Buttons, Events, and Other Swing Basics Containers and Layout Managers 946

Frames, GUI and events. Introduction to Swing Structure of Frame based applications Graphical User Interface (GUI) Events and event handling

Transcription:

JComponent JPanel JPanel JFrameJDialog, JOptionPane JFrame JPanel

Myclass SomeInterface SomeInterface anobject = new SomeInterface () { public void interfacefunc() { System.out.println("Some message"); ; public class ButtonTester { public static void main(string[] args) { JFrame myframe = new JFrame(); final int F_WIDTH = 100; final int F_HEIGHT = 60; myframe.setsize(f_width, F_HEIGHT); myframe.settitle("button Tester"); myframe.setdefaultcloseoperation(jframe.exit_on_close); JButton button = new JButton("Click me!"); myframe.add(button); button.addactionlistener(new ActionListener() { public void actionperformed(actionevent event) { System.out.println("I was clicked."); ); myframe.setvisible(true);

import javax.swing.jframe; import javax.swing.jbutton; import java.awt.*; import java.awt.event.*; public class FrameViewer { public static void main (String[] args) { JFrame myframe = new JFrame(); // make a new JFrame object final int F_WIDTH = 300; // 300 pixels wide final int F_HEIGHT = 400; // 400 pixels high myframe.setsize(f_width, F_HEIGHT); myframe.settitle("my Frame"); // this is optional myframe.setdefaultcloseoperation(jframe.exit_on_close); myframe.setlayout( new FlowLayout() ); JButton mybutton = new JButton("Click me!"); myframe.add(mybutton); JButton mybutton2 = new JButton("Click me too!"); myframe.add(mybutton2); class ClickListener implements ActionListener { public void actionperformed(actionevent someevent) { System.out.println("I was clicked!"); class ClickListener2 implements ActionListener { public void actionperformed(actionevent someevent) {System.out.println("Don't you dare click me again!"); ClickListener mylistener = new ClickListener(); mybutton.addactionlistener(mylistener); ClickListener2 mylistener2 = new ClickListener2(); mybutton2.addactionlistener(mylistener2); myframe.setvisible(true);

class ClickListener2 implements ActionListener { public void actionperformed(actionevent someevent) { System.out.println("I was clicked!"); mybutton2.settext("ensmallened!"); myframe.settitle("smaller frame!"); int currh = myframe.getheight(); int currw = myframe.getwidth(); myframe.setsize(currw/2, currh/2); mybutton = new JButton("Make bigger!"); myframe.add(mybutton); ClickListener mylistener = new ClickListener(); mybutton.addactionlistener(mylistener); mybutton2 = new JButton("Make smaller!"); myframe.add(mybutton2); ClickListener2 mylistener2 = new ClickListener2(); mybutton2.addactionlistener(mylistener2); myframe.setvisible(true);

public class Border extends JFrame { public Border(String title) { super(title); Container cp = getcontentpane(); cp.setlayout(new BorderLayout()); cp.add(new JButton("Center"), BorderLayout.CENTER); cp.add(new JButton("North"), BorderLayout.NORTH); cp.add(new JButton("South"), BorderLayout.SOUTH); cp.add(new JButton("East"), BorderLayout.EAST); cp.add(new JButton("West"), BorderLayout.WEST); pack(); setvisible(true);

JMenuBar menubar = new JMenuBar(); JMenu advisingmenu = new JMenu("Advising"); advisingmenu.setmnemonic(keyevent.vk_a); menubar.add(advisingmenu); JMenuItem apptmenuitem = new JMenuItem("Appointments"); apptmenuitem.setaccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_A,ActionEvent.CTRL_MASK)); advisingmenu.add(apptmenuitem);... JMenuItem specmenuitem = new JMenuItem("Special Requests"); specmenuitem.setaccelerator(...); specmenuitem.setenabled(false); advisingmenu.add(specmenuitem); myframe.setjmenubar(menubar);

JDialog JFrame JOptionPane JOptionPane.showMessageDialog( null, "You love CPSC 211", "Message", JOptionPane.INFORMATION_MESSAGE); int result = JOptionPane.showConfirmDialog( null, "Do you like Swing?", "Confirm", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); MouseAdapter MouseListener WindowAdapter WindowListener Code Example:

focusgained focuslost tab JList JTree JListJTreeJTable

public class ListDemo extends JPanel implements ListSelectionListener { private JList list; private DefaultListModel listmodel;... public ListDemo() { super(new BorderLayout()); listmodel = new DefaultListModel(); listmodel.addelement("jane Doe"); listmodel.addelement("john Smith"); listmodel.addelement("kathy Green"); //Create the list and put it in a scroll pane. list = new JList(listModel);

public class ListDemo extends JPanel implements ListSelectionListener { private JList list; private DefaultListModel listmodel;... public ListDemo() { super(new BorderLayout()); public class ListDemo extends JPanel implements ListSelectionListener { private JList list; private DefaultListModel listmodel;... public ListDemo() { super(new BorderLayout()); listmodel = new DefaultListModel(); listmodel.addelement("jane Doe"); listmodel.addelement("john Smith"); listmodel.addelement("kathy Green"); listmodel = new DefaultListModel(); listmodel.addelement("jane Doe"); listmodel.addelement("john Smith"); listmodel.addelement("kathy Green"); //Create the list and put it in a scroll pane. list = new JList(listModel); //Create the list and put it in a scroll pane. list = new JList(listModel); public class RadioTester { JFrame myframe; JRadioButton orangebutton; JRadioButton bluebutton; ButtonGroup group; JPanel panel; public void go(){ myframe = new JFrame(); final int F_WIDTH = 200; final int F_HEIGHT = 200; myframe.setsize(f_width, F_HEIGHT); myframe.settitle("radio Button Tester"); myframe.setdefaultcloseoperation(jfram e.exit_on_close); // continued -->

orangebutton = new JRadioButton("orange"); bluebutton = new JRadioButton("blue"); group = new ButtonGroup(); group.add(orangebutton); group.add(bluebutton); panel = new JPanel(); panel.add(orangebutton); panel.add(bluebutton); myframe.add(panel); myframe.setvisible(true); public static void main(string[] args) { RadioTester rt = new RadioTester(); rt.go(); orangebutton = new JRadioButton("orange"); bluebutton = new JRadioButton("blue"); group = new ButtonGroup(); group.add(orangebutton); group.add(bluebutton); panel = new JPanel(); panel.add(orangebutton); panel.add(bluebutton); myframe.add(panel); myframe.setvisible(true); public static void main(string[] args) { RadioTester rt = new RadioTester(); rt.go(); orangebutton = new JRadioButton("orange"); bluebutton = new JRadioButton("blue"); group = new ButtonGroup(); group.add(orangebutton); group.add(bluebutton); panel = new JPanel(); panel.add(orangebutton); panel.add(bluebutton); myframe.add(panel); myframe.setvisible(true); public static void main(string[] args) { RadioTester rt = new RadioTester(); rt.go(); orangebutton = new JRadioButton("orange"); bluebutton = new JRadioButton("blue"); group = new ButtonGroup(); group.add(orangebutton); group.add(bluebutton); panel = new JPanel(); panel.add(orangebutton); panel.add(bluebutton); myframe.add(panel); myframe.setvisible(true); public static void main(string[] args) { RadioTester rt = new RadioTester(); rt.go();

setbackground(color.orange)