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




Have Programming Question? Ask it here!
 
 
 


rocio
OfficeArea
1 Answer(s)      4 years and 9 months ago
Posted in : Java Beginners



Advertisement
View Answers

July 28, 2009 at 12:00 PM


Hi Friend,

Try the following code:

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

class Form extends JFrame{
JLabel label1,label2;
JTextField text1,text2;
JButton button;
JButton exit;
JPanel panel;
Form(){
panel=new JPanel(new GridLayout(3,2));
label1=new JLabel("Enter the length of the office: ");
label2=new JLabel("Enter the width of the office: ");
text1=new JTextField(10);
text2=new JTextField(10);
button=new JButton("Calculate");
exit= new JButton("Exit");
panel.add(label1);
panel.add(text1);
panel.add(label2);
panel.add(text2);
panel.add(button);
panel.add(exit);
add(panel,BorderLayout.CENTER);
button.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
String value1=text1.getText();
int num1=Integer.parseInt(value1);
String value2=text2.getText();
int num2=Integer.parseInt(value2);

int area=num1*num2;
JFrame f=new JFrame();
JTextField result=new JTextField(10);
result.setText(Integer.toString(area));
f.add(result);
f.setVisible(true);
f.pack();
}
});
exit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
System.exit(0);
}
});
}
}
class OfficeArea
{
public static void main(String arg[])
{
try
{
Form frame=new Form();
frame.pack();
frame.setVisible(true);
}
catch(Exception e)
{}
}
}

Hope that it will be helpful for you.
Thanks


Related Tutorials/Questions & Answers:
OfficeArea - Java Beginners
(ActionEvent event) { System.exit(0); } }); } } class OfficeArea
Eclipse - Java Beginners
); } }); } } class OfficeArea { public static void main(String args[]) { try
Advertisements
 

 

 

DMCA.com