網(wǎng)站制作NEWS
JAVA編程:編寫一個(gè)applet,讀取一個(gè)矩形的邊長(zhǎng),然后輸入一個(gè)空心矩形
import java.awt.*;
import javax.swing.*;
public class drawRech extends JApplet {
public void paint(Graphics g){
super.paint(g);
this.setBackground(Color.WHITE);
String width = JOptionPane.showInputDialog("Enter the width");
String height = JOptionPane.showInputDialog("Enter the height");
int wid = 0;
int heig = 0;
try{
wid = Integer.parseInt(width);
heig = Integer.parseInt(height);
}
catch(NumberFormatException e){
JOptionPane.showMessageDialog(null, "Wrong input");
}
g.drawRect(100, 100, wid, heig);
}
}
已添加異常處理,測(cè)試成功
多重隨機(jī)標(biāo)簽