計算機網(wǎng)絡(luò)第五次作業(yè)

完成一個ping的GUI界面的小程序:

???? ?新建窗口,設(shè)置窗口的大小。添加Label控件,設(shè)置字體和調(diào)整控件所處的位置。添加文本域,設(shè)置文本域的大小和位置,用來顯示輸出信息。添加文本控件,設(shè)置文本控件的大小和位置,用來輸入IP地址。添加Button控件,設(shè)置Button控件的大小和位置,編寫B(tài)utton控件的監(jiān)聽事件,用來獲取文本框輸入的IP地址,然后調(diào)用ping函數(shù),用來pingIP地址。

frame = new JFrame("PING");

frame.setBounds(300, 400, 600, 700);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.getContentPane().setLayout(null);

JLabel lblNewLabel = new JLabel("IP地址");

lblNewLabel.setBounds(14, 573, 100, 50);

lblNewLabel.setFont(new Font("宋體",Font.PLAIN,20));

frame.getContentPane().add(lblNewLabel);//添加Label控件

textField = new JTextField();

textField.setBounds(104, 580, 300, 40);

frame.getContentPane().add(textField);

textField.setColumns(10);

JButton btnNewButton = new JButton("運行");

btnNewButton.setBounds(439, 578, 113, 40);

btnNewButton.setFont(new Font("宋體",Font.PLAIN,20));

frame.getContentPane().add(btnNewButton);

scrollPane.setBounds(0, 0, 582, 515);

frame.getContentPane().add(scrollPane);

JTextArea textArea = new JTextArea();

scrollPane.setViewportView(textArea);

btnNewButton.addActionListener(new ActionListener(){//Button的監(jiān)聽事件

@Override

public void actionPerformed(ActionEvent e) {

// TODO Auto-generated method stub

String content=textField.getText();

new Thread(new Runnable() {

@Override

public void run() {

Ping.ping02(textArea, content);

}

}).start();;

}


最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容