JOptionPane
in
Programming Questions
•
1 year ago
Can anyone tell me how to combine results of area and perimeter of a rectangle in one JOptionPane?
import javax.swing.JOptionPane;
void setup(){
size(480,120);
background(0);
noLoop();
}
void draw(){
background(0);
int width;
int height;
int length;
int area;
int perimeter;
String heightstr, widthstr;
heightstr = JOptionPane.showInputDialog("Enter the height: ");
widthstr = JOptionPane.showInputDialog("Enter the width: ");
width=parseInt(widthstr);
height=parseInt(heightstr);
area = width * height;
perimeter = 2 * height + 2 * width;
JOptionPane.showMessageDialog(null, area, "Area", JOptionPane.INFORMATION_MESSAGE);
JOptionPane.showMessageDialog(null, perimeter, "Perimeter", JOptionPane.INFORMATION_MESSAGE);
}
widthstr = JOptionPane.showInputDialog("Enter the width: ");
width=parseInt(widthstr);
height=parseInt(heightstr);
area = width * height;
perimeter = 2 * height + 2 * width;
JOptionPane.showMessageDialog(null, area, "Area", JOptionPane.INFORMATION_MESSAGE);
JOptionPane.showMessageDialog(null, perimeter, "Perimeter", JOptionPane.INFORMATION_MESSAGE);
}
1