0% found this document useful (0 votes)
18 views20 pages

OOP

Uploaded by

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

OOP

Uploaded by

dasunnirmal887
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

1.

import javax.swing.*;

class Window extends JFrame {

Window(){
setTitle("My First Window");
setSize(300,300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
}
}

class Example {
public static void main(String args[]){
Window c1 = new Window();
c1.setVisible(true);
}
}

2.
import javax.swing.*;
import java.awt.*;
class Window extends JFrame {
private JButton btn1;
private JButton btn2;
private JButton btn3;
private JButton btn4;
private JButton btn5;

Window(){
setTitle("Bodar Layout Window");
setSize(300,300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);

btn1 = new JButton("North");


btn2 = new JButton("South");
btn3 = new JButton("East");
btn4 = new JButton("West");
btn5 = new JButton("Center");

add(btn1, BorderLayout.PAGE_START);
add(btn2, BorderLayout.PAGE_END);
add(btn3, BorderLayout.LINE_END);
add(btn4, BorderLayout.LINE_START);
add(btn5, BorderLayout.CENTER);
}
}

class Example {
public static void main(String args[]){
Window c1 = new Window();
c1.setVisible(true);
}
}

3.
import javax.swing.*;
import java.awt.*;
class Window extends JFrame {
private JLabel lbl1;
private JLabel lbl2;

Window(){
setTitle("Bodar Layout Window");
setSize(400,200);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);

initComponents();
}

public void initComponents(){


lbl1 = new JLabel("This is the North button");
lbl2 = new JLabel("This is the South button");
lbl1.setHorizontalAlignment(JLabel.CENTER);
lbl2.setHorizontalAlignment(JLabel.CENTER);

add(lbl1, BorderLayout.PAGE_START);
add(lbl2,BorderLayout.PAGE_END);

}
}

class Example {
public static void main(String args[]){
Window c1 = new Window();
c1.setVisible(true);
}
}

4.
import javax.swing.*;
import java.awt.*;
class Window extends JFrame {
private JLabel lbl1;
private JLabel lbl2;

Window(){
setTitle("Bodar Layout Window");
setSize(400,200);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);

initComponents();
}
public void initComponents(){
lbl1 = new JLabel("This is the North button");
lbl2 = new JLabel("This is the South button");
lbl1.setHorizontalAlignment(JLabel.CENTER);
lbl2.setHorizontalAlignment(JLabel.CENTER);

lbl1.setFont(new Font("Serif",1,20));
lbl2.setFont(new Font("Serif",1,20));

add(lbl1, BorderLayout.PAGE_START);
add(lbl2,BorderLayout.PAGE_END);

}
}

class Example {
public static void main(String args[]){
Window c1 = new Window();
c1.setVisible(true);
}
}

5.
import javax.swing.*;
import java.awt.*;
class Window extends JFrame {
private JButton btn1;
private JButton btn2;
private JButton btn3;
private JButton btn4;

Window(){
setTitle("flow Layout Window");
setSize(350,200);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
setLayout(new FlowLayout());

initComponents();
}

public void initComponents(){


btn1 = new JButton("Button 1");
btn2 = new JButton("This is a button");
btn3 = new JButton("Button 2");
btn4 = new JButton("Execute");

add(btn1);
add(btn2);
add(btn3);
add(btn4);

}
}
class Example {
public static void main(String args[]){
Window c1 = new Window();
c1.setVisible(true);
}
}

6.
import javax.swing.*;
import java.awt.*;
class Window extends JFrame {
private JButton btn1;
private JButton btn2;
private JButton btn3;
private JButton btn4;

Window(){
setTitle("flow Layout Window");
setSize(400,300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
setLayout(new FlowLayout(FlowLayout.LEADING));

initComponents();
}

public void initComponents(){


btn1 = new JButton("Button 1");
btn2 = new JButton("This is a button");
btn3 = new JButton("Button 2");
btn4 = new JButton("Execute");

add(btn1);
add(btn2);
add(btn3);
add(btn4);

}
}

class Example {
public static void main(String args[]){
Window c1 = new Window();
c1.setVisible(true);
}
}

7.
import javax.swing.*;
import java.awt.*;
class Window extends JFrame {
private JButton btn1;
private JButton btn2;
private JButton btn3;
private JButton btn4;

Window(){
setTitle("flow Layout Window");
setSize(400,300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
setLayout(new FlowLayout(FlowLayout.TRAILING));
initComponents();
}

public void initComponents(){


btn1 = new JButton("Button 1");
btn2 = new JButton("This is a button");
btn3 = new JButton("Button 2");
btn4 = new JButton("Execute");

add(btn1);
add(btn2);
add(btn3);
add(btn4);

}
}

class Example {
public static void main(String args[]){
Window c1 = new Window();
c1.setVisible(true);
}
}

8.
import javax.swing.*;
import java.awt.*;
class Window extends JFrame {
private JButton btn1;
private JButton btn2;
private JButton btn3;
private JButton btn4;

Window(){
setTitle("Grid Layout Window");
setSize(400,300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
setLayout(new GridLayout(2, 2));
initComponents();
}

public void initComponents(){


btn1 = new JButton("Button 1");
btn2 = new JButton("Button 2");
btn3 = new JButton("Button 3");
btn4 = new JButton("Button 4");
add(btn1);
add(btn2);
add(btn3);
add(btn4);

}
}

class Example {
public static void main(String args[]){
Window c1 = new Window();
c1.setVisible(true);
}
}

9.
import javax.swing.*;
import java.awt.*;

class Calculator extends JFrame {


private JButton[] btns;
private static final String[] btnNames = {"7", "8", "9", "*", "4", "5", "6", "/", "1", "2",
"3", "+", "0", ".", "=", "-"};
private JPanel btnPanel;

Calculator() {
setSize(300, 300);
setTitle("Calculator");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);

btnPanel = new JPanel(new GridLayout(4, 4, 5,5));

btns = new JButton[16];

for (int i = 0; i < btns.length; i++) {


btns[i] = new JButton(btnNames[i]);
}

for (int i = 0; i < btns.length; i++) {


btnPanel.add(btns[i]);
}

add(btnPanel, BorderLayout.CENTER);
}
}

class Example {
public static void main(String args[]){
Calculator c1 = new Calculator();
c1.setVisible(true);
}
}
10.
This code will not show any thing because it extends the JPanel instead of JFrame, Also the
JPanel need to be add to the JFrame to be displayed since there no JFrame and therefore this
code will not show any thing.

11.
import javax.swing.*;
import java.awt.*;
class Window extends JFrame {
private JPanel panel;
private JButton btn1;
private JButton btn2;
private JButton btn3;
private JButton btn4;
private JButton btn5;
private JButton btn6;
private JButton btn7;
private JButton btn8;

Window(){
setTitle("JPanel is a Container");
setSize(400,200);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);

initComponents();
}
public void initComponents() {
Panel panel = new Panel();

btn1 = new JButton("North");


btn2 = new JButton("South");
btn3 = new JButton("East");
btn4 = new JButton("West");
btn5 = new JButton("Button 1");
btn6 = new JButton("Button 2");
btn7 = new JButton("Button 3");
btn8 = new JButton("Button 4");

panel.setLayout(new GridLayout(2,2));

add(btn1, BorderLayout.PAGE_START);
add(btn2, BorderLayout.PAGE_END);
add(btn3, BorderLayout.LINE_END);
add(btn4, BorderLayout.LINE_START);
panel.add(btn5);
panel.add(btn6);
panel.add(btn7);
panel.add(btn8);
add(panel, BorderLayout.CENTER);

}
}
class Example {
public static void main(String args[]){
Window c1 = new Window();
c1.setVisible(true);
}
}

12.
The buttonPanel uses the FlowLayout layout manager, which arranges the buttons
horizontally, and the buttonPanel is inserted to the center of the frame using a BorderLayout,
which results in the mixing of layouts. When these two elements are combined, a layout
results in which the buttonPanel keeps its horizontal alignment inside the frame's center.

13.
import javax.swing.*;
import java.awt.*;

class Calculator extends JFrame {


private JButton[] btns;
private static final String[] btnNames = {"7", "8", "9", "*", "4", "5", "6", "/", "1", "2",
"3", "+", "0", ".", "=", "-"};
private JTextField txt1;

private JPanel displayPanel;


private JPanel btnPanel;

Calculator() {
setSize(300, 300);
setTitle("Calculator");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);

displayPanel = new JPanel(); //-> by default -> FlowLayout


btnPanel = new JPanel(new GridLayout(4, 4, 1,1));

txt1 = new JTextField(25);

displayPanel.add(txt1);

btns = new JButton[16];

for (int i = 0; i < btns.length; i++) {


btns[i] = new JButton(btnNames[i]);
}

for (int i = 0; i < btns.length; i++) {


btnPanel.add(btns[i]);
}

add(displayPanel, BorderLayout.PAGE_START);
add(btnPanel, BorderLayout.CENTER);
}
}
class Example {
public static void main(String args[]){
Calculator c1 = new Calculator();
c1.setVisible(true);
}
}

14.
import javax.swing.*;
import java.awt.*;

class Window extends JFrame {


private JPanel p1;
private JPanel txtPanel;
private JTextField txt1;

Window() {
setSize(400, 300);
setTitle("Demonstrate TextField");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);

initComponents();
}

public void initComponents() {


p1 = new JPanel(new GridLayout(1, 2));
txtPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));

txt1 = new JTextField(10);


txt1.setFont(new Font("Serif", Font.BOLD, 20));
txt1.setHorizontalAlignment(JTextField.RIGHT);
txtPanel.add(txt1);
p1.add(txtPanel);
add(p1);
}
}

class Example {
public static void main(String args[]){
Window w1 = new Window();
w1.setVisible(true);
}
}

15.
The layout of this code will be flowlayout.Because of the flowlayout manager and the order
in which the components are added,the GUI will have a simple horizontal arrangement of the
components from left to right.The first text field will be on the right side and the second text
field will be on the left side followed by the buttons.
16.
The out put will be a simple window with the border name "Demonstrate JLabel" and inside
of the window top left conor there is a label as "This is a JLabel".

17.

18.
import java.awt.*;
import javax.swing.*;

class Window extends JFrame{


private JPanel p1;
private JPanel p2;
private JPanel p3;
private JTextField txt1;
private JTextField txt2;
private JTextField txt3;
private JTextField txt4;
private JLabel lbl1;
private JLabel lbl2;
private JLabel lbl3;
private JLabel lbl4;
private JLabel lbl5;
private JButton btn1;
private JButton btn2;

Window(){
setSize(400,200);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setLocationRelativeTo(null);
setTitle("Student Detail Form");

initComponents();
}

public void initComponents(){


p1 = new JPanel();
p2 = new JPanel();
p3 = new JPanel();
p1.setLayout(new GridLayout(0,2,0,5));
p3.setLayout(new FlowLayout(FlowLayout.TRAILING));

txt1 = new JTextField(15);


txt2 = new JTextField(15);
txt3 = new JTextField(15);
txt4 = new JTextField(15);

lbl1 = new JLabel("Student id");


lbl2 = new JLabel("Name");
lbl3 = new JLabel("Address");
lbl4 = new JLabel("Phone No");
lbl5 = new JLabel("Student Details Form");
lbl5.setFont(new Font("Serif",1,20));
btn1 = new JButton("Add Student");
btn2 = new JButton("Cancel");

p1.add(lbl1);
p1.add(txt1);

p1.add(lbl2);
p1.add(txt2);

p1.add(lbl3);
p1.add(txt3);

p1.add(lbl4);
p1.add(txt4);

p2.add(lbl5);
p3.add(btn1);
p3.add(btn2);

add(p1);
add(p2,BorderLayout.PAGE_START);
add(p3,BorderLayout.PAGE_END);
}
}

class Example{
public static void main(String args[]){
new Window().setVisible(true);

}
}

19.
The output will be a simple frame with a JComboBox in the north part of the frame with four
options "RED,GREEN,BLACK,BLUE".

20.
import java.awt.*;
import javax.swing.*;

class Window extends JFrame{


private JPanel p1;
private JTextField txt1;
private JTextField txt2;
private JTextField txt3;
private JTextField txt4;
private JLabel lbl1;
private JLabel lbl2;
private JLabel lbl3;
private JLabel lbl4;

Window(){
setSize(300,200);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setLocationRelativeTo(null);
setTitle("Student Detail Form");

initComponents();
}

public void initComponents(){


p1 = new JPanel();
p1.setLayout(new GridLayout(0,2));

txt1 = new JTextField(12);


txt2 = new JTextField(12);
txt3 = new JTextField(12);
txt4 = new JTextField(12);

lbl1 = new JLabel("Student id");


lbl2 = new JLabel("Name");
lbl3 = new JLabel("Address");
lbl4 = new JLabel("Phone No");

p1.add(lbl1);
p1.add(txt1);

p1.add(lbl2);
p1.add(txt2);

p1.add(lbl3);
p1.add(txt3);

p1.add(lbl4);
p1.add(txt4);

add(p1);
}
}

class Example{
public static void main(String args[]){
new Window().setVisible(true);

}
}

21.
import java.awt.*;
import javax.swing.*;

class Window extends JFrame{


private JPanel p1;
private JPanel p2;
private JPanel p3;
private JTextField txt1;
private JTextField txt2;
private JTextField txt3;
private JTextField txt4;
private JLabel lbl1;
private JLabel lbl2;
private JLabel lbl3;
private JLabel lbl4;
private JLabel lbl5;
private JButton btn1;
private JButton btn2;

Window(){
setSize(400,300);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setLocationRelativeTo(null);
setTitle("Student Detail Form");

initComponents();
}

public void initComponents(){


p1 = new JPanel();
p2 = new JPanel();
p3 = new JPanel();
p1.setLayout(new GridLayout(0,2));
p3.setLayout(new FlowLayout(FlowLayout.TRAILING));

txt1 = new JTextField(12);


txt2 = new JTextField(12);
txt3 = new JTextField(12);
txt4 = new JTextField(12);

lbl1 = new JLabel("Student id");


lbl2 = new JLabel("Name");
lbl3 = new JLabel("Address");
lbl4 = new JLabel("Phone No");
lbl5 = new JLabel("Student Details From");

btn1 = new JButton("Add Student");


btn2 = new JButton("Cancel");

p1.add(lbl1);
p1.add(txt1);

p1.add(lbl2);
p1.add(txt2);

p1.add(lbl3);
p1.add(txt3);

p1.add(lbl4);
p1.add(txt4);

p2.add(lbl5);
p3.add(btn1);
p3.add(btn2);

add(p1);
add(p2,BorderLayout.PAGE_START);
add(p3,BorderLayout.PAGE_END);
}
}

class Example{
public static void main(String args[]){
new Window().setVisible(true);

}
}

22.
An toggle button is a graphical user interface component that represents a two-state switch,
with each click switching the status of the button between "selected" and "unselected." It is
often applied to indicate binary decisions, such as turning on or off a feature, turning
something on or off, or choosing between two options.

23.
import java.awt.*;
import javax.swing.*;

class Window extends JFrame{


private JPanel p1;
private JPanel p2;
private JPanel p3;
private JPanel genderPanel;
private JTextField txt1;
private JTextField txt2;
private JLabel lbl1;
private JLabel lbl2;
private JLabel lbl3;
private JLabel lbl4;
private JButton btn1;
private JButton btn2;
private JRadioButton j1;
private JRadioButton j2;

Window(){
setSize(400,200);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setLocationRelativeTo(null);

initComponents();
}

public void initComponents(){


p1 = new JPanel();
p2 = new JPanel();
p3 = new JPanel();
genderPanel = new JPanel();
j1 = new JRadioButton();
j2 = new JRadioButton();
p1.setLayout(new GridLayout(0,2));
p3.setLayout(new FlowLayout(FlowLayout.TRAILING));
txt1 = new JTextField(15);
txt2 = new JTextField(15);

lbl1 = new JLabel("Name");


lbl2 = new JLabel("Address");
lbl3 = new JLabel("Gender");
lbl4 = new JLabel("Student Details");
lbl4.setFont(new Font("Times New Roman", Font.PLAIN, 30));

j1.setText("Male");
j2.setText("Female");

btn1 = new JButton("Save");


btn2 = new JButton("Cancel");

genderPanel.add(j1);
genderPanel.add(j2);

p1.add(lbl1);
p1.add(txt1);

p1.add(lbl2);
p1.add(txt2);

p1.add(lbl3);
p1.add(genderPanel);

p2.add(lbl4);
p3.add(btn1);
p3.add(btn2);

add(p1);
add(p2,BorderLayout.PAGE_START);
add(p3,BorderLayout.PAGE_END);
}
}

class Example{
public static void main(String args[]){
new Window().setVisible(true);
}
}

24.
import java.awt.*;
import javax.swing.*;

class Window extends JFrame{


private JPanel p1;

Window(){
setSize(300,100);
setTitle("RadioButton Test");
setDefaultCloseOperation(EXIT_ON_CLOSE);
setLocationRelativeTo(null);

initComponents();
}

public void initComponents(){


p1 = new JPanel();
JCheckBox c1 = new JCheckBox("Plain");
JCheckBox c2 = new JCheckBox("Bolt");
JCheckBox c3 = new JCheckBox("Italic");
JCheckBox c4 = new JCheckBox("Bolt/Italic");

p1.add(c1);
p1.add(c2);
p1.add(c3);
p1.add(c4);

add(p1);
}
}

class Example{
public static void main(String args[]){
new Window().setVisible(true);

}
}

25.
import java.awt.*;
import javax.swing.*;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;

class Window extends JFrame implements ItemListener {


private JPanel p1;
private JPanel p2;
private JLabel lbl1;
private JLabel lbl2;
private JComboBox<String> c1;

Window() {
setSize(400, 200);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setLocationRelativeTo(null);

initComponents();
}

public void initComponents() {


p1 = new JPanel();
p2 = new JPanel();
lbl1 = new JLabel("ComboBox Demo");
lbl2 = new JLabel("Date");
lbl1.setFont(new Font("Times New Roman", Font.BOLD, 30));
p2.setLayout(new FlowLayout(FlowLayout.TRAILING));

String months[] = {"January", "February", "March", "April", "May", "June", "July",


"August",
"September", "October", "November", "December"};
c1 = new JComboBox<>(months);
c1.addItemListener(this); // Set the current instance (Window) as the item listener

p1.add(lbl1);
p2.add(lbl2);
p2.add(c1); // Add the combo box to the panel

add(p1, BorderLayout.PAGE_START);
add(p2, BorderLayout.LINE_START);
}

// Implement the itemStateChanged method of the ItemListener interface


public void itemStateChanged(ItemEvent e) {
if (e.getSource() == c1) {
String selectedMonth = (String) c1.getSelectedItem();
lbl2.setText("Date: " + selectedMonth); // Update the label text
}
}
}

class Example {
public static void main(String args[]) {
new Window().setVisible(true);
}
}

26.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

class Window extends JFrame {


private JPanel p1;
private JPanel p2;
private JSlider[] sliders;
private JLabel lbl;

Window() {
setSize(400, 300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
setLayout(new BorderLayout());

initComponents();
}

public void initComponents() {


p1 = new JPanel();
p1.setLayout(new FlowLayout());
lbl = new JLabel("Equalizer");
lbl.setFont(new Font("Times New Roman", Font.BOLD, 30));

p1.add(lbl);

p2 = new JPanel();
p2.setLayout(new GridLayout(1, 10));

sliders = new JSlider[10];


for (int i = 0; i < 10; i++) {
sliders[i] = new JSlider(JSlider.VERTICAL);
sliders[i].setPaintTicks(true);
sliders[i].setPaintLabels(true);
p2.add(sliders[i]);
}

add(p1, BorderLayout.NORTH);
add(p2, BorderLayout.CENTER);
}
}

class Example {
public static void main(String args[]) {
new Window().setVisible(true);
}
}

27.
28.
29.
30.

31.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

class Window extends JFrame {


private JSlider slider;

Window() {
setSize(300, 100);
setTitle("Slider Example");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);

setLayout(new FlowLayout());

initComponents();
}

public void initComponents() {

slider = new JSlider(JSlider.HORIZONTAL, 0, 50, 10);


slider.setMinorTickSpacing(2);
slider.setMajorTickSpacing(10);
slider.setPaintTicks(true);
slider.setPaintLabels(true);

add(slider);
}
}

class Example {
public static void main(String args[]){
new Window().setVisible(true);
}
}

32.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

class Window extends JFrame {


private JPanel p1;
private JPanel p2;
private JPanel p3;
private JLabel lbl1;
private JLabel lbl2;
private JLabel lbl3;
private JSlider slider1;
private JSlider slider2;
private JSlider slider3;

Window() {
setSize(350, 300);
setTitle("Slider Example");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);

setLayout(new FlowLayout());

initComponents();
}

public void initComponents() {


p1 = new JPanel();
p2 = new JPanel();
p3 = new JPanel();
p1.setLayout(new BoxLayout(p1, BoxLayout.Y_AXIS));
p2.setLayout(new BoxLayout(p2, BoxLayout.Y_AXIS));
p3.setLayout(new BoxLayout(p3, BoxLayout.Y_AXIS));

lbl1 = new JLabel("JSlider without Tick Marks");


slider1 = new JSlider(JSlider.HORIZONTAL);
slider1.setPaintTicks(true);
slider1.setPaintLabels(true);
lbl2 = new JLabel("JSlider with Tick Marks");
slider2 = new JSlider(JSlider.HORIZONTAL, 0, 50, 10);
slider2.setMinorTickSpacing(2);
slider2.setPaintTicks(true);
slider2.setPaintLabels(true);

lbl3 = new JLabel("JSlider with Tick & Labls");


slider3 = new JSlider(JSlider.HORIZONTAL, 0, 50, 10);
slider3.setMinorTickSpacing(2);
slider3.setMajorTickSpacing(10);
slider3.setPaintTicks(true);
slider3.setPaintLabels(true);

Dimension sliderDimension = new Dimension(200, 50);


slider1.setPreferredSize(sliderDimension);
slider2.setPreferredSize(sliderDimension);
slider3.setPreferredSize(sliderDimension);

p1.add(lbl1);
p1.add(slider1);

p2.add(lbl2);
p2.add(slider2);

p3.add(lbl3);
p3.add(slider3);

add(p1, BorderLayout.NORTH);
add(p2, BorderLayout.CENTER);
add(p3, BorderLayout.SOUTH);
}
}

class Example {
public static void main(String args[]) {
SwingUtilities.invokeLater(() -> {
new Window().setVisible(true);
});
}
}

You might also like