0% found this document useful (0 votes)
12 views

Advance Java Pratical 3

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)
12 views

Advance Java Pratical 3

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
You are on page 1/ 7

ADVANCE JAVA PRATICAL 3

PAGE NO 13 Q1
import java.awt.*;
import java.applet.*;

/* <applet code="College.class" 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 java.awt.*;
import java.applet.*;

/* <applet code="College.class" 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 java.awt.*;
public class College
{
public static void main( String args[] )
{
Frame f = new Frame();
f.setVisible(true);
f.setSize(400,400);
f.setLayout(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");

f.add(b1,BorderLayout.NORTH);
f.add(b2,BorderLayout.SOUTH);
f.add(b3,BorderLayout.EAST);
f.add(b4,BorderLayout.WEST);
f.add(b5,BorderLayout.CENTER);
}
}
PAGE 16 Q1

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

/* <applet code="College.class" 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 java.awt.*;
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) {
gc.gridx = x;
gc.gridy = y;
gc.gridwidth = w;
gc.gridheight = h;
gc.weightx = wx;
gc.weighty = wy;
gc.fill = GridBagConstraints.BOTH;
add(comp, gc);
}

public static void main(String args[]) {


College c = new College();
c.setTitle("GridBag Layout in Java Example");
c.setSize(300, 200);
c.setVisible(true);
}
}

Page 22 Q-1
import java.awt.Button;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import javax.swing.*;

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();


this.setLayout(layout);
gbc.fill = GridBagConstraints.HORIZONTAL;

gbc.gridx = 0;
gbc.gridy = 0;
this.add(new Button("Button One"), gbc);

gbc.gridx = 1;
gbc.gridy = 0;
this.add(new Button("Button Two"), gbc);

gbc.ipady = 20;

gbc.gridx = 0;
gbc.gridy = 1;
this.add(new Button("Button Three"), gbc);

gbc.gridx = 1;
gbc.gridy = 1;
this.add(new Button("Button Four"), gbc);

gbc.gridx = 0;
gbc.gridy = 2;
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.gridwidth = 2;
this.add(new Button("Button Five"), gbc);

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

You might also like