Exp 4
Exp 4
import java.awt.*;
import javax.swing.*;
public class Border1
{
JFrame jframe;
Border1()
{
jframe = new JFrame();
JButton btn2 = new JButton("DOWN");
JButton btn3 = new JButton("RIGHT");
JButton btn4 = new JButton("LEFT");
JButton btn5 = new JButton("TOP");
jframe.setLayout(new BorderLayout());
jframe.add(btn2, BorderLayout.SOUTH);
jframe.add(btn3, BorderLayout.EAST);
jframe.add(btn4, BorderLayout.WEST);
jframe.add(btn5, BorderLayout.NORTH);
jframe.setSize(300,300);
jframe.setVisible(true);
}
// main method
public static void main(String argvs[])
{
new Border1();
}
}
Output:
X.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class CardLayoutExample extends JFrame implements ActionListener {
CardLayout card;
JButton b1,b2,b3;
Container c;
CardLayoutExample(){
c = getContentPane();
card = new CardLayout(40,30);
c.setLayout(card);
b1 = new JButton("Apple");
b2 = new JButton("Boy");
b3 = new JButton("Cat");
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
}
Output:
XIII.
Q.1
import java.awt.Button;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import javax.swing.*;
public class GridBagLayoutExample1 extends JFrame{
public static void main(String[] args) {
GridBagLayoutExample1 a = new GridBagLayoutExample1();
}
public GridBagLayoutExample1() {
Q.2
import java.awt.Button;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.*;
import javax.swing.*;
public class GridBagLayoutExample2 extends JFrame{
public static void main(String[] args) {
GridBagLayoutExample2 a = new GridBagLayoutExample2();
}
public GridBagLayoutExample2() {
}
Output: