0% found this document useful (0 votes)
9 views7 pages

Java AWT Applet and Layout Examples

Uploaded by

vedant.walse41
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views7 pages

Java AWT Applet and Layout Examples

Uploaded by

vedant.walse41
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

ADVANCE JAVA PRATICAL 3

PAGE NO 13 Q1
import [Link].*;
import [Link].*;

/* <applet code="[Link]" width=300 height=300> </applet> */


public class College extends Applet {
public void init() {
setLayout(new GridLayout(5, 5));
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 5; j++) {
int k = i * 5 + j;
add(new Button("Button" + (k + 1)));
}
}
}

public void paint(Graphics g) {


// Optional: any custom painting code can go here
}
}
PAGE 13 Q2

import [Link].*;
import [Link].*;

/* <applet code="[Link]" width=300 height=300> </applet> */


public class College extends Applet {
public void init() {
setLayout(new GridLayout(2,5,10,10));
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 5; j++) {
int k = i * 5 + j;
if(k>=0){
add(new Button("Button" + k));
}
}
}
}

public void paint(Graphics g) {


// Optional: any custom painting code can go here
}
}

PAGE 16 Q2

import [Link].*;
public class College
{
public static void main( String args[] )
{
Frame f = new Frame();
[Link](true);
[Link](400,400);
[Link](new BorderLayout());

Button b1 = new Button("North");


Button b2 = new Button("South");
Button b3 = new Button("East");
Button b4 = new Button("West");
Button b5 = new Button("Center");

[Link](b1,[Link]);
[Link](b2,[Link]);
[Link](b3,[Link]);
[Link](b4,[Link]);
[Link](b5,[Link]);
}
}
PAGE 16 Q1

import [Link].*;
import [Link].*;

/* <applet code="[Link]" width=300 height=300> </applet> */


public class College extends Applet {
public void init() {
setLayout(new GridLayout(3,2,10,10));
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 2; j++) {
int k = i * 2 + j;
if(k>=0 && k<5){
add(new Button("Button" +( k+1)));
}
}
}
}
public void paint(Graphics g) {
// Optional: any custom painting code can go here
}
}

Pratical No 4

Page No 22 Q-2

import [Link].*;
public class College extends Frame {
College() {
Label l1 = new Label("Name");
TextField t1 = new TextField(10);
Label l2 = new Label("Comments");
TextArea t2 = new TextArea(6, 15);
Button b1 = new Button("Submit");
setLayout(new GridBagLayout());
GridBagConstraints gc = new GridBagConstraints();

addComponent(l1, gc, 0, 0, 1, 1, 0, 0);


addComponent(t1, gc, 1, 0, 1, 1, 0, 20);
addComponent(l2, gc, 0, 1, 1, 1, 0, 0);
addComponent(t2, gc, 1, 1, 1, 1, 0, 60);
addComponent(b1, gc, 0, 2, 2, 1, 0, 20);
}
void addComponent(Component comp, GridBagConstraints gc, int x, int y, int w, int
h, int wx, int wy) {
[Link] = x;
[Link] = y;
[Link] = w;
[Link] = h;
[Link] = wx;
[Link] = wy;
[Link] = [Link];
add(comp, gc);
}

public static void main(String args[]) {


College c = new College();
[Link]("GridBag Layout in Java Example");
[Link](300, 200);
[Link](true);
}
}

Page 22 Q-1
import [Link];
import [Link];
import [Link];
import [Link].*;

public class GridBagLayoutExample extends JFrame {


public static void main(String[] args) {
GridBagLayoutExample a = new GridBagLayoutExample();
}
public GridBagLayoutExample() {
GridBagLayout grid = new GridBagLayout();
GridBagConstraints gbc = new GridBagConstraints();
setLayout(grid);
setTitle("GridBag Layout Example");

GridBagLayout layout = new GridBagLayout();


[Link](layout);
[Link] = [Link];

[Link] = 0;
[Link] = 0;
[Link](new Button("Button One"), gbc);

[Link] = 1;
[Link] = 0;
[Link](new Button("Button Two"), gbc);

[Link] = 20;

[Link] = 0;
[Link] = 1;
[Link](new Button("Button Three"), gbc);

[Link] = 1;
[Link] = 1;
[Link](new Button("Button Four"), gbc);

[Link] = 0;
[Link] = 2;
[Link] = [Link];
[Link] = 2;
[Link](new Button("Button Five"), gbc);

setSize(300, 300);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
}

You might also like