Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners adding of two numbers in designing of frame

Have Programming Question? Ask it here!
 
 
 


shyamalagowri
adding of two numbers in designing of frame
2 Answer(s)      3 years and 9 months ago
Posted in : Java Beginners


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........


Advertisement
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
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
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
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
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
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
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 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
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     ... of two numbers! Sum: 32... these arguments and print the addition of those numbers. In this example, args
frame
frame  how to creat a frame in java   Hi Friend, Try the following code: import java.awt.*; import javax.swing.*; import java.awt.event.*; class RetrieveDataFromTextFields{ public static void main(String[] 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
Numbers
Java NotesNumbers Two kinds of numbers. There are basically two kinds of numbers in Java and most other programming languages: binary integers (most commonly using the type int) and binary floating-point numbers (most commonly using
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
to test the functionality of adding two numbers. So we have created our class named... Writing and testing method of addition of two numbers  ... a method named sum() which takes two int parameters and return addition of these two
Adding an employee
Adding an employee  coding for adding an employee
frame update another frame.
frame update another frame.   How do I make a link or form in one frame update another frame
adding view to viewcontroller
adding view to viewcontroller  How to add a frame window that opens on button click .. in iPhone application
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
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
one frame update another frame
one frame update another frame  How do I make a link or form in one frame update another 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
Java Frame
Java Frame  What is the difference between a Window and a Frame
panel and frame
panel and frame  What is the difference between panel and frame
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
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      
testcase for adding - JUNIT
testcase for adding  hi deepak...I am new to junit.can u send me a JUnit test case for adding or multiplying of two numbers.please i need it urgently
billing frame
billing frame  how to generate billing frame using swing which contain sr. no, name of product, quantity, price & total
Create a Frame in Java
of the frame or window. This method takes two arguments width (int), height (int... Create a Frame in Java       Introduction This program shows you how to create a frame
Adding a text file - Java Beginners
Adding a text file  Hello, I need a program that will search a text file of strings representing numbers of type int and will write the largest and the smallest numbers to the screen. The file contains nothing but strings
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
Creating a Frame
; Setting the Icon for a Frame    Showing a Dialog Box  ... a Multi line Label for a JButton Component    Adding an Icon to a JButton Component    Making a Frame Non-Resizable
Image on frame
Image on frame   Hi, This is my code. In this I am unable to load... java.awt.event.*; public class AwtImg extends Frame { Image img; public...(); } AwtImg() { super("Image Frame"); MediaTracker mt=new
Advertisements
 

 

 

DMCA.com