I am writing a rectangle applet. Everything works fine, runs and compiles fine. What i am supposed to do as well is restrict the maximum and minimum size of the applet such that the user cannot enter a negative number or zero for the min, and limit the max so that the rectangle will be properly displayed in the applet. I am just not sure how to do it. I was thinking to use an if statement, but i'm not completely sure. here is my code
import java.applet.*; import java.awt.*; import java.awt.event.*; import java.text.*; import java.awt.Graphics; public class rectangle extends Applet implements ActionListener { //declare variables Image logo; //declare an Image object int height, width; //construct components Label heightLabel = new Label("Enter the height of your rectangle: "); TextField heightField = new TextField(10); Label widthLabel = new Label ("Enter the width of your recntagle: "); TextField widthField = new TextField(10); Button drawButton = new Button("Draw Rectangle"); Label outputLabel = new Label("Click the Draw Rectangle button to see your rectangle."); public void init() { setMaximumSize(new Dimension(700,700)); setMinimumSize(new Dimension(500,500)); setForeground(Color.green); add(companyLabel); add(heightLabel); add(heightField); add(widthLabel); add(widthField); add(drawButton); drawButton.addActionListener(this); add(outputLabel); setBackground(Color.red); } public void actionPerformed(ActionEvent e) { height = Integer.parseInt(heightField.getText()); width = Integer.parseInt(widthField.getText()); repaint(); } public void paint(Graphics g) { g.setColor(Color.green); g.drawRect(125,100,width,height); g.fillRect(125,100,width,height); } }