第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

數(shù)據(jù)不正確時(shí)的Java showInputDialog

數(shù)據(jù)不正確時(shí)的Java showInputDialog

慕慕森 2021-07-05 17:15:52
import javax.swing.*;import java.io.Serializable;import java.rmi.registry.LocateRegistry;import java.rmi.registry.Registry;public class Server implements Serializable{    public static void main(String[] args) {        String test1= JOptionPane.showInputDialog(null,"Port(0-65535):","Port",JOptionPane.QUESTION_MESSAGE);        int portnumber = tryParse(test1);        if (portnumber !=0) {            try {                Registry reg = LocateRegistry.createRegistry(portnumber);   //Creates and exports a Registry instance on the local host that accepts requests                RmiImplementation imp = new RmiImplementation("C://ServerStorage");                reg.bind("remoteObject", imp);                System.out.println("Server is ready.");                System.out.println(portnumber);            } catch (Exception e) {                System.out.println("Server failed: " + e);            }        }    }    private static Integer tryParse(String text) {        try {            return Integer.parseInt(text);        } catch (Exception e) {            return 0;        }    }}上面的代碼幫助我設(shè)置我的文件服務(wù)器。當(dāng)應(yīng)用程序運(yùn)行時(shí),會(huì)請(qǐng)求對(duì)話框端口號(hào)。如果我輸入字母而不是數(shù)字,程序?qū)⑼V惯\(yùn)行,但我希望它繼續(xù)并再次顯示對(duì)話框。
查看完整描述

1 回答

?
茅侃侃

TA貢獻(xiàn)1842條經(jīng)驗(yàn) 獲得超21個(gè)贊

嘗試使用do-while,


int portnumber = 0;

do {

     String text= JOptionPane.showInputDialog(null,"Port(0-65535):","Port",JOptionPane.QUESTION_MESSAGE);

     portnumber = tryParse(text);

}while(portnumber==0);


查看完整回答
反對(duì) 回復(fù) 2021-07-14
  • 1 回答
  • 0 關(guān)注
  • 170 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)