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

Building visual basic application
Building visual basic applicationBuilding visual basic application
Building visual basic application
Sara Corpuz
 

What's hot (20)

Lecture 1 introduction to vb.net
Lecture 1   introduction to vb.netLecture 1   introduction to vb.net
Lecture 1 introduction to vb.net
 
Android Layout.pptx
Android Layout.pptxAndroid Layout.pptx
Android Layout.pptx
 
Scientific Calculator.pptx
Scientific Calculator.pptxScientific Calculator.pptx
Scientific Calculator.pptx
 
Elements of Java Language
Elements of Java Language Elements of Java Language
Elements of Java Language
 
collection framework in java
collection framework in javacollection framework in java
collection framework in java
 
JAVA GUI PART I
JAVA GUI PART IJAVA GUI PART I
JAVA GUI PART I
 
JavaScript Lecture notes.pptx
JavaScript Lecture notes.pptxJavaScript Lecture notes.pptx
JavaScript Lecture notes.pptx
 
CLISP Lab Manual - Dr.J.VijiPriya
CLISP Lab Manual - Dr.J.VijiPriyaCLISP Lab Manual - Dr.J.VijiPriya
CLISP Lab Manual - Dr.J.VijiPriya
 
Javascript functions
Javascript functionsJavascript functions
Javascript functions
 
Java Applets
Java AppletsJava Applets
Java Applets
 
c++ lab manual
c++ lab manualc++ lab manual
c++ lab manual
 
Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)
 
C#.NET
C#.NETC#.NET
C#.NET
 
Java oops PPT
Java oops PPTJava oops PPT
Java oops PPT
 
Building visual basic application
Building visual basic applicationBuilding visual basic application
Building visual basic application
 
Introduction to Listview in Android
Introduction to Listview in AndroidIntroduction to Listview in Android
Introduction to Listview in Android
 
Javascript
JavascriptJavascript
Javascript
 
Graphical User Interface (Gui)
Graphical User Interface (Gui)Graphical User Interface (Gui)
Graphical User Interface (Gui)
 
Methods In C-Sharp (C#)
Methods In C-Sharp (C#)Methods In C-Sharp (C#)
Methods In C-Sharp (C#)
 
C# Loops
C# LoopsC# Loops
C# Loops
 

Similar to Creating a windowed program

Creating a frame within an applet
Creating a frame within an appletCreating a frame within an applet
Creating a frame within an applet
myrajendra
 
Event handling63
Event handling63Event handling63
Event handling63
myrajendra
 
Guice tutorial
Guice tutorialGuice tutorial
Guice tutorial
Anh Quân
 
The java swing_tutorial
The java swing_tutorialThe java swing_tutorial
The java swing_tutorial
sumitjoshi01
 

Similar to Creating a windowed 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 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