Lecture 17

287 views

Published on

Notes on core java

Published in: Technology, News & Politics
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
287
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
9
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Lecture 17

  1. 1. Core Java 1 Debasish Pratihari Setting Fonts Example : import java.awt.*; class FontDemo extends Frame{ Label label; Font font; FontDemo(){ super("FontDemo By Debasish Pratihari"); label= new Label("Welcome to Lakshya"); setLayout(new FlowLayout()); // Font Setting for Output-2 font=new Font("Arial",Font.BOLD,20); // Font Setting for Output-3 //font=new Font("Arial",Font.BOLD+Font.ITALIC,30); label.setFont(font); add(label); pack(); setVisible(true); } public static void main(String args[]){ new FontDemo(); } } Output 1: Output 2: Output 3: Lecture/core/awt5/17 Page #1 feel the Technology…
  2. 2. Core Java Debasish Pratihari Setting Cursors for Components Example import java.awt.*; class CursorDemo extends Frame{ Button button; Cursor cursor; CursorDemo(){ super("FontDemo By Debasish Pratihari"); button= new Button("Click Me"); setLayout(new FlowLayout()); cursor= new Cursor(Cursor.HAND_CURSOR); button.setCursor(cursor); add(button); pack(); setVisible(true); } public static void main(String args[]){ new CursorDemo(); } } ToolKit Object :  This object represents the environment on your computer so it encapsulate all the properties and capabilities of that environment , including screen size and resolution.  To Obtain toolkit object: o o ToolKit toolkit = ToolKit.getDefaultToolKit(); Frame f= new Frame(); ToolKit toolkit=f.getToolKit(); Lecture/core/awt5/17 Page #2 feel the Technology…
  3. 3. Core Java Debasish Pratihari GraphicsEnvironment:  This object contains information about graphics device attached to the system.  the To Obtain GraphicsEnvironment Object : GraphicsEnvironment graphics= GraphicsEnvironment.getLocalGraphicsEnvironment(); Steps to create Menu :          create a Menu Bar create required Menus create Menu Items for all the menus make the Menu items event sensitive provide the event handlers for Menu items add the menu items into the corresponding Menus. add menus to the menu bar or incase of sub-menu add the menu to the corresponding main-menu. add the menu bar to the container Example of Menu: Lecture/core/awt5/17 Page #3 feel the Technology…
  4. 4. Core Java Debasish Pratihari Code Example : import java.awt.*; import java.awt.event.*; public class MenuDemo extends Frame{ Label label; MenuBar mb; Menu col,ft,fname,style; MenuItem red,green,blue,font1,font2,font3; MenuShortcut ms; Font font; CheckboxMenuItem style1,style2,style3; public MenuDemo(){ label=new Label("Welcome to Lakshya"); mb = new MenuBar(); col = new Menu("Color"); add(label); ms=new MenuShortcut(KeyEvent.VK_R); red=new MenuItem("Red",ms); green=new MenuItem("Green",new MenuShortcut(KeyEvent.VK_R,true)); blue=new MenuItem("Blue"); col.add(red); col.add(green); col.add(blue); ft = new Menu("Font"); fname= new Menu("Name"); font1=new MenuItem("Arial"); font2=new MenuItem("Verdana"); font3=new MenuItem("Garamond"); style= new Menu("Style"); style1= new CheckboxMenuItem("Bold"); style2= new CheckboxMenuItem("Italic"); style3= new CheckboxMenuItem("Underline"); fname.add(font1); fname.add(font2); fname.add(font3); style.add(style1); style.add(style2); style.add(style3); ft.add(fname); ft.add(style); mb.add(col); mb.add(ft); add(back); setMenuBar(mb); setTitle("MenuDemo By Debasish Pratihari"); setSize(300,200); setVisible(true); } public static void main(String args[]){ new MenuDemo(); } } Lecture/core/awt5/17 Page #4 feel the Technology…

×