Home Tutorialhelp Comment Main program

 
 

Comment

Avishek Bhattacharyya
Main program,
January 13, 2010 at 7:26 AM

Pls give me the program for the calculator.also pls point out if I could import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
class Calculator implements ActionListener
{
Frame f;
JButton b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,b15;
Panel p;
TextField tf1;
GridLayout gl;
Calculator()
{
f=new Frame("Calculator");
p=new Panel();
b1=new JButton("0");
b1.addActionListener(this);
b2=new JButton("1");
b2.addActionListener(this);
b3=new JButton("2");
b3.addActionListener(this);
b4=new JButton("3");
b4.addActionListener(this);
b5=new JButton("4");
b5.addActionListener(this);
b6=new JButton("5");
b6.addActionListener(this);
b7=new JButton("6");
b7.addActionListener(this);
b8=new JButton("7");
b8.addActionListener(this);
b9=new JButton("8");
b9.addActionListener(this);
b10=new JButton("9");
b10.addActionListener(this);
b11=new JButton("+");
b11.addActionListener(this);
b12=new JButton("-");
b12.addActionListener(this);
b13=new JButton("x");
b13.addActionListener(this);
b14=new JButton("/");
b14.addActionListener(this);
tf1=new TextField(20);
p.add(tf1);
tf1.setBackground(Color.yellow);
gl=new GridLayout(4,4,10,20);
p.setLayout(gl);
p.add(b1);p.add(b2);p.add(b3);p.add(b4);p.add(b5);p.add(b6);p.add(b7);p.add(b8);p.add(b9);p.add(b10);p.add(b11);p.add(b12);p.add(b13);p.add(b14);

f.add(p);
f.setSize(100,200);
f.setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==b1)
{
String s1=b1.getText();
tf1.setText(s1);
}
if(e.getSource()==b2)
{
String s1=b2.getText();
tf1.setText(s1);
}
if(e.getSource()==b3)
{
String s1=b3.getText();
tf1.setText(s1);
}
if(e.getSource()==b4)
{
String s1=b4.getText();
tf1.setText(s1);
}
if(e.getSource()==b5)
{
String s1=b5.getText();
tf1.setText(s1);
}
if(e.getSource()==b6)
{
String s1=b6.getText();
tf1.setText(s1);
}
if(e.getSource()==b7)
{
String s7=b7.getText();
tf1.setText(s1);
}
if(e.getSource()==b8)
{
String s1=b8.getText();
tf1.setText(s1);
}
if(e.getSource()==b9)
{
String s1=b9.getText();
tf1.setText(s1);
}
if(e.getSource()==b10)
{
String s1=b10.getText();
tf1.setText(s1);
}
if(e.getSource()==b11)
{
String s1=b11.getText();
tf1.setText(s1);
}
if(e.getSource()==b12)
{
String s1=b1.getText();
tf1.setText(s1);
}
if(e.getSource()==b13)
{
String s1=b13.getText();
tf1.setText(s1);
}

if(e.getSource()==b14)
{
String s1=b14.getText();
tf1.setText(s1);
}
}
public static void main(String args[])
{
Calculator c=new Calculator();
}
} this program work.
View All Comments | View Tutorial
Advertisement
Related Tutorial and Articles
Java Beginners

java main program
java main program  how to write a main program for the following code public class JaroWinkler { private String compOne; private String compTwo; private String theMatchA = ""; private String theMatchB 

Java Beginners

MAin error
MAin error  Error while running hello program in another dir rather in bin. path is already set. java -version jdk1.6.0_24 no error while compilation but @ d tym of runnin error in main class is generated Exception in thread 

Java Beginners

main func - Java Beginners
main func  why do we pass array of strings in main function of java?  Hi Friend, It is used to signify that the user may opt to enter parameters to the java program at command line. Thanks 

Java Beginners

main() syntax - Java Beginners
main() syntax  Hi, I would like to know the complete structure of the main() in jdk1.5 with sample program. Regards, UsmanAli Shaik,   Hi Friend, Structure of Java program: [package declaration 

Java Beginners

problem with main - Java Beginners
int Y_FACE = 50; public static final int EYE_WIDTH = 10; public static... static final int NOSE_DIAMETER = 10; public static final int X_NOSE = 195... a problem. when i compile it appears this message: java.lang.NoSuchMethodError: main 

Java Beginners

main method
main method  Why is the java main method static 

Java Beginners

Can a main method be overloaded?
Can a main method be overloaded?   Hi, Can a main method be overloaded? thanks,   Hi, Yes, In Java program we could having multiple number of main() methods with different Signature and implementation in the class 

Java Beginners

When is java main method called?
When is java main method called?  When is java main method called? Please explain the main method in Java with the help of code.   In a java class, main(..) method is the first method called by java environment when 

Java Beginners

What is the return type of the main method?
type of the main method? thanks   Hi, In the java programming the Main() method doesn't return anything hence declared void. In Java, you need... appear in a real Java program. For more visit http://www.roseindia.net/java/java 

Java Beginners

Static keyword in public static void main
://www.roseindia.net/java/learn-java-in-a-day/create-first-program.shtml Explanation... keyword. Following is an example of static declaration: static int i=10... void main(String args[]) { meth(42); } } In the above code, as soon 

General

Main Thread and Child Thread
There are two types of threads in Java Progarm In Java there are Main and Child Threads used in Programming. Main thread is automatically created when program runs. Child Thread gets created by the main thread . Java Main 

Java Beginners

Till Slip Program Error Free - No Main Method
Till Slip Program Error Free - No Main Method  Hi there i am a java... that the program recquires a main() method in order to be runned - here is the following code... the GUI as it is more reliable and efficent - the current program that i am working 

Java Beginners

Till Slip Program Error Free - No Main Method
Till Slip Program Error Free - No Main Method  Hi there i am a java... that the program recquires a main() method in order to be runned - here is the following code... the GUI as it is more reliable and efficent - the current program that i am working 

Java Beginners

Till Slip Program Error Free - No Main Method
Till Slip Program Error Free - No Main Method  Hi there i am a java... that the program recquires a main() method in order to be runned - here is the following code... the GUI as it is more reliable and efficent - the current program that i am working 

Java Beginners

Till Slip Program Error Free - No Main Method
Till Slip Program Error Free - No Main Method  Hi there i am a java... that the program recquires a main() method in order to be runned - here is the following code... the GUI as it is more reliable and efficent - the current program that i am working 

Java Beginners

Till Slip Program Error Free - No Main Method
Till Slip Program Error Free - No Main Method  Hi there i am a java... that the program recquires a main() method in order to be runned - here is the following code... the GUI as it is more reliable and efficent - the current program that i am working 

Java Beginners

Till Slip Program Error Free - No Main Method
Till Slip Program Error Free - No Main Method  Hi there i am a java... that the program recquires a main() method in order to be runned - here is the following code... the GUI as it is more reliable and efficent - the current program that i am working 

Java Beginners

Main function.. - Java Beginners
Main function..  Hi Friend.. public static void main(String args[]) What does it mean...public - static - void - main -(String args[]) Can u plz... return the value when it exits main(): This is the entry point for the application 

Java Beginners

Why we should use string args[] in main method in java?
Why we should use string args[] in main method in java?  we use only string in the main method not any other one.. specify the reason... and tell me each and every meaning of public static void main(String args[])...    

Java Beginners

main function defnition in class - Java Beginners
and will subsequently invoke all the other methods required by your program. The main method...main function defnition in class  why do we use public infront of a main function   Hi friend, The main method is similar to the main 

Java Beginners

What is the arguement of main method?
What is the arguement of main method?  hi, What is the arguement of main method? thanks,   Hi, For main() method accepts only an array of String object as arguement. For moe details on http://www.roseindia.net/java 

Java-Tutorials

What is Public static void main
the rules otherwise your program will not run. Signature of main method in java...[]) //this is most classic signature of main method. Remember the varargs version of java will work in java 1.5 or later version only. Main is the entry point of  

Java Beginners

Main topics in java for IT corporate working?
Main topics in java for IT corporate working?  What are the main and most important topics in java should be mastered that are usually incorporated in IT corporate world 

JDBC Questions

Exception in thread "main" java.lang.ClassCastException
Exception in thread "main" java.lang.ClassCastException  I am trying.... Anyone help me please. Java Code: import java.sql.*; import org.postgis....){e.printStackTrace();} } } public static void main(String[] argv) { try { Class driver 

Java Beginners

Exception in thread "main" java.lang.ClassCastException
Exception in thread "main" java.lang.ClassCastException  I am trying.... Anyone help me please. Java Code: import java.sql.; import org.postgis....){e.printStackTrace();} } } public static void main(String[] argv) { try { Class driver 

Hibernate Interview Questions

What is the main feature of Hibernate3?
What is the main feature of Hibernate3?  What is the main feature... or local Java API, including a second-level cache browser. ∑ Eclipse support... timings as it supports inheritance, polymorphism, composition and the Java 

Java Interview Questions

create main page
create main page  <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <%@page import="java.sql.*"%> <%@page import="java.util.*"%> <%@ page session="true 

Java Beginners

How to eliminate error," Could not find the main class: filecopy.FileCopy. Program will exit." ?
class: filecopy.FileCopy. Program will exit. Exception in thread "main" Java...How to eliminate error," Could not find the main class: filecopy.FileCopy. Program will exit." ?  run: java.lang.NoClassDefFoundError: filecopy 

Java Interview Questions

main method
main method  What is the argument type of a program's main() method 

Java Beginners

What is the first argument of the String array in main() method?
. This article gives your a very easy java program which illustrates about the string...What is the first argument of the String array in main() method?  Hi, What is the first argument of the String array in main() method? Thanks 

Java-Tutorials

Listing the Main Attributes in a JAR File Manifest
Listing the Main Attributes in a JAR File Manifest       Jar Manifest: Jar Manifest file is the main... the information syntax with rule and restrictions. Main Attributes in Jar file 

Java Interview Questions

main() method
main() method  Can we define two main() methods having same parameter but with different return type in a program 

General

Understanding public static void main function
function in Java programming language. In this section we will learn about main function. The main method is the first method, which the Java Virtual Machine... method is the entry point in the Java program and java program can't run without 

Java Beginners

main method
can not make multiple main with in the same class program fails to compile. Compiler gives error that the main method is already defined in the class...main method  hello, Can I make multiple main methods in the same 

Java Beginners

exception in thread main java.lang.unsupportedclassversionerror unsupported major.minor version 50.0 - Java Beginners
!"); } } for example: javac xxx.java-->comping java xxxx:error :exception in thread main... for compilation and execution of java program. Therefore set the path of one java version...exception in thread main java.lang.unsupportedclassversionerror unsupported 

Java Beginners

Why is the main method declared static?
Why is the main method declared static?  Hi, Why is the main method declared static? thanks   Hi, When we declare main() method in any Java class always has the same signature, and we declare public static void main 

Java Interview Questions

main function in java - Java Interview Questions
main function in java  1....why is function main() define as static in java? 2...drawbacks of using rmi 

Java Beginners

What if the main() method is declared as private?
What if the main() method is declared as private?  Hi, What if the main() method is declared as private? Thanks   Hi, I have found some reference site for java programming coding for Main() method is declared 

Java Beginners

Can a main method be declared final?
be override in a subclass. for more about main method be declared final in Java...Can a main method be declared final?   Hi, Can a main method be declared final? Thanks   Hi, Yes we can. The final method can 

Java Interview Questions

write a java program for inserting a substring in to the given main string from a given position
write a java program for inserting a substring in to the given main string from a given position  write a java program for inserting a substring in to the given main string from a given position 

Java Beginners

What are the main disadvantages of Java Server Faces 2.0?
What are the main disadvantages of Java Server Faces 2.0?  What are the main disadvantages of Java Server Faces 2.0 

Java Beginners

How to Differenciate Main Thread and Child Thread in Java
Main Thread and Java Child Thread. Please Suggest any example or online link... in Java Programming Language. These are Java Main Thread and the Child Thread...How to Differenciate Main Thread and Child Thread in Java  hi 

Java Beginners

how to solve the nullPointer Exception in main - Java Beginners
how to solve the nullPointer Exception in main  New to Java ,pls help me how fix Null pointer Exception in main: two files , split .java another... main(String[] args) { String actualState; String str1 = "s0;input 

Java Magazine Questions

Main job of cpu
Main job of cpu  What is the Main Job of CPU?   The CPU perform two main task .. 1. It carry out program instructions and also 2. Process the data and information 

Java Beginners

.jar file keeps giving me " could not find the main class". Program will exit.
.jar file keeps giving me " could not find the main class". Program will exit... click on it, it gives me the message" could not find the main class. Program... netbeans's project properties clearly sets testing2.hihi as my Main class and I have 

Java Interview Questions

JAVA what is different between static block and public static void main(String a[]) method
JAVA what is different between static block and public static void main(String... void main(String a[]) method,we execute method without main method(by static block) why need of public static void main(String [])?   Static blocks 

Java Beginners

Should a main method be compulsorily declared in all java classes?
Should a main method be compulsorily declared in all java classes?  hi, Should a main method be compulsorily declared in all java classes? thanks... in all java classes. Where as the main method we should be defined only if the source 

Free Magazine

Tips & Tricks
?? You got it right! The program below runs without the main method. Here we have...Tips & Tricks          Here are some basic implementations of java language, which you would 

Java Beginners

exception in thread main java.lang.unsupportedclassversionerror unsupported major.minor version 50.0 - Java Beginners
exception in thread main java.lang.unsupportedclassversionerror unsupported.... java -version java version "1.4.2_06" javac -version java version.... Thanks  my code is class xxx { public static void main(String 

Java Beginners

Accessing non-static members through the main method in Java.
Accessing non-static members through the main method in Java.  ... methods. If it is so, an obvious question arises as to how can the main() method in Java has access to non-static members (variables or methods) even though 

Java Beginners

how to return to main menu after adding all the info. - Java Beginners
how to return to main menu after adding all the info.  import java.util.Scanner; public class RegistrationSystem { public static void main...; System.out.println("School Registration System Main Menu 

Java Interview Questions

How I call the function union from the main - Java Interview Questions
static void main(String[] args) I would like to call the function union and I... declared in main function //------------------------------- package model...; } public static void main(String[] args) { Relation relation = new 

Swing AWT

how to open one Jframe from main method call
how to open one Jframe from main method call  I have downloaded a snake game project in java. Initially the project contains three java files i.e... the main() method, when i run this Engine.java class game starts running 

Java Beginners

main function
main function  Give me the description of public static void main(Strings args 

Java Beginners

main method
main method  psvm(String args[]) what does this arguement in paranthesis denote?   Hi Friend, public-It indicates that the main() method can be called by any object. static-It indicates that the main() method 

Java Beginners

java program
java program  write a java program which shows how to declare and use STATIC member variable inside a java class.   The static variable... Static { static int a = 10; static int b = 20; } class StaticMember { public static 

Java Beginners

About Main
 

Java Beginners

About Main
 

Java Beginners

java program
java program  write a program showing two threads working... void main(String args[ ]) throws IOException{ MyClass obj1=new MyClass...; } public void run(){ for(int i = 1; i<=10; i 

Java Beginners

How to Create Animated Main Menu Application with Java Swnig Buttons - Java Beginners
How to Create Animated Main Menu Application with Java Swnig Buttons  Hello sir I want to display Main Menu after Log in i have created Log in Form but I want More attractive Animated Main Menu which includes Following 

Java-Tutorials

How to run a Java program in CMD
discussed how to write and run Java program in CMD. Tips to run Java program... a notepad or any other editor and write a small program in Java as given below... command at your command prompt. set path=%path%;C:\Program Files\Java\jdk1.5.0_09 

Java Beginners

Java Program
Java Program  How to Write a Java program which read in a number... out in the standard output. The program should be started like this: java... into a fixed size buffers of strings. The buffer can store at most 10 strings 

Java Beginners

Java Program
Java Program for accepting numbers from 1 - 999 and printing them in form of words  Program for accepting numbers from 1 - 999 and printing them in form of words   Java Convert Number to Words The given code accept 

Java Beginners

Java Program - Java Beginners
Java Program  Write a java program to find out the sum of digits...: import java.util.*; public class SumOfDigits { public static void main... != 0) { sum += num % 10; num =num/ 10 

Java Interview Questions

Display Hello even before main get executed??
Display Hello even before main get executed??  I have a class (main... is how? **class Hello{ public static void main(String[] args... the program. Please assist 

Ajax Questions

Main function parameter in C language - Ajax
Main function parameter in C language  Please let me know how this Main(int argc,char*argv[]) works and detailed example on their roles in command...; Hi Friend, int main(int argc, char **argv) The main function serves 

Java Server Faces Questions

exception in thread main while running servlet
exception in thread main while running servlet  I got exception in thread main no such method error while running servlet. I have added servlet.api.jar file in classpath.my classpath is C:\Program Files\Apache Software Foundation 

Java Beginners

Java Program - Java Beginners
Java Program  A Java Program that input 10 Numbers and find out... static void main(String[] args) { Scanner input = new Scanner(System.in...("Enter 10 numbers."); for (int i=1;i<11;i++){ int 

Free Magazine

Tips & Tricks
Tips & Tricks           Splash Screen in Java 6.0 Splash screens... of the application. AWT/Swing can be used to create splash screens in Java. Prior to Java SE 

Java Beginners

Java Program - Java Beginners
Java Program  Write a program to compute sum of digits of a given... SumOfDigits { public static void main(String[] args) { Scanner input... % 10; num =num/ 10 

JSP Interview Questions

how to pass variable from simple java main class(not servlet) to the jsp page?
how to pass variable from simple java main class(not servlet) to the jsp page?  I have a simple Java class in which I invoke a call to a JSP page... from the simple Java class to the JSP page. How can I do that? Here is my 

Java Beginners

a java program... - Java Beginners
a java program...  write a program to check that a number... of the number. write a program to print the following pattern 55555 54444... main(String args[]) throws IOException{ BufferedReader bf = new BufferedReader 

General

10 Minutes Guide to Ant
10 Minutes Guide to Ant       Introduction Well for the next 10 minutes get ready to devote... have a solid knowledge of java programming and development of web application 

Java Beginners

Java Program - Java Beginners
Java Program  Write a Java program that calculates and prints...,R should be accepted as command line input as below. e.g. java SimpleInterest 5 10 15  Hi Friend, Try the following code: import java.io. 

Java Beginners

java Program - Java Beginners
java Program  1. Write a java program to accept 10 numbers in an array and compute the sum of the square of these number. 2. Wrtie a java program... static void main(String[] args){ Scanner input=new Scanner(System.in 

Java Beginners

java program - Java Beginners
java program  program to get an output i.e., is: INPUT... { str = oneWords[num % 10]; num /= 10; str = tensWords[num % 10] + str; num /= 10; } if (num == 0) return str 

Java Beginners

Java Program - Java Beginners
Java Program  The numbers in the following sequence are called... a program using do‚?¶..while loop to calculate and print the first m Fibonacci numbers... void main(String[] args) { System.out.println("*****Fibonnaci Series 

Java Beginners

Java Program - Java Beginners
Java Program  Hi, I'm have complications with this program. I keep getting errors and my coding is off. Can you help me? Write a program called...: Have your program accept the user input in two text fields. When a button 

Java Beginners

Java Program - Java Beginners
Java Program  Write a program that converts a decimal number to Roman... main(String[] args) { DecimalToRoman dec=new DecimalToRoman..."), new Roman( 40, "XL"), new Roman( 10, "X"), new Roman( 9 

Java Beginners

Java program - Java Beginners
Java program  Dear maam/Sir, I am a 2nd year Computer programming student and we are given an assignment, a program that will show... not that familiar with java environment.. My friend told me that you can help me with my 

Java Beginners

Java Program - Java Beginners
Java Program  Hi I'm having trouble with this problem, I keep getting errors. Write a program GuessGame.java that plays the game ?guess the number? as follows: Your program chooses the number to be guessed by selecting 

Java Beginners

determine the top 10 highest and 10 lowest in java
determine the top 10 highest and 10 lowest in java  hello, I have... that contains the codebooks and namesmembers. I want to make 10 the highest rank anyone who borrows a book and who the 10 smallest borrow books. Please help me master 

Java Beginners

Java program? - Java Beginners
Java program?  In order for an object to escape planet's.... The escape velocity varies from planet to planet.Create a Java program which calculates the escape velocity for the planet. Your program should first prompt 

Java Interview Questions

Main method overloading
Main method overloading  Can we overload main()method 

Web Development

Top 10 Web Development Languages
Top 10 Web Development Languages For a web designer or a web developer... the main point of internet access across the globe website development or designing... a choice but an irreplaceable necessity. While offshoot Java based web 

Java-Tutorials

Setting Tool Tips on Cells in a JTable
of program: With the help of this program you will set the tool tips on cells... Setting Tool Tips on Cells in a JTable   ... the tool tips in the cells in a JTable component. So, you will be able to know 

Development process Questions

why not float main?
why not float main?  why should the main be int or void?why cant it be float or char? why int main()?why not float main()?or char main 

Development process Questions

why not float main?
why not float main?  why should the main be int or void?why cant it be float or char? why int main()?why not float main()?or char main 

Java Beginners

java program based on array
java program based on array  Create Student class with attributes... StudentDemo which will have main method. Declare array of Student object with size 10. Initialize all 10 elements of this array with new objects. Write logic which 

Java Beginners

java program - Java Beginners
java program  ahm... i will use a table, text field and a button in java... a user will input a data to be search in the table.. after searching..."); textArea.setColumns(10); textArea.setLineWrap(true); textArea.setRows(5 

General

Java Virtual Machine(JVM)
Machine JVM is the main component of Java architecture and it is the part... works . Firstly we write the simple java program(source code) the java compiler... a simplest java program : public class MyFirstProgram {   

Java Beginners

java program based on array
java program based on array  write a program to create an array of 10 integers in main.accept values from the user in that array .now again ask... the no. passed .finally return the result block to main and print 

Java Magazine Questions

Main memory is also known as
Main memory is also known as   Main memory of a computer is also known 

JavaScript Questions

JSON main question
JSON main question  What is the main purpose of JSON ,in which cases can i use 

Ajax Questions

JSON main question
JSON main question  What is the main purpose of JSON ,in which cases can i use 

Java Beginners

public static void main
public static void main  what is mean public static void main?   public-It indicates that the main() method can be called by any object. static-It indicates that the main() method is a class method. void- It indicates 

Java Beginners

if i run this prog, i got exeption in thread "main" java.lang.ArrayIndexOutOfBoundsException:0 at Maxof2.main(Maxof2.java:9), whats the resolution for ths?
if i run this prog, i got exeption in thread "main...?  class Maxof2{ public static void main(String args[]){ //taking... with run command. Run your code with the following statement: java Maxof2 5 6 

Java Beginners

Class and interface in same file and accessing the class from a main class in different package
Class and interface in same file and accessing the class from a main class... pattern videos on YouTube, however I have a small doubt on some basic Java concept... a class named CantFly in same file. A main method CheckAnimal.java. Below 

Java Beginners

Class and interface in same file and accessing the class from a main class in different package
Class and interface in same file and accessing the class from a main class... pattern videos on YouTube, however I have a small doubt on some basic Java concept... a class named CantFly in same file. A main method CheckAnimal.java. Below 

Java Interview Questions

Interview Tips - Java Interview Questions
Interview Tips  Hi, I am looking for a job in java/j2ee.plz give me interview tips. i mean topics which i should be strong and how to prepare. Looking for a job 3.5yrs experience 

Advertisements Advertisements
 

 

 

DMCA.com