Name: Chinmay Pradhan Roll No :269
Category A- SWING
CatA1
Write a program to create a form to enter bio-data of student. Use various components such as JLabel, JButton,
JTextField, JTextArea, JComboBox, JOptionPane, JCheckbox.
Source Code:
package biodata;
import javax.swing.JOptionPane;
public class Dataframe extends javax.swing.JFrame {
public Dataframe() {
initComponents();
private void b1ActionPerformed(java.awt.event.ActionEvent evt) {
String name=t1.getText()+""+t2.getText()+""+t3.getText();
String msg="Thank you"+name;
msg+="\n Gender";
if(r1.isSelected()==true)
msg+=r1.getText();
else
msg+=r2.getText();
msg+="\n Address"+ta.getText()+"\n DOB"+t4.getText()+"\n Email:"+t5.getText()+"Contact number"+t6.getText();
msg+="\n Languages Known";
Object obj[]=l1.getSelectedValues();
for (int i=0;i<obj.length;i++)
{
Name: Chinmay Pradhan Roll No :269
msg+=obj[i]+",";
msg+="\n Hobbies:";
if(c1.isSelected())
msg+=c1.getText()+",";
if(c2.isSelected())
msg+=c2.getText()+",";
if(c3.isSelected())
msg+=c3.getText()+",";
if(c4.isSelected())
msg+=c4.getText()+",";
JOptionPane.showMessageDialog(this,msg);
public static void main(String args[]) {
public void run() {
new Dataframe().setVisible(true);
private javax.swing.JButton b1;
private javax.swing.JButton b2;
private javax.swing.ButtonGroup buttonGroup1;
private javax.swing.JCheckBox c1;
private javax.swing.JCheckBox c2;
private javax.swing.JCheckBox c3;
private javax.swing.JCheckBox c4;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel10;
private javax.swing.JLabel jLabel11;
private javax.swing.JLabel jLabel2;
Name: Chinmay Pradhan Roll No :269
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel7;
private javax.swing.JLabel jLabel8;
private javax.swing.JLabel jLabel9;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JList<String> l1;
private javax.swing.JRadioButton r1;
private javax.swing.JRadioButton r2;
private javax.swing.JTextField t1;
private javax.swing.JTextField t2;
private javax.swing.JTextField t3;
private javax.swing.JTextField t4;
private javax.swing.JTextField t5;
private javax.swing.JTextField t6;
private javax.swing.JTextField t7;
private javax.swing.JTextArea ta;
OUTPUT
Name: Chinmay Pradhan Roll No :269
Name: Chinmay Pradhan Roll No :269
CatA2.java
Write a Program which takes name and age from the user on click of the button and display a message on label,
user is eligible to vote or not.
Source Code:
package validity;
public class AgeFrame extends javax.swing.JFrame {
public AgeFrame() {
initComponents();
private void bActionPerformed(java.awt.event.ActionEvent evt) {
String n= t1.getText();
int a= Integer.parseInt(t2.getText());
if(a>=18)
l.setText(n+"You are Eligible for Voting");
else
l.setText(n+"You are not eligible for voting");
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
t1.setText("");
t2.setText("");
public static void main(String args[]) {
private javax.swing.JButton b;
private javax.swing.JButton jButton1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel l;
private javax.swing.JTextField t1;
private javax.swing.JTextField t2;
Name: Chinmay Pradhan Roll No :269
}
Output:
Cat A3
Name: Chinmay Pradhan Roll No :269
Write a Program that creates a list containing ice-cream flavours. On selecting of any flavour price should be
displayed in text field.
Source Code:
package javaapplication11;
public class ListboxD extends javax.swing.JFrame {
public ListboxD() {
initComponents();
private void lValueChanged(javax.swing.event.ListSelectionEvent evt) {
if(l.getSelectedValue().equalsIgnoreCase("Chocolate"))
t.setText("Price is 100");
else if(l.getSelectedValue().equalsIgnoreCase("Butterscotch"))
t.setText("Price is 90");
else if(l.getSelectedValue().equalsIgnoreCase("Vanila"))
t.setText("Price is 110");
else if(l.getSelectedValue().equalsIgnoreCase("Tender Coconut"))
t.setText("Price is 130");
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new ListboxD().setVisible(true);
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JList<String> l;
private javax.swing.JTextField t;
}
Name: Chinmay Pradhan Roll No :269
}
Output
CatA4
Name: Chinmay Pradhan Roll No :269
Write a program to create a comboBox, textfield and Button and on click of button the value of textfield should be
added to comboBox
Source Code:
package ComboBox;
public class ComboBoxForm extends javax.swing.JFrame {
public ComboBoxForm() {
initComponents();
private void bActionPerformed(java.awt.event.ActionEvent evt) {
c.addItem(t.getText());
t.setText("");
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new ComboBoxForm().setVisible(true);
});
private javax.swing.JButton b;
private javax.swing.JComboBox<String> c;
private javax.swing.JLabel jLabel1;
private javax.swing.JTextField t;
Output:
Name: Chinmay Pradhan Roll No :269
CatA5
Write a program to create two textfield and four radiobuttons (+,-,*,%) and on selecting the radiobutton, the
operation should be performed and result should be displayed in JOptionPane.
Source Code:
package radiobuttond;
import javax.swing.JOptionPane;
public class Radiof extends javax.swing.JFrame {
double n1,n2;
void input()
Name: Chinmay Pradhan Roll No :269
{
n1=Double.parseDouble(t1.getText());
n2=Double.parseDouble(t2.getText());
public Radiof() {
initComponents();
private void r1ActionPerformed(java.awt.event.ActionEvent evt) {
input();
JOptionPane.showMessageDialog(this,"Addition of"+n1+"and"+n2+"is"+(n1+n2));
private void r2ActionPerformed(java.awt.event.ActionEvent evt) {
input();
JOptionPane.showMessageDialog(this,"Subtraction of"+n1+"and"+n2+"is"+(n1-n2));
private void r3ActionPerformed(java.awt.event.ActionEvent evt) {
input();
JOptionPane.showMessageDialog(this,"Multiplication of"+n1+"and"+n2+"is"+(n1*n2));
private void r4ActionPerformed(java.awt.event.ActionEvent evt) {
input();
JOptionPane.showMessageDialog(this,"Division of"+n1+"and"+n2+"is"+(n1/n2));
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
Name: Chinmay Pradhan Roll No :269
new Radiof().setVisible(true);
private javax.swing.ButtonGroup bg;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JRadioButton r1;
private javax.swing.JRadioButton r2;
private javax.swing.JRadioButton r3;
private javax.swing.JRadioButton r4;
private javax.swing.JTextField t1;
private javax.swing.JTextField t2;
Output:
Name: Chinmay Pradhan Roll No :269
CatA6
Create an application where user can place order for pizza. Accept user-name, address, mobile Number fri=om user.
Give options for 4 types of pizza(basic,thick and chewy, thin and crispy, Chicago deep dish). Also proivide options for
multiple toppings(Pepperoni, sauseage, black olives and mushrooms).Confirm the order by displaying all details in a
JOptionPane.
Source Code:
package pizzademo;
import javax.swing.JOptionPane;
public class ComboFrame extends javax.swing.JFrame {
public ComboFrame() {
initComponents();
private void b1ActionPerformed(java.awt.event.ActionEvent evt) {
String msg="Name:"+t1.getText()+"\n Address:"+ta.getText()+"\n Contact Number:"+t2.getText()+"\n Pizza
Type:"+c.getSelectedItem()+"\n Toppins:";
Object obj[]=l.getSelectedValues();
for(int i=0;i<obj.length;i++){
msg+=obj[i]+",";
JOptionPane.showMessageDialog(this,msg);
public static void main(String args[]) {
public void run() {
new ComboFrame().setVisible(true);
private javax.swing.JButton b1;
private javax.swing.JComboBox<String> c;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
Name: Chinmay Pradhan Roll No :269
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JList<String> l;
private javax.swing.JTextField t1;
private javax.swing.JTextField t2;
private javax.swing.JTextArea ta;
OUTPUT