📄 frame1.java~40~
字号:
package udpclient;import java.awt.*;import java.awt.event.*;import javax.swing.*;import java.net.*;import java.io.*;import java.util.*;/** * <p>Title: </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2002</p> * <p>Company: </p> * @author unascribed * @version 1.0 */public class Frame1 extends JFrame { JPanel contentPane; byte[] sendBuf =new byte[256]; DatagramPacket packet; InetAddress address; int port; DatagramSocket socket=null; TextField textField1 = new TextField(); TextField textField2 = new TextField(); Button button1 = new Button(); //Construct the frame public Frame1() { enableEvents(AWTEvent.WINDOW_EVENT_MASK); try { jbInit(); /*if(args.length!=2) { System.out.println("usage:java quoteClient <hostname><port#>"); return; }*/ } catch(Exception e) { e.printStackTrace(); } } //Component initialization private void jbInit() throws Exception { //setIconImage(Toolkit.getDefaultToolkit().createImage(Frame1.class.getResource("[Your Icon]"))); contentPane = (JPanel) this.getContentPane(); textField1.setText("textField1"); textField1.setBounds(new Rectangle(83, 39, 190, 29)); contentPane.setLayout(null); this.setSize(new Dimension(400, 300)); this.setTitle("Frame Title"); textField2.setText("textField2"); textField2.setBounds(new Rectangle(81, 83, 192, 28)); button1.setLabel("button1"); button1.setBounds(new Rectangle(115, 196, 124, 40)); button1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { button1_actionPerformed(e); } }); contentPane.add(textField1, null); contentPane.add(textField2, null); contentPane.add(button1, null); } //Overridden so we can exit when window is closed protected void processWindowEvent(WindowEvent e) { super.processWindowEvent(e); if (e.getID() == WindowEvent.WINDOW_CLOSING) { System.exit(0); } } void button1_actionPerformed(ActionEvent e) { try { socket=new DatagramSocket(); } catch(java.io.IOException ee) { System.err.println("Could not create Datagram socket."); } if(socket!=null) { try { port=1139;//Integer.parseInt(1037); address=InetAddress.getLocalHost(); packet=new DatagramPacket(sendBuf,256,address,port); socket.send(packet); packet=new DatagramPacket(sendBuf,256);System.out.println(packet); socket.receive(packet);System.out.println(packet); String received=new String(packet.getData()); System.out.println("hello"); System.out.println("Quote of the Moment:"+received); socket.close(); } catch(IOException fe) { System.err.println("IOException:"+fe); fe.printStackTrace(); } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -