Programming Task: Task 1 Controlled Assessment Practice.

Slides:



Advertisements
Similar presentations
1 Applets Programming Enabling Application Delivery Via the Web.
Advertisements

Java Applets:. How Applets differ from application?: They do not use main method but init(), start() and paint() methods of the applet class They can.
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.
Programming and Problem Solving With Java Copyright 1999, James M. Slack Applets What is an Applet? Applet Parameters Graphics in Applets Other Applet.
CS 178: Programming with Multimedia Objects Aditya P. Mathur Professor of Computer Sciences Purdue University, West Lafayette Sept 9, 2004 Last update:
Event Handling Events and Listeners Timers and Animation.
Lecture 24 Applets. Introduction to Applets Applets should NOT have main method but rather init, stop, paint etc They should be run through javac compiler.
Java Programming, 3e Concepts and Techniques Chapter 3 Manipulating Data Using Methods.
1 Recitation 11. Applet Applets. An applet is a Java program that is started by a browser (e.g. netscape or internet explorer) when an html file has a.
CS3157 Java UI Recitation. Material Covered: Overview of AWT components, Event Handling, creating applets, and sample UI. Not covered in recitation: Drawing,
Chapter 3 - Introduction to Java Applets Outline 3.1Introduction 3.2Thinking About Objects 3.4A Simple Java Applet: Drawing a String 3.5Two More Simple.
Chapter 13: Advanced GUIs and Graphics J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
1 Class 8. 2 Chapter Objectives Use Swing components to build the GUI for a Swing program Implement an ActionListener to handle events Add interface components.
Graphical User Interfaces A Quick Outlook. Interface Many methods to create and “interface” with the user 2 most common interface methods: – Console –
Lesson 35: Review of the Java GUI. The JFrame, Container and JButton.
Io package as Java’s basic I/O system continue’d.
CSTP WS00CS423 (cotter)1 Java Applets Objective: Learn how to develop Java programs that interact with users through a Web browser.
Chapter 9: Applets Jim Burns Fall Outline Learn about applets Learn about applets Write an HTML doc to host an applet Write an HTML doc to host.
Java Programming, 2E Introductory Concepts and Techniques Chapter 3 Manipulating Data Using Methods.
Java Programming, 3e Concepts and Techniques Chapter 2 - Part 2 Creating a Java Application and Applet.
Introduction to Graphical User Interfaces. Objectives * Students should understand what a procedural program is. * Students should understand what an.
ThinkTank can help students… Create an outline of topics and subtopics to assist research. Narrow their research topic so it becomes more specific.
Java Programming, 3e Concepts and Techniques Chapter 3 Section 65 – Manipulating Data Using Methods – Java Applet.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 12 Advanced GUIs and Graphics.
Java Programming: From Problem Analysis to Program Design, Second Edition1  Learn about basic GUI components.  Explore how the GUI components JFrame,
Applets and Frames CS 21a: Introduction to Computing I First Semester,
Java Applet Presented by Fitsum Okubu. Introduction Introduction Graphics Graphics Methods and Variables Methods and Variables Events Events Decision.
Java GUI’s are event driven, meaning they generate events when the user interacts with the program. Typical events are moving the mouse, clicking a mouse.
CSE 501N Fall ‘09 20: Event Handling and Inner Classes 17 November 2009 Nick Leidenfrost.
Graphics in Java Starring: NetBeans Co-Starring: Java.awt.
Ch 3-4: GUI Basics Java Software Solutions Foundations of Program Design Sixth Edition by Lewis & Loftus Coming up: GUI Components.
Graphic User Interface. Graphic User Interface (GUI) Most of us interact with computers using GUIs. GUIs are visual representations of the actions you.
FEN IntroJava2006 AAU1 GUI: Graphical User Interface AWT/SWING: Components Drag and Drop in NetBeans Events Listeners.
Graphics and Event-Driven Programming in Java John C. Ramirez Department of Computer Science University of Pittsburgh.
Swing GUI Components You can create graphics components to place on your applet using classes available in the Swing package ( javax.swing ) Class names.
MT311 Java Application Development and Programming Languages Li Tak Sing ( 李德成 )
Concurrent Programming and Threads Threads Blocking a User Interface.
Lec 16 Adding Mouse and KeyEvent handlers to an Applet Class.
Java Classes, Objects, and Events: A Preview JavaMethods An Introduction to Object-Oriented Programming Maria Litvin Gary Litvin Copyright © 2003 by Maria.
Java Applets: GUI Components, Events, Etc. Ralph Westfall June, 2010.
Applets and Frames. Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved L14: GUI Slide 2 Applets Usually.
Graphical User Interface You will be used to using programs that have a graphical user interface (GUI). So far you have been writing programs that have.
Java Applet Basics (2). The Body Mass Index Calculator.
Introduction to GUI in 1 Graphical User Interface 2 Nouf Almunyif.
Java Programming: From Problem Analysis to Program Design, 3e Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
Applets. Internet/WWW How does it work? Internet/WWW.
Week101 APCS-AB: Java Miscellaneous Topics: Snippets we missed in Chapters 1-6 of book November 11, 2005.
Applets Java code is compiled into byte code instead of machine language –Languages like C, C++, Pascal and others are compiled into machine language so.
Compiling and running Java programs with BlueJ. Successfully compiled files program files in BlueJ You can tell from the shade of a program icon in BlueJ.
Sadegh Aliakbary Sharif University of Technology Fall 2011.
1NetBeans Tutorial Using the “Properties” menu, name the List “List1” and the button “Button1”. NetBeans Tutorial6.
Chapter 10 - Writing Graphical User Interfaces1 Chapter 10 Writing Graphical User Interfaces.
Swing GUI Components So far, we have written GUI applications which can ‘ draw ’. These applications are simple, yet typical of all Java GUI applications.
Lesson 28: More on the GUI button, frame and actions.
Event Handling CS 21a: Introduction to Computing I First Semester,
Agenda For Feb PowerPoint Presentation on Java Methods. 3. Finish Happy Face Assignment (Due by the.
Applets. 9/04/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved L12: Applets Slide 2 Applets Usually.
1 Applets Programming. Introduction Java programs are divided into two main categories, applets and applications. An application is an ordinary Java program.
Introducing, the JFrame Gives us a work area beside System.out.println.
Prepared by: Dr. Abdallah Mohamed, AOU-KW Unit7: Event-driven programming 1.
CompSci 230 S Programming Techniques
Customizing the Quick Access Toolbar in Microsoft Office
Lecture 09 Applets.
Ellen Walker Hiram College
Event Handling CS 21a: Introduction to Computing I
Constructors, GUI’s(Using Swing) and ActionListner
Chapter 5 Processing Input with Applets
Basic Lessons 5 & 6 Mr. Kalmes.
Enabling Application Delivery Via the Web
APPLET PROGRAMMING.
Presentation transcript:

Programming Task: Task 1 Controlled Assessment Practice

1.In NetBeans, create a new project by going to "File > New Project." In the "Choose Project" window, click "Java Application" and click "Next." Name the project “ControlledAssessment" and click "Finish.“ 2.Under "Source Packages" double-click the “controlledassessment" package (with the brown box icon) 3.Click "New > Java Class." Name the class “FirstApplet" and click "Finish” Creating An Applet

4.Under the line "package controlledassessment;" type the following two lines of Java code: import java.applet.*; import java.awt.*; This imports the Applet and Graphics Java libraries, which you will use in your code. 4.4 Between "public class FirstApplet" and the "{" type "extends Applet" to tell Java that the FirstApplet class is going to be an Applet. Creating An Applet * Le me wondering why my applet needs to go to the library * Le me finding out that library files are pre-written files of code that I can call inside my code!

1.Create the following methods to have your Java code initialize the Applet "paint" a line of text on the screen: public void paint (Graphics g) { g.drawstring (“Hello World”, 25, 50); } 2.Click "Run" from the top menu of NetBeans, then click "Run File." Your Java Applet's window will pop up and you will see your text on the screen. Creating An Applet

We know that we need a number between 0 and 255 for our binary game, but it needs to be random….. 1.Under the line "package controlledassessment;" type another line to import the Random library: import java.util.Random; 2.Inside the Paint() class, we create a new instance of a Random: Random myRand = new Random(); Generating Random Numbers

1.Next, we create an integer variable and give use myRand to generate a random number up to 255: int randomInt = myRand.nextInt(255); 2.Finally, we print this out to the applet screen: Generating Random Numbers g.drawString ("Random Number was:" + randomInt, 25, 60); * Le me realising that to draw a new line, I need to add 10 to the y axis of the draw() co-ordinates!

1.Firstly, we create two TextField variables private TextField input; private TextField output; 2.Then, we create a new method inside the applet: public void init() { } 3.Then we create an instance of a TextField on the applet screen: this.input = new TextField(10); this.output = new TextField(50); Entering Data We are going to create a new function within the applet where we will begin to create text boxes to allow the user to type in data.

4.Finally, we want to add these textboxes to the screen! this.add(input); this.add(output); 5.Click "Run" from the top menu of NetBeans, then click "Run File." Your Java Applet's window will pop up and you will see your text and the new text boxes on the screen. Entering Data

1.We first import the extra library classes needed for ‘listening’ for events. import java.awt.event.ActionEvent; import java.awt.event.ActionListener; 2.Then we implement the ActionListener in our main class so that we can run our button. And create an instance of a button. User Interaction Before your user can interact with the screen at all, the form will need a button to call the function. This is called an ‘on-click event’

1.Next we want to add the button to the applet in the same way that we did for the text boxes 2.Then link the button to the ActionListener. 3.Finally, we need to create a method called ‘actionPerformed’ which hears the button click and performs an action (like putting some text into a text box). 4.Now, run your file! User Interaction

Your finished code should look like this: Import library classes Instantiate (create) variables Initial function actionPerformed function listening for button click Function creating random numbers

1.Can you put the text from one box into another? 2.Can you put the random number into a text box? 3.Can you save a random number and add it to the next one? Extra Tasks