adding of two numbers in designing of frame

adding of two numbers in designing of frame

hello sir, now i'm create two textfield for mark1&mark2 from db.how to add these two numbers in another one text field.how to write a coding... if u have another one idea pls tell me........

View Answers

November 23, 2010 at 11:47 AM

Hi Friend,

Try the following code:

import java.awt.*;
import java.sql.*;
import javax.swing.*;
import java.awt.event.*;
class  SumOfNumbers{

    public static void main(String[] args){
    JFrame f=new JFrame();
    JLabel label1=new JLabel("First Number: ");
    JLabel label2=new JLabel("Second Number: ");
    JLabel label3=new JLabel("Result: ");
    final JTextField text1=new JTextField(20);
    final JTextField text2=new JTextField(20);
    final JTextField text3=new JTextField(20);
    JButton button=new JButton("Calculate");
    try{
           Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
           Connection con = DriverManager.getConnection("jdbc:odbc:student");
           Statement st=con.createStatement();
           ResultSet rs=st.executeQuery("select * from student where id=1");
           int mar1=0,mar2=0;
           if(rs.next()){
               mar1=rs.getInt("marks1");
               mar2=rs.getInt("marks2");
           }
           text1.setText(Integer.toString(mar1));
           text2.setText(Integer.toString(mar2));
           button.addActionListener(new ActionListener(){
               public void actionPerformed(ActionEvent e){
               int num1=Integer.parseInt(text1.getText());
               int num2=Integer.parseInt(text2.getText());
               int result=num1+num2;
               text3.setText(Integer.toString(result));
               }
            });
        }
        catch(Exception e){
        }
        JPanel p=new JPanel(new GridLayout(4,2));
        p.add(label1);
        p.add(text1);
        p.add(label2);
        p.add(text2);
        p.add(label3);
        p.add(text3);
        p.add(button);

        f.add(p);
        f.setVisible(true);
        f.pack();
    }
}

Thanks


November 27, 2012 at 5:07 PM

adding of two numbers in designing of frame package swings;

import java.awt.Container; import java.awt.FlowLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.IOException; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextField; import javax.swing.JTextPane;

public class Swings extends JFrame implements ActionListener {

JButton jb1;
JTextField jt3;
JButton jb2;
JLabel jl1;
JTextField jt1;
JLabel jl2;
JTextField jt2;
float c;

Swings() {

    jb1 = new JButton("Sum");
    jt3 = new JTextField(10);
    jb2 = new JButton("reset");
    jl1 = new JLabel("First number");
    jt1 = new JTextField(10);
    jl2 = new JLabel("Second number number");
    jt2 = new JTextField(10);
    Container con = getContentPane();
    JPanel jp = new JPanel(new FlowLayout(FlowLayout.LEFT));

    jp.add(jl1);
    jp.add(jt1);
    jp.add(jl2);
    jp.add(jt2);
    jp.add(jb1);
    jp.add(jt3);
    jp.add(jb2);

    con.add(jp);
    jb1.addActionListener(this);
    jb2.addActionListener(this);

}

public static void main(String[] args) throws IOException {
    Swings sw = new Swings();
    sw.setVisible(true);
    sw.setSize(250, 250);
    sw.setResizable(true);
    sw.setDefaultCloseOperation(EXIT_ON_CLOSE);

}

@Override
public void actionPerformed(ActionEvent e) {
    if (e.getSource() == jb1) {
        if ((jt1 != null && !"".equals(jt1)) && (jt2 != null && !"".equals(jt2))) {
            try {
                float a = Integer.parseInt(jt1.getText());
                float b = Integer.parseInt(jt1.getText());
                c = a + b;
                jt3.setText(Float.toString(c));
            } catch (NumberFormatException ae) {
                System.out.println("This is not a number");
                System.out.println(ae.getMessage());
            }
        }
    } else {
        jt1.setText("");
        jt2.setText("");
        jt3.setText("");
    }

}

}









Related Tutorials/Questions & Answers:
adding of two numbers in designing of frame
adding of two numbers in designing of frame  hello sir, now i'm create two textfield for mark1&mark2 from db.how to add these two numbers in another one text field.how to write a coding... if u have another one idea pls
Adding two numbers
Adding two numbers  Accepting value ffrom the keyboard and adding two numbers
Advertisements
adding two numbers - Java Beginners
adding two numbers  hii friends....... this is my program...]=Integer.parseInt(in.readLine()); int s=x[1]+y[1]; System.out.println("Sum of two...]; System.out.println("Sum of two no. is:"+s); } } For read more
adding two numbers using bitwise operators
adding two numbers using bitwise operators  adding two integer numbers with using bitwise opeators   Hi Friend, Try the following code...[] args) { System.out.println("Adding 5 and 6......"); int x=5,y=6; int xor
adding two numbers with out using any operator
adding two numbers with out using any operator  how to add two numbers with out using any operator   import java.math.*; class AddNumbers { public static void main(String[] args) { BigInteger num1=new
Addition of two numbers
Addition of two numbers  addition of two numbers
Listing all even numbers between two numbers
Listing all even numbers between two numbers  Hi, How to write code to list all the even numbers between two given numbers? Thanks   Hi... the numbers. Check the tutorial Write a program to list all even numbers between two
Applet for add two numbers
); add(text2); label3 = new Label("Sum of Two Numbers...Applet for add two numbers  what is the java applet code for add two numbers?   import java.awt.Graphics; import javax.swing.*; public
Add two big numbers
Add two big numbers       In this section, you will learn how to add two big numbers. For adding two numbers implement two big decimal numbers then apply the Sum() method
How to add two numbers in Java?
are going to define two numbers and then use the plus operator for adding two... How to add two numbers in a Java program? In Java you can easily add... numbers in Java it will return you int value as sum of two numbers. In real world
problem in adding a fullscreen frame nd adding a glass pane to it
problem in adding a fullscreen frame nd adding a glass pane to it  hi , here is my code import java.awt.*; import javax.swing.*; import java.awt.ToolKit; class MyFrame extends Jframe{ Container c; JPanel glass; MyFrame
Add two big numbers - Java Beginners
Add two big numbers - Java Beginners  Hi, I am beginner in Java and leaned basic concepts of Java. Now I am trying to find example code for adding big numbers in Java. I need basic Java Beginners example. It should easy
mysql difference between two numbers
mysql difference between two numbers  How to get total bate difference between two dates for example 1/01/2012 and 1/02/2012 in MYSQL?   ... between two date. The syntax of DATEDIFF is .. SELECT DATEDIFF('2012-01-31 23:59
To find first two maximum numbers in an array
To find first two maximum numbers in an array  Java program to find first two maximum numbers in an array,using single loop without sorting array
Generate random number between two numbers in Scala
Generate random number between two numbers in Scala  Hi, How to Generate random number between two numbers in Scala? Thanks   Hi, Following code can be used for generating random number in scala: val rand = new
Generate random number between two numbers in Scala
Generate random number between two numbers in Scala  Hi, How to Generate random number between two numbers in Scala? Thanks   Hi, Following code can be used for generating random number in scala: val rand = new
Comparing Two Numbers
Comparing Two Numbers      ... of comparing two numbers and finding out the greater one. First of all, name a class "Comparing" and take two numbers in this class. Here we have taken a=24
Write a program to list all even numbers between two numbers
Write a program to list all even numbers between two numbers       Java Even Numbers - Even... all the even numbers between two numbers. For this first create a class named
Swapping of two numbers
Swapping of two numbers      ... program to calculate swap of two numbers. Swapping is used where  you want... ability. In this program we will see how we can swap two numbers. We can do
Swapping of two numbers in java
Swapping of two numbers in java In this example we are going to describe swapping of two numbers in java  without using the third number in java. We... values from the command prompt. The swapping of two numbers is based on simple
Sum of two numbers using command line arguments in Java
Sum of two numbers using command line arguments in Java  Hi, How...? The calculate the sum of two numbers using command line arguments in Java... sum = a+b; Check complete example code at Add Two Numbers in Java. Thanks
Swapping of two numbers without using third variable
Swapping of two numbers without using third variable In this tutorial we will learn about swapping of two number in java without using third variable. This is simple program to swap two value using arithmetic operation Swapping of two
JavaScript determine add, product of two numbers
JavaScript determine add, product of two numbers In this section, you... numbers. To find this, we have created two textboxes and four button...("Sum of two numbers is: "+sum); } function divide
FRAME
FRAME  WHILE I'M RUNNINGFILE OF A GUI PROGRAMME(JDBC CONNECTION) INSTEAD OF OUTPUT FRAME ONLY TWO BLANK FRAMES ARE GETTING DISPLAYD... CAN ANYONE HELP ME TO SOLVE DS PROBLEM
FRAME
FRAME  WHILE I'M RUNNINGFILE OF A GUI PROGRAMME(JDBC CONNECTION) INSTEAD OF OUTPUT FRAME ONLY TWO BLANK FRAMES ARE GETTING DISPLAYD... CAN ANYONE HELP ME TO SOLVE DS PROBLEM
Add Two Numbers in Java
Add Two Numbers in Java     ... Addition of two numbers! Sum: 32... these arguments and print the addition of those numbers. In this example, args
To find first two maximum numbers in an array,using single loop without sorting array.
To find first two maximum numbers in an array,using single loop without sorting array.  Java program to find first two maximum numbers in an array,using single loop without sorting array
To find first two maximum numbers in an array,using single loop without sorting array.
To find first two maximum numbers in an array,using single loop without sorting array.  Java program to find first two maximum numbers in an array,using single loop without sorting array
Find L.C.M. of two numbers in Java
Find L.C.M. of two numbers in Java Program In this section, you will learn how to find LCM(Least Common Element) of two integers.The least common multiple is the smallest positive integer that is a multiple of both the numbers. Here we
frame
frame  how to creat a frame in java   Hi Friend, Try the following code:ADS_TO_REPLACE_1 import java.awt.*; import javax.swing.*; import java.awt.event.*; class RetrieveDataFromTextFields{ public static void
Swap two numbers without using third variable
Swap two numbers without using third variable In this section we are going to swap two variables without using the third variable. For this, we have used... arithmetic operations like we have added both the numbers and stored
Writing and testing method of addition of two numbers
we are going to test the functionality of adding two numbers. So we have created... Writing and testing method of addition of two numbers  ... a method named sum() which takes two int parameters and return addition of these two
frame update another frame.
frame update another frame.   How do I make a link or form in one frame update another frame
Add two number in java
Add two number in java In this section you will learn about how to add two number in java. In java adding two number,  first taking the input provided... be added, So two add,  convert these String into numeric type
Frame query
Frame query  Hi, I am working on Images in java. I have two JFrame displaying same image. We shall call it outerFrame and innerFrame.In innerFrame i am rotating the image.After all the rotations i need to display this image
frame generation
frame generation  Hi I wnat to genarate one frame with two tabs working ,production..and I want two radiobuttons sector ,others in the frames..based on the tab selection I want to clikc the radio button..when i ckick the radio
Midpoint of two number
important to find the number that is exactly between two numbers. In this example we are finding a midpoint of two numbers by using the while loop.   ...Midpoint of two number      
Designing an NXSD
Designing an NXSD  Hi, I am struggling to incorporate a logic to read the line 18 and 19. Test file looks something like this :- "00016"7"15/06/2015"08/06/2015"19/07/2015"Miss Claire Alvarez"P/2287"Mrs Helen Collins"NONE"22875
one frame update another frame
one frame update another frame  How do I make a link or form in one frame update another frame
panel and frame
panel and frame  What is the difference between panel and frame
Java Frame
Java Frame  What is the difference between a Window and a Frame
Database Designing
Database Designing       There are some rules are available for designing the database... the database in two or more tables and create the relationship between them. After isolate
Rational Numbers
Rational Numbers   Write and fully test a class that represents rational numbers. A rational number can be represented as the ratio of two integer... static method that returns the largest common factor of the two positive
adding view to viewcontroller
adding view to viewcontroller  How to add a frame window that opens on button click .. in iPhone application
billing frame
billing frame  how to generate billing frame using swing which contain sr. no, name of product, quantity, price & total
Adding an employee
Adding an employee  coding for adding an employee
Frame with JDBC - JDBC
Frame with JDBC   i am using frame having two textfield so how i retrieve the data from the ms-access there is two columns name and salary   Hi,Do you want to display the data on JSP Page?If yes then following tutorial
Create a Frame in Java
the size of the frame or window. This method takes two arguments width (int... Create a Frame in Java       Introduction This program shows you how to create a frame
adding a dialogue
adding a dialogue  Blockquote Hi can you help with the program below,the program is a loop that prints out a code and a quantity when prompt for the user input.what I need is to modify the code to incorporate a dialogue asking
adding loop
adding loop  Hi I have a program that is not compiling when I add a loop can you help me?The program below is compiling without the loop. > Blockquote mport java.util.*; import java.text.*; import java.util.Scanner

Ads