¡¶Java»ù´¡ÈëÃÅ¡·¿ÎºóÏ°Ìâ¼°´ð°¸

²©Ñ§¹È¡ª¡ªÈÃIT½Ìѧ¸ü¼òµ¥£¬ÈÃITѧϰ¸üÓÐЧ

}

}

public static void main(String[] args) { }

new Information();

// Ϊµ¥Ñ¡ºÍ¸´Ñ¡°´Å¥Ìí¼Óʼþ¼àÌýÆ÷ cb1.addActionListener(listener1); cb2.addActionListener(listener1); cb3.addActionListener(listener1); rb1.addActionListener(listener2); rb2.addActionListener(listener2);

// ½«JPanelÃæ°åºÍJScrollPaneÃæ°åÌí¼Óµ½JFrameÈÝÆ÷ÖÐ Container container = this.getContentPane(); container.add(panel, BorderLayout.NORTH); container.add(pane, BorderLayout.CENTER); this.pack();

this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setVisible(true);

3¡¢±àдһ¸öJFrame´°¿Ú£¬ÒªÇóÈçÏ£º

1£©´°¿Ú°üº¬Ò»¸ö²Ëµ¥À¸ºÍÒ»¸öJLabel±êÇ©¡£

2£©²Ëµ¥À¸ÖÐÓÐÁ½¸ö²Ëµ¥£¬µÚÒ»¸ö²Ëµ¥ÓÐÁ½¸ö²Ëµ¥ÏËüÃÇÖ®¼äÓ÷ָô·û·Ö¿ª£¬µÚ¶þ¸ö²Ëµ¥ÓÐÒ»¸ö

²Ëµ¥Ïî¡£

3£©JLabel±êÇ©·ÅÖÃÔÚ´°¿ÚµÄÖмä(¼´BorderLayout.CENTER)£¬µ±µã»÷²Ëµ¥ÏîµÄʱºò£¬²Ëµ¥ÏîÖеÄ

Îı¾ÏÔʾµÄJLabel±êÇ©ÖС£

²Î¿¼´ð°¸

import javax.swing.*; import java.awt.*; import java.awt.event.*;

public class MyMenu extends JFrame implements ActionListener {

JLabel label = new JLabel(\ÇëÑ¡Ôñ²Ëµ¥\JMenuItem aaMenuItem, baMenuItem; MyMenu() {

JMenuBar menuBar = new JMenuBar(); JMenu aMenu = new JMenu(\²Ëµ¥A\JMenu bMenu = new JMenu(\²Ëµ¥B\

JMenuItem aaMenuItem = new JMenuItem(\²Ëµ¥Ïî AA\JMenuItem abMenuItem = new JMenuItem(\²Ëµ¥ÏîAB\

²©Ñ§¹È¡ª¡ªÈÃIT½Ìѧ¸ü¼òµ¥£¬ÈÃITѧϰ¸üÓÐЧ

}

public void actionPerformed(ActionEvent e) { }

public static void main(String args[]) {

JFrame frame = new MyMenu();

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(300, 200); frame.setVisible(true);

JMenuItem source = (JMenuItem) (e.getSource()); label.setText(\Ñ¡ÔñÁ˲˵¥:\label.setHorizontalAlignment(JLabel.CENTER); JMenuItem baMenuItem = new JMenuItem(\²Ëµ¥Ïî BA\menuBar.add(aMenu); menuBar.add(bMenu); aMenu.add(aaMenuItem); aMenu.addSeparator(); aMenu.add(abMenuItem); bMenu.add(baMenuItem);

aaMenuItem.addActionListener(this); abMenuItem.addActionListener(this); baMenuItem.addActionListener(this); setJMenuBar(menuBar);

getContentPane().add(label, BorderLayout.CENTER);

}

µÚ10Õ ÍøÂç±à³Ì

Ò»¡¢Ìî¿ÕÌâ

1¡¢TCPЭÒéµÄÌصãÊÇ ÃæÏòÁ¬½Ó £¬¼´ÔÚ´«ÊäÊý¾ÝÇ°ÏÈÔÚ ¿Í»§¶Ë ºÍ ·þÎñÆ÷¶Ë ½¨Á¢Âß¼­Á¬½Ó¡£

2¡¢ÔÚ¼ÆËã»úÖУ¬¶Ë¿ÚºÅÊÇÓà 2 ×Ö½Ú£¬Ò²¾ÍÊÇ16λµÄ¶þ½øÖÆÊý±íʾ£¬ËüµÄÈ¡Öµ·¶Î§ÊÇ 0-65535 ¡£

3¡¢TCP/IPЭÒé±»·ÖΪËĸö²ã£¬·Ö±ðÊÇ Á´Â·²ã ¡¢ ÍøÂç²ã ¡¢ ÔËÊä²ã ¡¢ Ó¦Óò㠡£ 4¡¢ÔÚJDKÖУ¬IPµØÖ·Óà InetAddress ÀàÀ´±íʾµÄ£¬¸ÃÀàÌṩÁËÐí¶àºÍIPµØÖ·Ïà¹ØµÄ²Ù×÷¡£¡£ 5¡¢Ê¹ÓÃUDPЭÒ鿪·¢ÍøÂç³ÌÐòʱ£¬ÐèҪʹÓÃÁ½¸öÀ࣬·Ö±ðÊÇ DatagramPacket ºÍ

ÁªÏµ¿Í·þ£º779662525#qq.com(#Ì滻Ϊ@)