JFrame & JLabel. By Iqtidar Ali

Similar documents
GUI and its COmponent Textfield, Button & Label. By Iqtidar Ali

JFrame In Swing, a JFrame is similar to a window in your operating system

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

Java, Swing, and Eclipse: The Calculator Lab.

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

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

Multiple Choice Questions: Identify the choice that best completes the statement or answers the question. (15 marks)

Dr. Hikmat A. M. AbdelJaber

SampleApp.java. Page 1

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

PIC 20A GUI with swing

14.2 Java s New Nimbus Look-and-Feel 551 Sample GUI: The SwingSet3 Demo Application As an example of a GUI, consider Fig. 14.1, which shows the SwingS

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

CSCI 201L Midterm Written Summer % of course grade

Introduction to the JAVA UI classes Advanced HCI IAT351

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

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

Graphics User Defined Forms, Part I

Introduction to Graphical Interface Programming in Java. Introduction to AWT and Swing

Lab 4. D0010E Object-Oriented Programming and Design. Today s lecture. GUI programming in

INTRODUCTION TO (GUIS)

Graphical User Interface

11/6/15. Objec&ves. RouleQe. Assign 8: Understanding Code. Assign 8: Bug. Assignment 8 Ques&ons? PROGRAMMING PARADIGMS

More about GUIs GEEN163

Give one example where you might wish to use a three dimensional array

JAVA NOTES GRAPHICAL USER INTERFACES

Systems Programming. Bachelor in Telecommunication Technology Engineering Bachelor in Communication System Engineering Carlos III University of Madrid

Window Interfaces Using Swing Objects

Dr. Hikmat A. M. AbdelJaber

CS 201 Advanced Object-Oriented Programming Lab 1 - Improving Your Image Due: Feb. 3/4, 11:30 PM

FirstSwingFrame.java Page 1 of 1

CS 251 Intermediate Programming GUIs: Components and Layout

Chapter 12 Advanced GUIs and Graphics

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

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

Final Examination Semester 2 / Year 2010

CSIS 10A Assignment 7 SOLUTIONS

RAIK 183H Examination 2 Solution. November 11, 2013

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

Introduction. Introduction

Java Swing Introduction

CSCI 201L Midterm Written SOLUTION Summer % of course grade

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

Building a GUI in Java with Swing. CITS1001 extension notes Rachel Cardell-Oliver

Lecture 9. Lecture

Midterm assessment - MAKEUP Fall 2010

PROGRAMMING DESIGN USING JAVA (ITT 303) Unit 7

G52PGP. Lecture oo3 Java (A real object oriented language)

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

CSC 1214: Object-Oriented Programming

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

AP CS Unit 11: Graphics and Events

Swing from A to Z Some Simple Components. Preface

H212 Introduction to Software Systems Honors

Window Interfaces Using Swing Objects

RAIK 183H Examination 2 Solution. November 10, 2014

Java Applet & its life Cycle. By Iqtidar Ali

Interfaces & Polymorphism part 2: Collections, Comparators, and More fun with Java graphics

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

SWING - GROUPLAYOUT CLASS

User interfaces and Swing

Hanley s Survival Guide for Visual Applications with NetBeans 2.0 Last Updated: 5/20/2015 TABLE OF CONTENTS

Java Swing. Recitation 11/(20,21)/2008. CS 180 Department of Computer Science, Purdue University

IT101. Graphical User Interface

MIT AITI Swing Event Model Lecture 17

Name CS/120 Sample Exam #1 -- Riley. a) Every program has syntax, which refers to the form of the code, and, which refers to the meaning of the code.

CSCI 201L Midterm Written SOLUTION Fall % of course grade

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

Topic 9: Swing. Swing is a BIG library Goal: cover basics give you concepts & tools for learning more

Topic 9: Swing. Why are we studying Swing? GUIs Up to now: line-by-line programs: computer displays text user types text. Outline. 1. Useful & fun!

Computer Science 210: Data Structures. Intro to Java Graphics

Chapter 12 GUI Basics

1.00 Lecture 14. Lecture Preview

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

Final Examination Semester 2 / Year 2011

Class 14: Introduction to the Swing Toolkit

ANSWER KEY Exam 2 Computer Programming 230 Dr. St. John Lehman College City University of New York Thursday, 5 November 2009

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

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

// autor igre Ivan Programerska sekcija package mine;

Answer on question #61311, Programming & Computer Science / Java

Theory Test 3A. University of Cape Town ~ Department of Computer Science. Computer Science 1016S ~ For Official Use

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

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

SINGLE EVENT HANDLING

CS211 GUI Dynamics. Announcements. Motivation/Overview. Example Revisted

Midterm Test II Object Oriented Programming in Java Computer Science, University of Windsor Fall 2014 Time 2 hours. Answer all questions

Graphical User Interfaces (GUIs)

Part I: Learn Common Graphics Components

JApplet. toy example extends. class Point { // public int x; public int y; } p Point 5.2. Point. Point p; p = new Point(); instance,

TTTK Program Design and Problem Solving Tutorial 3 (GUI & Event Handlings)

COMP Assignment #10 (Due: Monday, March 11:30pm)

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

Object-Oriented Software Engineering Re-exam, 2012 (Also Object-Oriented Analysis, Design and Programming, Re-exam, 2012)

Swing Programming Example Number 2

CSC 1051 Data Structures and Algorithms I. Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University

Programmierpraktikum

CSCI 201L Midterm Written Fall % of course grade

Section Basic graphics

Transcription:

JFrame & JLabel By Iqtidar Ali

JFrame & its Features JFrame is a window with border, title and buttons. The component added to frame are referred to as its contents & are managed by the content pane. To add a component to JFrame, we must use its contentpane and will add it to content Pane. When JFrame is set visible, an event dispatching thread is started. It can be moved, resized.

JFrame Location By default, JFrame is displayed in upper-left corner of screen. To display frame at specified location, You can use the setlocation(x,y) method in JFrame class. This method places the upper-left corner of a frame at location(x,y).

Steps for creating a JFrame Window Construct an object of the JFrame. Set the size of the Jframe. Set the title of the Jframe to appear in title bar. Set the default close operation. When the user clicks close button, the program stops running. Make the Jframe visible.

import java.awt.*; import javax.swing.*; public class test extends JFrame{ public test(){ settitle("my Window"); setlayout(new FlowLayout()); setsize(300, 200 ); // Set the frame size setdefaultcloseoperation(jframe.exit_on_close); setvisible( true); // Display the frame public static void main(string[] args) test obj=new test();

LABEL To include a control in a window, you must add it to the window To do this, you must first create an instance of the desired control Then add it to a window by calling add() The syntax is Label compobj=new label() add(compobj); Here, compobj is an instance of the control that you want to add.

Label The easiest control to use is a label A label is an object of type Label, and it contains a string, which it displays Labels are passive controls that do not support any interaction with the user Label defines the following constructors: -Label( ) :- create empty label Label(String):- create label with given string Label(String, int):- Label with string & alignment

import java.awt.*; import javax.swing.*; public class test extends JFrame{ public test(){ settitle("my Window"); Label lb=new Label("Hello window"); add(lb); setlayout(new FlowLayout()); setsize(300, 200 ); // Set the frame size setdefaultcloseoperation(jframe.exit_on_close); setvisible( true); // Display the frame public static void main(string[] args) test obj=new test();

import java.awt.*; import javax.swing.icon; import javax.swing.imageicon; import javax.swing.jframe; import javax.swing.jlabel; import javax.swing.swingconstants; public class LabelFrame extends JFrame private JLabel label1; public LabelFrame() super("testing Label"); setlayout(new FlowLayout()); label1=new JLabel("Label with text"); label1.settooltiptext("this is Label1"); add(label1); public static void main(string[] args) LabelFrame labelframe=new LabelFrame(); labelframe.setdefaultcloseoperation(jframe.exit_on_close); labelframe.setsize(260,180); labelframe.setvisible(true); }

import java.awt.*; import javax.swing.icon; import javax.swing.imageicon; import javax.swing.jframe; import javax.swing.jlabel; import javax.swing.swingconstants; public class LabelFrame extends JFrame private JLabel label2; public LabelFrame() super("testing Label"); setlayout(new FlowLayout()); Icon bug=new ImageIcon(getClass().getResource("bug1.png")); label2=new JLabel("Label with text and icon", bug, SwingConstants.LEFT); label2.settooltiptext("this is Label2"); add(label2); public static void main(string[] args) LabelFrame labelframe=new LabelFrame(); labelframe.setdefaultcloseoperation(jframe.exit_on_close); labelframe.setsize(260,180); labelframe.setvisible(true); }

import java.awt.*; import javax.swing.icon; import javax.swing.imageicon; import javax.swing.jframe; import javax.swing.jlabel; import javax.swing.swingconstants; public class LabelFrame extends JFrame { private JLabel label3; public LabelFrame() { super("testing Label"); setlayout(new FlowLayout()); Icon bug=new ImageIcon(getClass().getResource("bug1.png")); label3=new JLabel(); label3.settext("label with icon and text at the bottom"); label3.seticon(bug); label3.sethorizontaltextposition(swingconstants.center); label3.settooltiptext("this is label3"); add(label3); } public static void main(string[] args) { LabelFrame labelframe=new LabelFrame(); labelframe.setdefaultcloseoperation(jframe.exit_on_close); labelframe.setsize(260,180); labelframe.setvisible(true); } }

THE END