Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Graphics;
- import javax.swing.JApplet;
- import javax.swing.JOptionPane;
- @SuppressWarnings("serial")
- public class Rectangle extends JApplet
- {
- private int x, y, w, h;
- public void init()
- {
- try
- {
- String xinput = JOptionPane.showInputDialog("Enter x-coordinate of the top left corner: ");
- x = Integer.parseInt(xinput);
- }
- catch (Exception e)
- {
- System.out.println("ERROR: You entered a non-integer value.");
- System.exit(0);
- }
- if (x < 0)
- {
- System.out.println("ERROR: You entered a negative number.");
- System.exit(0);
- }
- try
- {
- String yinput = JOptionPane.showInputDialog("Enter y-coordinate of the top left corner: ");
- y = Integer.parseInt(yinput);
- }
- catch (Exception e)
- {
- System.out.println("ERROR: You entered a non-integer value.");
- System.exit(0);
- }
- if (y < 0)
- {
- System.out.println("ERROR: You entered a negative number.");
- System.exit(0);
- }
- try
- {
- String winput = JOptionPane.showInputDialog("Enter the desired width of the rectangle: ");
- w = Integer.parseInt(winput);
- }
- catch (Exception e)
- {
- System.out.println("ERROR: You entered a non-integer value.");
- System.exit(0);
- }
- if (w < 0)
- {
- System.out.println("ERROR: You entered a negative number.");
- System.exit(0);
- }
- try
- {
- String hinput = JOptionPane.showInputDialog("Enter the desired height of the rectangle: ");
- h = Integer.parseInt(hinput);
- }
- catch (Exception e)
- {
- System.out.println("ERROR: You entered a non-integer value.");
- System.exit(0);
- }
- if (h < 0)
- {
- System.out.println("ERROR: You entered a negative number.");
- System.exit(0);
- }
- }
- public void paint(Graphics g)
- {
- super.paint(g);
- g.drawRect(x, y, w, h);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement