Java Tutorial – Building GUIs Java with Added Swing Daniel Bryant

Slides:



Advertisements
Similar presentations
Introduction to Eclipse. Start Eclipse Click and then click Eclipse from the menu: Or open a shell and type eclipse after the prompt.
Advertisements

Things to mention public static void main(String [] args) –The starting point for a free-standing Java application (i.e. one not run from the DrJava interactions.
Case Study Lecture 4 UML Huma Ayub Department of Software Engineering
Using Eclipse. Getting Started There are three ways to create a Java project: 1:Select File > New > Project, 2 Select the arrow of the button in the upper.
XP New Perspectives on Microsoft Office Access 2003, Second Edition- Tutorial 2 1 Microsoft Office Access 2003 Tutorial 2 – Creating And Maintaining A.
CA 121 Intro to Programming Tariq Aziz and Kevin Jones GUI Programming in Visual Studio.NET Chapter 1 Tariq Aziz and Kevin Jones.
A Guide to Oracle9i1 Introduction To Forms Builder Chapter 5.
Introduction to Java Lab CS110A – Lab Section 004 Instructor: Duo Wei.
1 Lab Session-I (A and B) CS-120 Fall 2000 Using Windows Using An Editor Using Visual C++ Using Compiler Writing and Running Programs Lab-1 DUE Fri September.
Using Relational Databases and SQL Steven Emory Department of Computer Science California State University, Los Angeles Laboratory 1: Introduction to Relational.
Creating And Maintaining A Database. 2 Learn the guidelines for designing databases When designing a database, first try to think of all the fields of.
Compunet Corporation Programming with Visual Basic.NET GUI Week # 11 Tariq Ibn Aziz.
COMPREHENSIVE Windows Tutorial 2 Organizing Your Files.
COMPREHENSIVE Excel Tutorial 8 Developing an Excel Application.
1 CSC 221: Computer Programming I Fall 2004 Objects and classes: a first pass  software objects, classes, object-oriented design  BlueJ IDE, compilation.
From BlueJ to NetBeans SWC 2.semester.
Web Design Using HTML Codes. WHAT DO I NEED TO BEGIN DESIGNING A HOME PAGE? 1.YOU NEED A FOLDER (also called a DIRECTORY) You should set up a folder or.
Microsoft Office 2003 Illustrated Introductory with Programs, Files, and Folders Working.
LESSON 2 CREATING A JAVA APPLICATION JAVA PROGRAMMING Compiled By: Edwin O. Okech [Tutor, Amoud University]
The NetBeans IDE CSIS 3701: Advanced Object Oriented Programming.
Introduction to Graphical User Interfaces. Objectives * Students should understand what a procedural program is. * Students should understand what an.
JLabel, JTextField, JButton and JOptionPane
Defining a Website. Review…. Page Title −The text that will be displayed in the title bar of the browser window on a web page File Name −What you “call”
Intro to Java 2 By Geb Thomas Based on the Java TutorialJava Tutorial.
Simple Address Book Case Study Lecture 4 UML Huma Ayub Department of Software Engineering.
Applets Chapter 17.  Java’s big splash onto the scene came in the mid 90’s. The people at Sun Microsystems had managed to work java programs into Web.
Intro to GUIs (Graphical User Interfaces) Section 2.5Intro. to GUIs: a GUI Greeter Section 3.7Graphical/Internet Java: Einstein's Equation.
Chapter 3: Using GUI Objects and the Visual Studio IDE.
HTML Concepts and Techniques Fourth Edition Project 6 Using Frames in a Web Site.
1 Development Environments AUBG, COS dept Lecture Title: Dev Env: Eclipse (Extract from Syllabus) Reference:
Introduction to GUI in Java 1. Graphical User Interface Java is equipped with many powerful,easy to use GUI component such as input and output dialog.
© 2005 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. Data Structures for Java William H. Ford William R. Topp Appendix E The EZJava.
OOP (Java): Simple/ OOP (Java) Objectives – –give some simple examples of Java applications and one applet 2. Simple Java Programs Semester.
In the next step you will enter some data records into the table. This can be done easily using the ‘Data Browser’. The data browser can be accessed via.
XP New Perspectives on Microsoft Access 2002 Tutorial 21 Microsoft Access Tutorial 2 – Creating And Maintaining A Database.
XP New Perspectives on Microsoft Office Access 2003, Second Edition- Tutorial 2 1 Microsoft Office Access 2003 Tutorial 2 – Creating And Maintaining A.
How to Run a Java Program CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington 1.
Program Design and Coding
Microsoft Visual Basic 2012 CHAPTER THREE Program Design and Coding.
Microsoft Visual Basic 2010 CHAPTER THREE Program Design and Coding.
1 CSC111H Graphical User Interfaces (GUIs) Introduction GUIs in Java Understanding Events A Simple Application The Containment Hierarchy Layout Managers.
Unit 1: Java and Eclipse The Eclipse Development Environment.
Comments in Java. When you create a New Project in NetBeans, you'll notice that some text is greyed out, with lots of slashes and asterisks:
Programming Fundamentals 2: Simple/ F II Objectives – –give some simple examples of Java applications and one applet 2. Simple Java.
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
Creating Applets. What is an applet? What is an applet? A Java program that runs in a web browser. A Java program that runs in a web browser. An applet.
”Java and JMLfor Dummies” The Java source code is written in a text file using your favourite editor (Notepad) and is saved with extension.java. Be careful.
Using Frames in a Web Site Project 6. Project Objectives Project 6: Using Frames in a Web Site 2 Define terms related to frames Describe the steps used.
Eclipse Project. Installing Visit to download a copy for your home computerhttp:// –Get Release version 3.0 (or.
Computer Science I Programming in Java (programming using Processing IN Java, using IntelliJ IDE) Classwork/Homework: copy your Processing projects over.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 2 – Welcome Application Introduction to Graphical.
Windows XP Lab 2 Organizing Your Work Competencies.
Sadegh Aliakbary Sharif University of Technology Fall 2011.
®® Microsoft Windows 7 Windows Tutorial 2 Organizing Your Files.
1NetBeans Tutorial Using the “Properties” menu, name the List “List1” and the button “Button1”. NetBeans Tutorial6.
Java With NetBeans First Project. Java Are language for this semester is Java The Development Environment is Netbeans.
Programming with Microsoft Visual Basic 2012 Chapter 14: Access Databases and SQL.
McGraw-Hill/Irwin The Interactive Computing Series © 2002 The McGraw-Hill Companies, Inc. All rights reserved. Microsoft Excel 2002 Using Macros Lesson.
A Quick Java Swing Tutorial
Excel Tutorial 8 Developing an Excel Application
Presenter Mindy Pistol Ext
How to Run a Java Program
Java Tutorial – Application Building
How to Run a Java Program
Advanced Programming in Java
Constructors, GUI’s(Using Swing) and ActionListner
Java Tutorial – Application Building
Developing Java Applications with NetBeans
Developing Java Applications with NetBeans
Presentation transcript:

Java Tutorial – Building GUIs Java with Added Swing Daniel Bryant

Get the files Create a directory on your home drive called JavaTutorial Visit my website and download today’s files into the new directory. *Right click each file and select “Save as”  These files will be used as a reference only. Accordingly, the files should be opened in Notepad and the contents cut and paste into NetBeans when necessary (i.e. do not mount the new directory or files within NetBeans)

Mounting the File System Create a directory named “GuiTutorial” in you home directory. Please note the case of the letters and the absence of spaces – Java can be very picky with file names!! Mount the empty “GuiTutorial” directory in NetBeans  File >> Mount Filesystem Create a package called “samplegui”  Right-click on newly mounted directory  New >> Java Package N.B. A package is essentially a unique named collection of classes and allows you to import (or use) other peoples code easily.

Packaging your classes We have created a package here to keep all of our classes grouped together The package name also refers to the directory structure in which your java files will be stored i.e. creating a package named samplegui will create a directory named samplegui in your GuiTutorial directory Please be careful with the case of letters. In addition package names must not contain spaces or you will get strange errors!

Compiling the Files Create a “Main Class”  Right-click on newly created package  New >> Java Main Class  Call this class “MyMain” The “Main Class” will be the entry point into your Java application and accordingly it will contain an important method that is executed whenever you run your class  public static void main(String[] args) We will use this class to instantiate our other objects and determine the flow of execution within the application, or in other words, utilise our other classes

Compiling the Files Create a Java Class  Right-click on samplegui package  New >> Java Class  Call this class “MainFrame” (Note case) Cut and paste the code from the first file you downloaded over any existing code that NetBeans has generated for you in the MainFrame class. It is essential that you delete any automatically generated code in this file only or your application will not compile Click on the “Build” pull down menu and select “Compile”  If all goes well you will see a message informing you the MainFrame.java class was compiled successfully

Compiling the Files Add appropriate code to the MyMain class to instantiate a MainFrame object and make it visible on the screen Public static void main (String[ ] args) { MainFrame frame = new MainFrame("Window Title"); frame.setVisible(true); } Run the code by clicking on the green triangle on the menu (the play button) You should see a window on the screen (quite a simple window and perhaps boring, but a GUI nonetheless!)

Compiling the Files Have a look at the code (and the comments I’ve provided) Look at and compile the other files you have downloaded  With the second file (MainFrame2.java) I want you to modify the code to create another button that, when pressed, opens a dialog box Don’t forget when you modify the code in the MainFrame class to compile your changes  Build >> Compile (F9)

The Files MainFrame.java  An implementation of a very simple GUI. Have a look at the code and ask any questions MainFrame2.java  The same GUI with buttons and Event handlers to launch additional code  I want you to add an additional button yourself that displays a dialogue box on screen

The Files MainFrame3.java  I’ve added a JLabel to the GUI so you can include text in your GUI application MainFrame4.java  I’ve created a GUI with a Layout Manager to specify how buttons are set out on the screen  I’ve also included an example of how to use a JFileChooser to load a file into you application