Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Bastet Massri   on Aug 07 In Java Category.

  
Question Answered By: Rhys Evans   on Aug 07

I have modified ur code to do so....


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


public class  Testt

{
public static  void main(String[]args) throws
NoSuchMethodError
{

Test1 test  = new Test1();
}
}



class Test1 implements ActionListener
{

TextField text1, text2, text3;
Label label1,label2;
Button button1,
button2,button3,button4,button5,button6;
Frame frame;
MenuBar menubar;
MenuItem item1;
FlowLayout flow;
Menu menu;


public Test1()
{


frame = new Frame("Have a nice day");

frame.setBounds(0,0,500,400);

menubar = new MenuBar();
frame.setMenuBar(menubar);

menu = new Menu("First Menu");
menubar.add(menu);

item1 = new MenuItem("Open");
menu.add(item1);

flow = new FlowLayout();
frame.setLayout(flow);

text1 = new TextField(12);
text2 = new TextField(12);
text3 = new TextField(12);

label1 = new Label(" and ");
label2 = new Label("=");

frame.add(text1);
frame.add(label1);
frame.add(text2);
frame.add(label2);
frame.add(text3);

button1 = new Button(" X ");
button2 = new Button(" / ");
button3 = new Button(" + ");
button4 = new Button(" - ");
button5 = new Button("Clear");
button6 = new Button("Exit");

frame.add(button1);
frame.add(button2);
frame.add(button3);
frame.add(button4);
frame.add(button5);
frame.add(button6);

frame.setVisible(true);

button1.addActionListener(this);
button2.addActionListener(this);
button3.addActionListener(this);
button4.addActionListener(this);
button5.addActionListener(this);
button6.addActionListener(this);

}

public void  actionPerformed(ActionEvent ee)
{

String msg = new String("Hullo from java");

// Multiply

if(ee.getSource() == button1)
{
Double double1 = new Double(text1.getText());
Double double2 = new Double(text2.getText());

double dd = double1.doubleValue() *
double2.doubleValue();

text3.setText(String.valueOf(dd));
}

// Divide

if(ee.getSource() == button2)
{
Double double1 = new Double(text1.getText());
Double double2 = new Double(text2.getText());

double dd = double1.doubleValue() /
double2.doubleValue();

text3.setText(String.valueOf(dd));
}

// Add

if(ee.getSource() == button3)
{
Double double1 = new Double(text1.getText());
Double double2 = new Double(text2.getText());

double dd = double1.doubleValue() +
double2.doubleValue();

text3.setText(String.valueOf(dd));
}

// Subtract

if(ee.getSource() == button4)
{
Double double1 = new Double(text1.getText());
Double double2 = new Double(text2.getText());

double dd = double1.doubleValue() -
double2.doubleValue();

text3.setText(String.valueOf(dd));
}



if(ee.getSource() == button5)
{
text1.setText(null);
text2.setText(null);
text3.setText(null);
}

if(ee.getSource() == button6)
{
System.exit(0);
}


}

}

Share: 

 

This Question has 3 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on Exit from frame using button Or get search suggestion and latest updates.


Tagged: