當前位置:編程學習大全網 - 編程軟體 - JAVA編程:編寫壹個applet,讀取壹個矩形的邊長,然後輸入壹個空心矩形

JAVA編程:編寫壹個applet,讀取壹個矩形的邊長,然後輸入壹個空心矩形

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語言編程,請大神幫忙~
  • 下一篇:求按鍵精靈(Quick Macro) v6.71.2192註冊碼
  • copyright 2024編程學習大全網