DOWNLOAD

Get our toolbar!

Friday, 29 April 2011

// To calculate for multiply 2 numbers by using applet.


CODE

import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class AppletMul extends Applet implements ActionListener{
TextField text1,text2,output;
Label label1,label2,label3;
Button button;
public void init(){
setLayout(null);
label1 = new Label("Enter Number1: ");
label1.setBounds(20,20,100,20);
add(label1);
text1 = new TextField(5);
text1.setBounds(150,20,100,20);
add(text1);
label2 = new Label("Enter Number2: ");
label2.setBounds(20,50,100,20);
add(label2);
text2 = new TextField(5);
text2.setBounds(150,50,100,20);
add(text2);
label3 = new Label("Mul of Two Numbers: ");
label3.setBounds(20,80,130,20);
add(label3);
output = new TextField(5);
output.setBounds(150,80,100,20);
add(output);
button = new Button("Mul");
button.setBounds(150,110,100,20);
add(button);
button.addActionListener(this);
}
public void actionPerformed(ActionEvent ae){
int num1=Integer.parseInt(text1.getText());
int num2=Integer.parseInt(text2.getText());
int Mul=num1*num2;
output.setText(Integer.toString(Mul));
}
}

HTML CODE

<HTML>
<BODY>
<APPLET ALIGN="CENTER" CODE="AppletSum.class" width = "700" height = "400"></APPLET>
</BODY>
</HTML>


 OUTPUT DISPLAY



// To calculate for adding 2 numbers by using applet.


CODE

import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class AppletSub extends Applet implements ActionListener
{
TextField text1,text2,output;
Label label1,label2,label3;
Button button;
public void init()
{
setLayout(null);
label1 = new Label("Enter Number1: ");
label1.setBounds(20,20,100,20);
add(label1);
text1 = new TextField(5);
text1.setBounds(150,20,100,20);
add(text1);
label2 = new Label("Enter Number2: ");
label2.setBounds(20,50,100,20);
add(label2);
text2 = new TextField(5);
text2.setBounds(150,50,100,20);
add(text2);
label3 = new Label("Sub of Two Numbers: ");
label3.setBounds(20,80,130,20);
add(label3);
output = new TextField(5);
output.setBounds(150,80,100,20);
add(output);
button = new Button("Sub");
button.setBounds(150,110,100,20);
add(button);
button.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
int num1=Integer.parseInt(text1.getText());
int num2=Integer.parseInt(text2.getText());
int sub=num1-num2;
output.setText(Integer.toString(sub));
}
}

HTML CODE

<HTML>
<BODY>
<APPLET ALIGN="CENTER" CODE="AppletSum.class" width = "700" height = "400"></APPLET>
</BODY>
</HTML>

OUTPUT DISPLAY


// Menu Bar in Java


CODE

import java.awt.event.ActionEvent;
     import java.awt.event.ActionListener;
     import javax.swing.JFrame;
     import javax.swing.JMenu;
    import javax.swing.JMenuBar;
    import javax.swing.JMenuItem;
    public class MenuBarExample extends JFrame
{
       public MenuBarExample()
{

       setTitle("MenuBarExample");
       setSize(200, 350);


       JMenuBar menuBar = new JMenuBar();

      setJMenuBar(menuBar);


      JMenu fileMenu = new JMenu("File");
      JMenu editMenu = new JMenu("Edit");
      JMenu viewMenu = new JMenu("View");
      menuBar.add(fileMenu);
      menuBar.add(editMenu);
      menuBar.add(viewMenu);


      JMenuItem newAction =   new JMenuItem("New");
      JMenuItem openAction =  new JMenuItem("Open");
      JMenuItem exitAction =    new JMenuItem("Exit");
      JMenuItem cutAction =     new JMenuItem("Cut");
      JMenuItem copyAction =  new  JMenuItem("Copy");
      JMenuItem pasteAction =  new JMenuItem("Paste");
      JMenuItem toolbarsAction= new JMenuItem("toolbarsAction");
      fileMenu.add(newAction);
      fileMenu.add(openAction);
      fileMenu.addSeparator();
      fileMenu.add(exitAction);
      editMenu.add(cutAction);
      editMenu.add(copyAction);
      editMenu.add(pasteAction);
      editMenu.addSeparator();
      viewMenu.add(toolbarsAction);

       newAction.addActionListener(new ActionListener();
 {
      public void actionPerformed(ActionEvent arg0)
 {
      System.out.println("You clicked on the new action");
  }
  }
  };
  }
     public static void main(String[] args)
 {
     MenuBarExample mba = new MenuBarExample();
     mba.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     mba.setVisible(true);
 }
 }
OUTPUT ON COMMAND


C:\saurabh>javac MenuBarExample.java

C:\saurabh>java MenuBarExample



OUTPUT DISPLAY

// PROGRAM TO CALCULATE ADDITION OF 2 NUMBER.


CODE


import java.awt.*;
    import java.applet.*;
    import java.awt.event.*;


    public class AppletSum extends Applet implements ActionListener{
      TextField text1,text2,output;
      Label label1,label2,label3;
      Button button;
      public void init(){
        setLayout(null);
        label1 = new Label("Enter Number1: ");
        label1.setBounds(20,20,100,20);
        add(label1);


        text1 = new TextField(5);
        text1.setBounds(150,20,100,20);
        add(text1);


        label2 = new Label("Enter Number2: ");
        label2.setBounds(20,50,100,20);
        add(label2);


        text2 = new TextField(5);
        text2.setBounds(150,50,100,20);
        add(text2);


        label3 = new Label("Sum of Two Numbers: ");
        label3.setBounds(20,80,130,20);
        add(label3);


        output = new TextField(5);
        output.setBounds(150,80,100,20);
        add(output);


        button = new Button("Sum");
        button.setBounds(150,110,100,20);
        add(button);


        button.addActionListener(this);
        }
        public void actionPerformed(ActionEvent ae){
        int num1=Integer.parseInt(text1.getText());
        int num2=Integer.parseInt(text2.getText());
        int sum=num1+num2;
        output.setText(Integer.toString(sum));
        }
    }



HTML CODE

<HTML>
<BODY>
<APPLET ALIGN="CENTER" CODE="AppletSum.class" width = "700" height = "400"></APPLET>
</BODY>
</HTML>


OUTPUT DISPLAY





Twitter Delicious Facebook Digg Stumbleupon Favorites More