0% found this document useful (0 votes)
16 views2 pages

GiteshPractical 12 3, Java

Uploaded by

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

GiteshPractical 12 3, Java

Uploaded by

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

import javax.swing.

*;
import java.awt.event.*;

class GiteshPractical_12_3 extends JFrame {

JTextField number1TextField;
JTextField number2TextField;
JLabel resultLabel;

GiteshPractical_12_3()
{

initializeComponents();
}

void initializeComponents() {
JLabel number1Label = new JLabel("Number 1:");
number1Label.setBounds(10, 20, 80, 25);
add(number1Label);

number1TextField = new JTextField(20);


number1TextField.setBounds(100, 20, 165, 25);
add(number1TextField);

JLabel number2Label = new JLabel("Number 2:");


number2Label.setBounds(10, 50, 80, 25);
add(number2Label);

number2TextField = new JTextField(20);


number2TextField.setBounds(100, 50, 165, 25);
add(number2TextField);

JButton addButton = new JButton("Add");


addButton.setBounds(100, 80, 100, 25);
add(addButton);

resultLabel = new JLabel("Result: ");


resultLabel.setBounds(10, 110, 255, 25);
add(resultLabel);

addButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
try {
double number1 =
Double.parseDouble(number1TextField.getText());
double number2 =
Double.parseDouble(number2TextField.getText());
double result = number1 + number2;
resultLabel.setText("Result: " + result);
} catch (NumberFormatException ex) {
JOptionPane.showMessageDialog(GiteshPractical_12_3.this,
"Please enter valid numbers.",
"Input Error",
JOptionPane.ERROR_MESSAGE);
}
}
});
}
public static void main(String[] args)
{
GiteshPractical_12_3 g=new GiteshPractical_12_3();
g.setTitle("Password Frame");
g.setSize(500, 500);
g.setVisible(true);
g.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}

You might also like