CBSE Guess > Papers > Important Questions > Class XI > 2012 > Informatics Practices By Ms. Lakshmi Pulikollu
CBSE CLASS XI
Chapter 4
Design a GUI desktop application in java to accept the name and favourite sport in two text fields and display an appropriate message including the name and favourite sport in a dialog box using the concat( ) method. The application must have an exit button to end the application and appropriate labels.
Code :
import javax.swing.JOptionPane;
private void MessageActionPerformed(java.awt.event.ActionEvent evt) {
String s1=tf1.getText();
String s2=tf2.getText();
String s3=s1.concat(" is a great ").concat(s2).concat(" palyer");
JOptionPane.showMessageDialog(null,s3); // TODO add your handling code here:
}
private void ExitActionPerformed(java.awt.event.ActionEvent evt) {
System.exit(0); // TODO add your handling code here:
}
Output :
(b) Design a GUI desktop application in java to accept age category using radio buttons and display an appropriate age based message in a text area on selection of a radio button. The application must have an exit button to end the application and appropriate labels.
Code :
private void rb1ItemStateChanged(java.awt.event.ItemEvent evt) {
if(rb1.isSelected()==true)
ta1.setText("You are MINOR \nYou CAN'T Vote in our Elections");
}
private void rb2ItemStateChanged(java.awt.event.ItemEvent evt) {
if(rb2.isSelected()==true)
ta1.setText("You are MAJOR \nYou CAN Vote in our Elections");
}
private void ExitActionPerformed(java.awt.event.ActionEvent evt) {
System.exit(0); // TODO add your handling code here:
}
Output :
(c) Design a GUI desktop application in java to accept weight in Kilograms in a text field and convert it into grams and milligrams on the click of two separate buttons. Display the result in a second text field. The application must have an exit button to end the application and appropriate labels.
Code :
private void GramsActionPerformed(java.awt.event.ActionEvent evt) {
double w=Double.parseDouble(tf1.getText());
double w1= w*1000; //1kg = 1000 grams
tf2.setText(""+w1); // TODO add your handling code here:
}
private void MilliActionPerformed(java.awt.event.ActionEvent evt) {
double w=Double.parseDouble(tf1.getText());
double w1= w*1000000; //1kg = 1000000 milli grams
tf2.setText(""+w1); // TODO add your handling code here:
}
private void ExitActionPerformed(java.awt.event.ActionEvent evt) {
System.exit(0); // TODO add your handling code here:
}
Output :
(d) Design a GUI desktop application in java to accept temperature in Celsius in a text field and display temperature in Fahrenheit in another text field on the click of a button. The application must have an exit button to end the application and appropriate labels.
Code :
private void ConvertActionPerformed(java.awt.event.ActionEvent evt) {
int c=Integer.parseInt(tf1.getText());
int f=(c*9/5)+32;
tf2.setText(""+f);
// Celsius to Fahrenheit (°C × 9/5) + 32 = °F , Fahrenheit to Celsius (°F - 32) x 5/9 = °C
// TODO add your handling code here:
}
private void ExitActionPerformed(java.awt.event.ActionEvent evt) {
System.exit(0); // TODO add your handling code here:
}
Output :
Submitted By Ms. Lakshmi Pulikollu
Email Id : [email protected] |