




















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
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
1 / 28
This page cannot be seen from the preview
Don't miss anything!
Check Boxes Radio Buttons Choices
Panel Frame
Grid Layout Border Layout Null Layout
The Checkbox are treated as radio button when using some button group
Used for grouping the checkboxes Constructors CheckboxGroup() Important methods public Checkbox getSelectedCheckbox() public void setSelectedCheckbox(Checkbox object)
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..
Panel Frames Dialog ScrollPane
public class myApplet extends Applet{} public class myFrame extends Fram{}
Can have different back ground color
Panel() Panel( LayoutManager initialLayout )
Refer to slide 9 Containers
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); }}
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
public Frame() public Frame(String frameTitle)
void resize(int height, int width) void show() void hide() void dispose() void setTitle(), String getTitle() setCursot( )
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