[go: up one dir, main page]

0% found this document useful (0 votes)
4 views1 page

Cs PDF

This document contains Java code for a simple GUI application that performs addition of two numbers. It creates a window with input fields for the first and second numbers, a result display, and buttons for adding the numbers, clearing the inputs, and exiting the application. The application uses Swing components and action listeners to handle user interactions.

Uploaded by

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

Cs PDF

This document contains Java code for a simple GUI application that performs addition of two numbers. It creates a window with input fields for the first and second numbers, a result display, and buttons for adding the numbers, clearing the inputs, and exiting the application. The application uses Swing components and action listeners to handle user interactions.

Uploaded by

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

GUI SIMPLE

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

public class Main {

public static void main(String[] args) {

JFrame obj = new JFrame("window");

obj.setSize(300, 400);

obj.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

obj.setLayout(new FlowLayout());

obj.setVisible(true);

JLabel fn=new JLabel("First Number");

JTextArea ft=new JTextArea(1,6);

JLabel sn=new JLabel("Second Number");

JTextArea st=new JTextArea(1,6);

JLabel rn=new JLabel("Result");

JTextArea rt=new JTextArea(1,6);

// rt.setEnabled(false);

JButton Add=new JButton("Add");

JButton clear=new JButton("Clear");

JButton Ex=new JButton("Exit");

Add.addActionListener(new AbstractAction() {

@Override public void actionPerformed(ActionEvent e) {

double f=Double.parseDouble(ft.getText());

double s=Double.parseDouble(st.getText());

double r=f+s;

rt.setText(String.valueOf(r)); } });

clear.addActionListener(new AbstractAction() {

@Override public void actionPerformed(ActionEvent e) {

ft.setText(" "); st.setText(" "); rt.setText(" ");

} });

Ex.addActionListener(new AbstractAction() {

@Override public void actionPerformed(ActionEvent e) { System.exit(0);

} });

obj.add(fn); obj.add(ft); obj.add(sn); obj.add(st); obj.add(rn); obj.add(rt); obj.add(Add); obj.add(clear); obj.add(Ex);

}}

You might also like