0% found this document useful (0 votes)
56 views4 pages

Date: Practical No.: 01 Aim: Program:: BIT (7 CE-1) Advanced Java ENROLL. NO.: 080050131034

This document describes a Java program that develops a Swing application with different layouts and components. The program creates buttons to select different layouts (Flow, Border, Grid, Box), and adds components like buttons, text fields, radio buttons and labels to a panel using the selected layout. When a layout button is clicked, the panel is removed and re-added with the chosen layout applied.

Uploaded by

Neha Bhuptani
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
56 views4 pages

Date: Practical No.: 01 Aim: Program:: BIT (7 CE-1) Advanced Java ENROLL. NO.: 080050131034

This document describes a Java program that develops a Swing application with different layouts and components. The program creates buttons to select different layouts (Flow, Border, Grid, Box), and adds components like buttons, text fields, radio buttons and labels to a panel using the selected layout. When a layout button is clicked, the panel is removed and re-added with the chosen layout applied.

Uploaded by

Neha Bhuptani
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 4

BIT (7th CE-1) ENROLL. NO.

: 080050131034

ADVANCED JAVA

Date: PRACTICAL NO.: 01 AIM: Develop a swing application with different layouts and various Components. PROGRAM: import java.awt.*; import java.awt.event.*; import javax.swing.*; public class LayoutsDemo extends JFrame implements ActionListener{ JButton layoutbuttons[]=new JButton[4]; JButton button = new JButton("Button"); JTextField text = new JTextField("Text Field",20); JRadioButton radio1 = new JRadioButton("Radio Button 1",true); JRadioButton radio2 = new JRadioButton("Radio Button 2",false); JRadioButton radio3 = new JRadioButton("Radio Button 3",false); JComboBox combo = new JComboBox(); JLabel label=new JLabel("Label");

String layoutlabels[]={"Flow Layout","Border Layout","Grid Layout","Box Layout"}; String displaylabels[]={"North","South","East","West","Center"}; JPanel laypanel=new JPanel(),disppanel=new JPanel(),radiopanel=new JPanel(); Container c; public static void main(String[] args) { LayoutsDemo ld=new LayoutsDemo("Study different Layouts..."); ld.setVisible(true); ld.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } LayoutsDemo(String title){ setTitle(title); setSize(500,300); c=getContentPane(); c.setLayout(new BorderLayout());

Page no.:

BIT (7th CE-1) ENROLL. NO.: 080050131034

ADVANCED JAVA

laypanel.setLayout(new FlowLayout()); disppanel.setLayout(null); radiopanel.setLayout(new FlowLayout()); for(int i=0;i<layoutbuttons.length;i++){ layoutbuttons[i]=new JButton(layoutlabels[i]); layoutbuttons[i].addActionListener(this); laypanel.add(layoutbuttons[i]); } for(int i=0;i<displaylabels.length;i++){ combo.addItem(displaylabels[i]); } radiopanel.add(radio1); radiopanel.add(radio2); radiopanel.add(radio3); disppanel.add(button); disppanel.add(text); disppanel.add(radiopanel); disppanel.add(combo); disppanel.add(label); button.setBounds(225,20,80,30); text.setBounds(225,60,60,30); radiopanel.setBounds(20,100,500,30); combo.setBounds(225,140,60,30); label.setBounds(225,180,60,30); c.add(laypanel,"North"); c.add(disppanel,"Center"); } @Override public void actionPerformed(ActionEvent ae){ Object src=ae.getSource(); disppanel.removeAll(); c.remove(disppanel); if(src==layoutbuttons[0]){ disppanel.setLayout(new FlowLayout());

Page no.:

BIT (7th CE-1) ENROLL. NO.: 080050131034

ADVANCED JAVA

disppanel.add(button); disppanel.add(text); disppanel.add(radiopanel); disppanel.add(combo); disppanel.add(label); } if(src==layoutbuttons[1]){ disppanel.setLayout(new BorderLayout()); disppanel.add(button,"North"); disppanel.add(text,"South"); disppanel.add(radiopanel,"Center"); disppanel.add(combo,"West"); disppanel.add(label,"East"); } if(src==layoutbuttons[2]){ disppanel.setLayout(new GridLayout(3,2)); disppanel.add(button); disppanel.add(text); disppanel.add(radiopanel); disppanel.add(combo); disppanel.add(label); } if(src==layoutbuttons[3]){ disppanel.setLayout(new BoxLayout(disppanel,BoxLayout.Y_AXIS)); disppanel.add(button); disppanel.add(text); disppanel.add(radiopanel); disppanel.add(combo); disppanel.add(label); } c.add(disppanel,"Center"); this.setVisible(true); } }

Page no.:

BIT (7th CE-1) ENROLL. NO.: 080050131034

ADVANCED JAVA

OUTPUT:

Page no.:

You might also like