Skip to content

Instantly share code, notes, and snippets.

@mherman22
Created March 29, 2020 07:34
Show Gist options
  • Select an option

  • Save mherman22/befc8112eddb91a6023efaca0f5d6e3c to your computer and use it in GitHub Desktop.

Select an option

Save mherman22/befc8112eddb91a6023efaca0f5d6e3c to your computer and use it in GitHub Desktop.
more understanding of java gui. #from analysis to design
package gui;
import javax.swing.*; //i am to use JOptionPane
public class Rectangle {
public static void main(String[] args) {
// TODO Auto-generated method stub
double width, length, area, perimeter;
String lengthstr, widthstr, outputstr;
lengthstr = JOptionPane.showInputDialog("Enter the Length:");
length = Double.parseDouble(lengthstr);
widthstr = JOptionPane.showInputDialog("Enter the Width");
width = Double.parseDouble(widthstr);
area = length * width;
perimeter = 2 * (length + width);
outputstr = "Length: "+ length + "\n" +
"Width: " + width + "\n" +
"Area: " + area +"square units\n" +
"Perimeter"+ perimeter +"units\n";
JOptionPane.showMessageDialog(null, outputstr,
"Rectangle",JOptionPane.INFORMATION_MESSAGE);
System.exit(0);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment