SlideShare a Scribd company logo
1 of 13
Creating a windowed program




  http://improvejava.blogspot.in/
                                    1
Objective

On completion of this period, you would be
able to know

• Creating a Windowed program




              http://improvejava.blogspot.in/
                                                2
Recap

In the previous class, you have leant
• The steps to create a Frame with in an Applet
• Relevant program




                http://improvejava.blogspot.in/
                                                  3
Creating a Windowed Program

• Creating applets is the most common use for
  Java’s AWT
• But, it is possible to create stand-alone AWT-
  based applications
• To do this
  – simply create an instance of the window or
    windows you need inside main( )
  – e.g. Create Frame window with in main()


                 http://improvejava.blogspot.in/   4
Example Program

// Create an AWT-based application.
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
// Create a frame window.
public class AppWindow extends Frame {
         String keymsg = "This is a test.";
         String mousemsg = "";
         int mouseX=30, mouseY=30;
         public AppWindow() {
                 addKeyListener(new MyKeyAdapter(this));
                 addMouseListener(new MyMouseAdapter(this));
                 addWindowListener(new MyWindowAdapter());
         }

                       http://improvejava.blogspot.in/         5
Example Program                               contd..

    public void paint(Graphics g) {
             g.drawString(keymsg, 10, 40);
             g.drawString(mousemsg, mouseX, mouseY);
    }
    // Create the window.
    public static void main(String args[]) {
             AppWindow appwin = new AppWindow();
             appwin.setSize(new Dimension(300, 200));
             appwin.setTitle("An AWT-Based Application");
             appwin.setVisible(true);
    }
}




                    http://improvejava.blogspot.in/             6
Example Program                             contd..

class MyKeyAdapter extends KeyAdapter {
       AppWindow appWindow;
       public MyKeyAdapter(AppWindow appWindow) {
               this.appWindow = appWindow;
       }
       public void keyTyped(KeyEvent ke) {
               appWindow.keymsg += ke.getKeyChar();
               appWindow.repaint();
       };
}




                 http://improvejava.blogspot.in/             7
Example Program                contd..
class MyMouseAdapter extends MouseAdapter {
       AppWindow appWindow;
       public MyMouseAdapter(AppWindow appWindow) {
               this.appWindow = appWindow;
       }
       public void mousePressed(MouseEvent me) {
               appWindow.mouseX = me.getX();
               appWindow.mouseY = me.getY();
               appWindow.mousemsg = "Mouse Down at " +
               appWindow.mouseX +
               ", " + appWindow.mouseY;
               appWindow.repaint();
       }
}
class MyWindowAdapter extends WindowAdapter {
       public void windowClosing(WindowEvent we) {
               System.exit(0);
       }
}                     http://improvejava.blogspot.in/    8
Example Program                            contd..

• Sample output from this program is shown here




           Fig. 67.1 Output of AppWindow program




                   http://improvejava.blogspot.in/             9
Example Program                           contd..


• When creating a windowed application, you will
  use main( ) to launch its top-level window
• After that, your program will function as a GUI-
  based application
   – not like the console-based programs used
     earlier




                  http://improvejava.blogspot.in/             10
Summary

• In this class we have seen

  – The creation of a windowed program
  – The relevant program




                 http://improvejava.blogspot.in/   11
Quiz

1. Can Window object be used as a standalone
    GI component?
   – Yes
   – No




                http://improvejava.blogspot.in/   12
Frequently Asked Questions

1.Write a program to create a AWT based
  standalone GUI program




                http://improvejava.blogspot.in/   13

More Related Content

What's hot

Java Basics for selenium
Java Basics for seleniumJava Basics for selenium
Java Basics for seleniumapoorvams
 
Oops concepts || Object Oriented Programming Concepts in Java
Oops concepts || Object Oriented Programming Concepts in JavaOops concepts || Object Oriented Programming Concepts in Java
Oops concepts || Object Oriented Programming Concepts in JavaMadishetty Prathibha
 
Event Handling in Java
Event Handling in JavaEvent Handling in Java
Event Handling in JavaAyesha Kanwal
 
Software testing methods, levels and types
Software testing methods, levels and typesSoftware testing methods, levels and types
Software testing methods, levels and typesConfiz
 
Automation Testing using Selenium
Automation Testing using SeleniumAutomation Testing using Selenium
Automation Testing using SeleniumNaresh Chintalcheru
 
JUnit- A Unit Testing Framework
JUnit- A Unit Testing FrameworkJUnit- A Unit Testing Framework
JUnit- A Unit Testing FrameworkOnkar Deshpande
 
Multithreading in java
Multithreading in javaMultithreading in java
Multithreading in javaArafat Hossan
 
JDBC: java DataBase connectivity
JDBC: java DataBase connectivityJDBC: java DataBase connectivity
JDBC: java DataBase connectivityTanmoy Barman
 
Software Testing
Software TestingSoftware Testing
Software TestingSengu Msc
 
SOFTWARE TESTING UNIT-4
SOFTWARE TESTING UNIT-4  SOFTWARE TESTING UNIT-4
SOFTWARE TESTING UNIT-4 Mohammad Faizan
 
Software testing.ppt
Software testing.pptSoftware testing.ppt
Software testing.pptKomal Garg
 
Test Automation Framework Designs
Test Automation Framework DesignsTest Automation Framework Designs
Test Automation Framework DesignsSauce Labs
 

What's hot (20)

Java Basics for selenium
Java Basics for seleniumJava Basics for selenium
Java Basics for selenium
 
Oops concepts || Object Oriented Programming Concepts in Java
Oops concepts || Object Oriented Programming Concepts in JavaOops concepts || Object Oriented Programming Concepts in Java
Oops concepts || Object Oriented Programming Concepts in Java
 
Event Handling in Java
Event Handling in JavaEvent Handling in Java
Event Handling in Java
 
Unit testing with JUnit
Unit testing with JUnitUnit testing with JUnit
Unit testing with JUnit
 
Software testing methods, levels and types
Software testing methods, levels and typesSoftware testing methods, levels and types
Software testing methods, levels and types
 
JUnit Presentation
JUnit PresentationJUnit Presentation
JUnit Presentation
 
Automation Testing using Selenium
Automation Testing using SeleniumAutomation Testing using Selenium
Automation Testing using Selenium
 
Java Programming
Java ProgrammingJava Programming
Java Programming
 
JUnit- A Unit Testing Framework
JUnit- A Unit Testing FrameworkJUnit- A Unit Testing Framework
JUnit- A Unit Testing Framework
 
Multithreading in java
Multithreading in javaMultithreading in java
Multithreading in java
 
JDBC: java DataBase connectivity
JDBC: java DataBase connectivityJDBC: java DataBase connectivity
JDBC: java DataBase connectivity
 
Software testing
Software testing Software testing
Software testing
 
Software Testing
Software TestingSoftware Testing
Software Testing
 
Manual testing
Manual testingManual testing
Manual testing
 
SOFTWARE TESTING
SOFTWARE TESTINGSOFTWARE TESTING
SOFTWARE TESTING
 
SOFTWARE TESTING UNIT-4
SOFTWARE TESTING UNIT-4  SOFTWARE TESTING UNIT-4
SOFTWARE TESTING UNIT-4
 
Software testing.ppt
Software testing.pptSoftware testing.ppt
Software testing.ppt
 
Testing soap UI
Testing soap UITesting soap UI
Testing soap UI
 
Software testing
Software testingSoftware testing
Software testing
 
Test Automation Framework Designs
Test Automation Framework DesignsTest Automation Framework Designs
Test Automation Framework Designs
 

Similar to Creating a Windowed Java Program

Creating a frame within an applet
Creating a frame within an appletCreating a frame within an applet
Creating a frame within an appletmyrajendra
 
Event handling63
Event handling63Event handling63
Event handling63myrajendra
 
Guice tutorial
Guice tutorialGuice tutorial
Guice tutorialAnh Quân
 
Java- GUI- Mazenet solution
Java- GUI- Mazenet solutionJava- GUI- Mazenet solution
Java- GUI- Mazenet solutionMazenetsolution
 
Visual Studio tool windows
Visual Studio tool windowsVisual Studio tool windows
Visual Studio tool windowsPVS-Studio
 
Single Sourcing RAP and RCP - Desktop and web clients from a single code base
Single Sourcing RAP and RCP - Desktop and web clients from a single code baseSingle Sourcing RAP and RCP - Desktop and web clients from a single code base
Single Sourcing RAP and RCP - Desktop and web clients from a single code baseRalf Sternberg
 
Wuff: Building Eclipse Applications and Plugins with Gradle
Wuff: Building Eclipse Applications and Plugins with GradleWuff: Building Eclipse Applications and Plugins with Gradle
Wuff: Building Eclipse Applications and Plugins with GradleAndrey Hihlovsky
 
The Ring programming language version 1.5.4 book - Part 71 of 185
The Ring programming language version 1.5.4 book - Part 71 of 185The Ring programming language version 1.5.4 book - Part 71 of 185
The Ring programming language version 1.5.4 book - Part 71 of 185Mahmoud Samir Fayed
 
Getting started with appium
Getting started with appiumGetting started with appium
Getting started with appiumPratik Patel
 
The java swing_tutorial
The java swing_tutorialThe java swing_tutorial
The java swing_tutorialsumitjoshi01
 
Google Web Toolkits
Google Web ToolkitsGoogle Web Toolkits
Google Web ToolkitsYiguang Hu
 
Java Intro: Unit1. Hello World
Java Intro: Unit1. Hello WorldJava Intro: Unit1. Hello World
Java Intro: Unit1. Hello WorldYakov Fain
 

Similar to Creating a Windowed Java Program (20)

Creating a frame within an applet
Creating a frame within an appletCreating a frame within an applet
Creating a frame within an applet
 
Event handling63
Event handling63Event handling63
Event handling63
 
Rcp by example
Rcp by exampleRcp by example
Rcp by example
 
Google GIN
Google GINGoogle GIN
Google GIN
 
Guice tutorial
Guice tutorialGuice tutorial
Guice tutorial
 
Lightning Talk - Xamarin
Lightning Talk - Xamarin Lightning Talk - Xamarin
Lightning Talk - Xamarin
 
Java- GUI- Mazenet solution
Java- GUI- Mazenet solutionJava- GUI- Mazenet solution
Java- GUI- Mazenet solution
 
Visage fx
Visage fxVisage fx
Visage fx
 
Visual Studio tool windows
Visual Studio tool windowsVisual Studio tool windows
Visual Studio tool windows
 
Android programming-basics
Android programming-basicsAndroid programming-basics
Android programming-basics
 
Single Sourcing RAP and RCP - Desktop and web clients from a single code base
Single Sourcing RAP and RCP - Desktop and web clients from a single code baseSingle Sourcing RAP and RCP - Desktop and web clients from a single code base
Single Sourcing RAP and RCP - Desktop and web clients from a single code base
 
pebble - Building apps on pebble
pebble - Building apps on pebblepebble - Building apps on pebble
pebble - Building apps on pebble
 
Wuff: Building Eclipse Applications and Plugins with Gradle
Wuff: Building Eclipse Applications and Plugins with GradleWuff: Building Eclipse Applications and Plugins with Gradle
Wuff: Building Eclipse Applications and Plugins with Gradle
 
The Ring programming language version 1.5.4 book - Part 71 of 185
The Ring programming language version 1.5.4 book - Part 71 of 185The Ring programming language version 1.5.4 book - Part 71 of 185
The Ring programming language version 1.5.4 book - Part 71 of 185
 
Getting started with appium
Getting started with appiumGetting started with appium
Getting started with appium
 
The java swing_tutorial
The java swing_tutorialThe java swing_tutorial
The java swing_tutorial
 
The java rogramming swing _tutorial for beinners(java programming language)
The java rogramming swing _tutorial for beinners(java programming language)The java rogramming swing _tutorial for beinners(java programming language)
The java rogramming swing _tutorial for beinners(java programming language)
 
Google Web Toolkits
Google Web ToolkitsGoogle Web Toolkits
Google Web Toolkits
 
Java Intro: Unit1. Hello World
Java Intro: Unit1. Hello WorldJava Intro: Unit1. Hello World
Java Intro: Unit1. Hello World
 
PhoneGap
PhoneGapPhoneGap
PhoneGap
 

More from myrajendra (20)

Fundamentals
FundamentalsFundamentals
Fundamentals
 
Data type
Data typeData type
Data type
 
Hibernate example1
Hibernate example1Hibernate example1
Hibernate example1
 
Jdbc workflow
Jdbc workflowJdbc workflow
Jdbc workflow
 
2 jdbc drivers
2 jdbc drivers2 jdbc drivers
2 jdbc drivers
 
3 jdbc api
3 jdbc api3 jdbc api
3 jdbc api
 
4 jdbc step1
4 jdbc step14 jdbc step1
4 jdbc step1
 
Dao example
Dao exampleDao example
Dao example
 
Sessionex1
Sessionex1Sessionex1
Sessionex1
 
Internal
InternalInternal
Internal
 
3. elements
3. elements3. elements
3. elements
 
2. attributes
2. attributes2. attributes
2. attributes
 
1 introduction to html
1 introduction to html1 introduction to html
1 introduction to html
 
Headings
HeadingsHeadings
Headings
 
Forms
FormsForms
Forms
 
Css
CssCss
Css
 
Views
ViewsViews
Views
 
Views
ViewsViews
Views
 
Views
ViewsViews
Views
 
Starting jdbc
Starting jdbcStarting jdbc
Starting jdbc
 

Creating a Windowed Java Program

  • 1. Creating a windowed program http://improvejava.blogspot.in/ 1
  • 2. Objective On completion of this period, you would be able to know • Creating a Windowed program http://improvejava.blogspot.in/ 2
  • 3. Recap In the previous class, you have leant • The steps to create a Frame with in an Applet • Relevant program http://improvejava.blogspot.in/ 3
  • 4. Creating a Windowed Program • Creating applets is the most common use for Java’s AWT • But, it is possible to create stand-alone AWT- based applications • To do this – simply create an instance of the window or windows you need inside main( ) – e.g. Create Frame window with in main() http://improvejava.blogspot.in/ 4
  • 5. Example Program // Create an AWT-based application. import java.awt.*; import java.awt.event.*; import java.applet.*; // Create a frame window. public class AppWindow extends Frame { String keymsg = "This is a test."; String mousemsg = ""; int mouseX=30, mouseY=30; public AppWindow() { addKeyListener(new MyKeyAdapter(this)); addMouseListener(new MyMouseAdapter(this)); addWindowListener(new MyWindowAdapter()); } http://improvejava.blogspot.in/ 5
  • 6. Example Program contd.. public void paint(Graphics g) { g.drawString(keymsg, 10, 40); g.drawString(mousemsg, mouseX, mouseY); } // Create the window. public static void main(String args[]) { AppWindow appwin = new AppWindow(); appwin.setSize(new Dimension(300, 200)); appwin.setTitle("An AWT-Based Application"); appwin.setVisible(true); } } http://improvejava.blogspot.in/ 6
  • 7. Example Program contd.. class MyKeyAdapter extends KeyAdapter { AppWindow appWindow; public MyKeyAdapter(AppWindow appWindow) { this.appWindow = appWindow; } public void keyTyped(KeyEvent ke) { appWindow.keymsg += ke.getKeyChar(); appWindow.repaint(); }; } http://improvejava.blogspot.in/ 7
  • 8. Example Program contd.. class MyMouseAdapter extends MouseAdapter { AppWindow appWindow; public MyMouseAdapter(AppWindow appWindow) { this.appWindow = appWindow; } public void mousePressed(MouseEvent me) { appWindow.mouseX = me.getX(); appWindow.mouseY = me.getY(); appWindow.mousemsg = "Mouse Down at " + appWindow.mouseX + ", " + appWindow.mouseY; appWindow.repaint(); } } class MyWindowAdapter extends WindowAdapter { public void windowClosing(WindowEvent we) { System.exit(0); } } http://improvejava.blogspot.in/ 8
  • 9. Example Program contd.. • Sample output from this program is shown here Fig. 67.1 Output of AppWindow program http://improvejava.blogspot.in/ 9
  • 10. Example Program contd.. • When creating a windowed application, you will use main( ) to launch its top-level window • After that, your program will function as a GUI- based application – not like the console-based programs used earlier http://improvejava.blogspot.in/ 10
  • 11. Summary • In this class we have seen – The creation of a windowed program – The relevant program http://improvejava.blogspot.in/ 11
  • 12. Quiz 1. Can Window object be used as a standalone GI component? – Yes – No http://improvejava.blogspot.in/ 12
  • 13. Frequently Asked Questions 1.Write a program to create a AWT based standalone GUI program http://improvejava.blogspot.in/ 13