Category A Java
Category A Java
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 Dataframe() {
initComponents();
String name=t1.getText()+""+t2.getText()+""+t3.getText();
msg+="\n Gender";
if(r1.isSelected()==true)
msg+=r1.getText();
else
msg+=r2.getText();
Object obj[]=l1.getSelectedValues();
{
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);
new Dataframe().setVisible(true);
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 AgeFrame() {
initComponents();
String n= t1.getText();
int a= Integer.parseInt(t2.getText());
if(a>=18)
else
t1.setText("");
t2.setText("");
private javax.swing.JButton b;
private javax.swing.JLabel l;
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 ListboxD() {
initComponents();
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");
t.setText("Price is 130");
java.awt.EventQueue.invokeLater(new Runnable() {
new ListboxD().setVisible(true);
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 ComboBoxForm() {
initComponents();
c.addItem(t.getText());
t.setText("");
java.awt.EventQueue.invokeLater(new Runnable() {
new ComboBoxForm().setVisible(true);
});
private javax.swing.JButton b;
private javax.swing.JComboBox<String> c;
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;
double n1,n2;
void input()
Name: Chinmay Pradhan Roll No :269
{
n1=Double.parseDouble(t1.getText());
n2=Double.parseDouble(t2.getText());
public Radiof() {
initComponents();
input();
JOptionPane.showMessageDialog(this,"Addition of"+n1+"and"+n2+"is"+(n1+n2));
input();
JOptionPane.showMessageDialog(this,"Subtraction of"+n1+"and"+n2+"is"+(n1-n2));
input();
JOptionPane.showMessageDialog(this,"Multiplication of"+n1+"and"+n2+"is"+(n1*n2));
input();
JOptionPane.showMessageDialog(this,"Division of"+n1+"and"+n2+"is"+(n1/n2));
java.awt.EventQueue.invokeLater(new Runnable() {
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 ComboFrame() {
initComponents();
Object obj[]=l.getSelectedValues();
for(int i=0;i<obj.length;i++){
msg+=obj[i]+",";
JOptionPane.showMessageDialog(this,msg);
new ComboFrame().setVisible(true);
private javax.swing.JComboBox<String> c;
private javax.swing.JList<String> l;
OUTPUT