Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Choices, Containers-Java Network Programming-Lecture Slides, Slides of Java Programming

This lecture is delivered by Prem Vikas at Jaypee Institute of Information Technology University for discussing following points of Java Network Programming: Layout, Managers, Grid, Constructors, Border, Layout, Null, Creating, Choices

Typology: Slides

2011/2012

Uploaded on 07/03/2012

aapti
aapti 🇮🇳

4.6

(28)

82 documents

1 / 28

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Java Programming
Day-04
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c

Partial preview of the text

Download Choices, Containers-Java Network Programming-Lecture Slides and more Slides Java Programming in PDF only on Docsity!

Java Programming

Day-

Outline

  • Few more GUI-Components

 Check Boxes  Radio Buttons  Choices

  • Containers

 Panel  Frame

  • More Layout Managers

 Grid Layout  Border Layout  Null Layout

  • GUI-Based Application Development

Radio Buttons

  • A special case of check box buttons

 The Checkbox are treated as radio button when using some button group

  • CheckBoxgroup

 Used for grouping the checkboxes  Constructors  CheckboxGroup()  Important methods  public Checkbox getSelectedCheckbox()  public void setSelectedCheckbox(Checkbox object)

  • Creating Radio buttons

 Create instance of a CheckboxGroup class  Create two or more check boxes using following constructor  public Checkbox(String label,boolean initialstate,CheckboxGroup)

radio buttons..

import java.awt.*;

import java.applet.*;

public class TestApplet extends Applet{

CheckboxGroup chgroup=new CheckboxGroup(); Checkbox chbox1=new Checkbox(“Left”,false,chgroup); Checkbox chbox2=new Checkbox(“Right”,false,chgroup);

public void init(){ add(chbox1) add(chbox2) } }

choices..

choices cont..

import java.awt.; import java.applet.;

public class TestApplet2 extends Applet{

Choice countries=new Choice();

public void init(){ countries.addItem(“Pakistan”); countries.addItem(“Iran”); countries.addItem(“China”); add(countries) } }

containers cont..

  • AWT Containers

 Panel  Frames  Dialog  ScrollPane

  • Extensions of Containers are also containers for example

 public class myApplet extends Applet{}  public class myFrame extends Fram{}

Panels

  • A panel usually have no GUI representation

 Can have different back ground color

  • It is used to organized components
  • Used on other containers so that more than one layouts can be used
  • Constructors

 Panel()  Panel( LayoutManager initialLayout )

  • Important Methods

 Refer to slide 9 Containers

  • Example: Multipanel Applet

multiple panels cont..

iImport java.awt.; import java.applet.;

public class Applet2 extends Applet {

Panel p1; Panel p2;

public Applet2(){

public void init() { p1=new Panel(); p2=new Panel(new GridLayout(3,2,5,5));

for(int a=1;a<6;a++) p1.add(new Button("Button"+a));

for(int a=6;a<12;a++) p2.add(new Button("Button"+a));

p1.setBackground(Color.red); p2.setBackground(Color.blue); add(p1); add(p2); }}

Frames

  • Well defined GUI
  • Enable you to create separate windows

 Can develop stand alone applications (no need of browser)  Allow development of may window applications  Can be displayed or hide dynamically (can use button to open a new frame)  Provides a rich set of cursors e.g. busy,resize,crosshair etc

  • Constructors

 public Frame()  public Frame(String frameTitle)

  • Important methods

 void resize(int height, int width)  void show()  void hide()  void dispose()  void setTitle(), String getTitle()  setCursot( )

Displaying and hiding a Farme

Frame example

Import java.wt.; import java.applet.;

public class FrameApplet extends Applet {

Frame f=new Frame("First Frame"); Button showFrame=new Button("Show Frame"); Button hideFrame=new Button("Hide Frame"); Button closeFrame=new Button("Close Frame");

public Applet2(){ }

public void init(){

f.setSize(300,300);

add(showFrame); add(hideFrame); add(closeFrame);

} //end of init method

public boolean action(Event e,Object obj){ String s;

//getting the label of the button clicked s=(String)obj;

if(s=="Show Frame") f.show();

if(s=="Hide Frame") f.hide();

if(s=="Close Frame") f.dispose();

return true;

} //end of action method

} // end of class

grid layout..

import java.awt.*l;

import java.applet.*;

public class Applet2 extends Applet {

public void init(){ GridLayout grid=new GridLayout(2,2,5,5); setLayout(grid);

for(int a=1;a<5;a++) add(new Button("Button"+a));

} //end of init method

} //end of class

grid layout

import java.awt.l; import java.applet.;

public class Applet2 extends Applet {

public void init(){ GridLayout grid=new GridLayout(2,2); setLayout(grid);

for(int a=1;a<5;a++) add(new Button("Button"+a));

grid.setVgap(5); grid.setHgap(5);

} //end of init method

} //end of class