c语言java实效编程百例_第1页
c语言java实效编程百例_第2页
c语言java实效编程百例_第3页
c语言java实效编程百例_第4页
c语言java实效编程百例_第5页
已阅读5页,还剩333页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、Java CIPJava / . ü2003.4 ISBN 7115107955JJAVA üTP312佚 CIP 2003 015137 -DYD -DYD %HDQV -DYD 偠Java 100061315儖787h109221.25518 1ü0 000 1/162003 3 1 2003 3 1 ISBN 7-115-10795-5/TPg317435.00 乬 01067129223 催偠 乪 -DYD $3, 催 -DYD -DYD %HDQV 偸züüzüü züü乥咘 乎吣偀乎1 2 W

2、eb 45 IE 81012亢1417 1 2 3 4 5 6 7 819 乥20乥22乥25 Windows 3136394142444751535658 9 10 11 12 13 14 15 16 17 18 19 20 21 2262 63646667偀7174767980哴82 23 24 25 26 27 28 29 30 31 3286 87889092 33 34 35 369597100 Zip 103 37 38 39 40108 偅109 41 42 43 44 45 46 47 48 49 50 51 52 53 DB2 110112113115116 SQL 1201

3、22124 SQL Server 128 Servelt 130 Servlet 义132 Oracle 135141 IP 143 IP 143144 IP 145146149 URL 义150 URL 151 URL 义 URL 152义158 URL 义159 Internet 160161164义166义169义171义催173 TCP 177 Socket 178 Echo 180 Finger 181 Whois 183184 DayTime 186 Time 187 Web 189 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 7

4、0 71 72 73 74 75 76 77 78 79 8022 Web 193 Web 197 Web 200 Https Web 207 SSL 208 UDP 211 UDP discard 212 UDP discard 214 UDP 215 UDP Echo 217 Echo 219223 RMI 226 81 82 83 84 85 86 87 88 89 90 91 92 93229 230233 94 95 96 97 98 99 100 101 102 103 104 105 106 107义. 236 POP3 240 IMAP Flags242246249254 PO

5、P3 259FTP 266 Telnet 271 C/S 279 TFTP 287289%HDQV299 108 109 110 111 112 113 114 115 116 117-DYD Bean 300 Bean URL304306310315321322 Unicode 3233263283313 :HE ,( 亢 1Swing JLabel javax.swing.border Swing EmptyBorderBevelBorderEtchedBorderLineBorder乬TitledBorderCompoundBorder 1-1 1-1 javax.swing.borde

6、r.Border OwnBorderBorder Swing getBorderInsets() Insets isBorderOpaque() 买paintBorder() Border c g xy widthheight 催1 Project JLabelDemo12 Application JLabelDemo1 MainFrame乬 JLabelDemo13 OwnBorder javax.swing.border.Border 2import java.awt.*;import javax.swing.border.*;class OwnBorder implements java

7、x.swing.border.Borderpublic interface Border Insets getBorderInsets(Component c); boolean isBorderOpaque();void paintBorder(Component c, Graphics g, int x, int y, int width, int height); 4 MainFrame 6 JLabel contentPane GridLayout 5 jbInit() GridLayoutJLabel JLabel OwnBorder 3private void jbInit() t

8、hrows Exception / gidLayout1 2 3 gridLayout1.setColumns(3); gridLayout1.setRows(2);/ JLabel jLabel1.setFont(new java.awt.Font("Dialog", 0, 14);public class MainFrame extends JFrame .private GridLayout gridLayout1 = new GridLayout(); private JLabel jLabel1 = new JLabel();private JLabel jLab

9、el2 = new JLabel(); private JLabel jLabel3 = new JLabel(); private JLabel jLabel4 = new JLabel(); private JLabel jLabel5 = new JLabel(); private JLabel jLabel6 = new JLabel();.private int thickness; / private Color color; /买/*买*/public OwnBorder(int thickness,Color color) this.thickness=thickness; t

10、his.color=color;/* Border */public void paintBorder(Component c,/Graphics g, / int x, int y, /int width, int height) /g.setColor(this.color);/买g.fill3DRect(x,y,width-thickness,thickness,true); / g.fill3DRect(x,y+thickness,thickness,height-thickness,true); /g.fill3DRect(x+thickness,y+height-thickness

11、,width-thickness,thickness,true); / g.fill3DRect(x+width-thickness,y,thickness,height-thickness,true); /* Border * Insets */public Insets getBorderInsets(Component c)return new Insets(thickness,thickness,thickness,thickness);/* Border * true,买*/public boolean isBorderOpaque() return true; 2 Web Web

12、1-2 Web IE乏咬义 1-2 Web java.lang Runtime Web Runtime Runtime getRuntime() Runtime 4static Runtime getRuntime(); Process exec(Stringd);jLabel1.setHorizontalAlignment(SwingConstants.CENTER); jLabel1.setText("jLabel2");jLabel2.setFont(new java.awt.Font("Dialog", 0, 14); jLabel2.setHo

13、rizontalAlignment(SwingConstants.CENTER); jLabel2.setText("jLabel2");jLabel3.setFont(new java.awt.Font("Dialog", 0, 14); jLabel3.setHorizontalAlignment(SwingConstants.CENTER); jLabel3.setText("jLabel3");jLabel4.setFont(new java.awt.Font("Dialog", 0, 14); jLabe

14、l4.setHorizontalAlignment(SwingConstants.CENTER); jLabel4.setText("jLabel4");jLabel5.setFont(new java.awt.Font("Dialog", 0, 14); jLabel5.setHorizontalAlignment(SwingConstants.CENTER); jLabel5.setText("jLabel5");jLabel6.setFont(new java.awt.Font("Dialog", 0, 14

15、); jLabel6.setHorizontalAlignment(SwingConstants.CENTER); jLabel6.setText("jLabel6");/ JLabel jLabel1.setBorder(new OwnBorder(10,Color.blue); jLabel2.setBorder(new OwnBorder(15,Color.red);jLabel3.setBorder(new OwnBorder(20,Color.orange); jLabel4.setBorder(new OwnBorder(25,Color.yellow); jL

16、abel5.setBorder(new OwnBorder(30,Color.green); jLabel6.setBorder(new OwnBorder(35,Color.white); Runtime.getRuntime() Runtime exec()d Windows NTWindows 2000 Windows XP dcmd /c start 乏 cmd Windows 98 Windows ME d 1 Project JLabelDemo22 Application JLabelDemo2 MainFrame 乬JLabelDemo23 MainFrame JLabel 4

17、 jLabel1 哴 3 1-3 5void jLabel1_mouseReleased(MouseEvent e) tryRuntime.getRuntime().exec("cmd /c start"); /义catch(Exception err)err.printStackTrace();public class MainFrame extends JFrame private JLabel jLabel1 = new JLabel();private void jbInit() throws Exception /jLabel1 jLabel1.setToolTi

18、pText(""); jLabel1.setDisplayedMnemonic('0'); jLabel1.setHorizontalAlignment(SwingConstants.CENTER);jLabel1.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR); /哴 jLabel1.setText("<html><body><font size=10 ><a href=> </a></font></bo

19、dy></html>"); /哴 mouseReleased jLabel1.addMouseListener(new java.awt.event.MouseAdapter() public void mouseReleased(MouseEvent e) jLabel1_mouseReleased(e););Runtime.getRuntime.exec(“cmd /c start”); 1-3 javax.swing.ListCellRenderer OwnCellRendererOwnCellRenderer JLabel 1-3 JLabel ListCe

20、llRenderer getListCellRendererComponent() OwnCellRenderer Component JLabel this getListCellRendererComponent list JList list.getSelectionBackground(),list.getSelection Foreground() value list.getM().getElementAt(index)String index isSelected cellHasFocus java.lang.ClassLoader getSystemResource() Cla

21、ssLoader ClassLoader.getSystemResource(String name)name URL name class c:myProjectsJListDemo 1-3-1.jpg images 1-3-1.jpg URL 1 Project JListDemo2 Application JListDemo MainFrame乬 JListDemo 3 OwnCellRenderer javax.swing.JLabel wizards|implements javax.swing.ListCellRenderer OwnCellRenderer 6import jav

22、a.awt.*; import javax.swing.*;URL url=ClassLoader.getSystemResource("images/1-3-1.jpg");static URL getSystemResource(String name);public Component getListCellRendererComponent(JList list,Object value,int index,Boolean isSelected,Boolean cellHasFocus); 4 OwnCellRenderer 5 OwnCellRenderer ge

23、tListCellRendererComponent6 MainFrame JList 7import java.awt.*; import java.awt.event.*; import javax.swing.*;class JListDemo extends JFrame String iconnames="","","偅","","","" / JList list;/ /ClassLoader.getSystemResource() class ,”images/

24、1-3-1.jpg”,class / images 1-3-1.jpg Icon icon1=new ImageIcon(ClassLoader.getSystemResource("images/1-3-1.jpg"); Icon icon2=new ImageIcon(ClassLoader.getSystemResource("images/1-3-2.jpg"); Icon icon3=new ImageIcon(ClassLoader.getSystemResource("images/1-3-3.jpg"); Icon i

25、con4=new ImageIcon(ClassLoader.getSystemResource("images/1-3-4.jpg"); Icon icon5=new ImageIcon(ClassLoader.getSystemResource("images/1-3-5.jpg"); Icon icon6=new ImageIcon(ClassLoader.getSystemResource("images/1-3-6.jpg");/*/public Component getListCellRendererComponent(

26、 JList list,Object value, int index,boolean isSelected, boolean cellHasFocus)if(value!=null)String text = value.toString(); this.setText(text);/this.setIcon(iconsindex);/ if(isSelected)/买咬this.setBackground(list.getSelectionBackground(); this.setForeground(list.getSelectionForeground();else/买咬买this.

27、setBackground(list.getBackground();this.setForeground(list.getForeground();return this; / /*/public OwnCellRenderer(Icon icons)this.icons = icons; this.setOpaque(true);this.setFont(new Font("Dialog",Font.PLAIN,14);class OwnCellRenderer extends JLabel implements ListCellRenderer.Icon icons;

28、/ 7 MainFrame jbInit() OwnCellRenderer list 4 IE Microsoft Windows Web IE IE 义 javax.swing JComboBox 1-4 IE JLabel JComboBox JComboBox 咬 JComboBox ActionEvent JComboBox 咬 javax.swing.ComboBoxEditor 1 Project JComboBoxDemo2 Application JComboBoxDemo MainFrame乬 JComboBoxDemo3 MainFrame JComboBox JLabe

29、l 8public class MainFrame extends JFrame private JPanel contentPane;private BorderLayout borderLayout1 = new BorderLayout();/*/private void jbInit() throws Exception .Icon icons=icon1,icon2,icon3,icon4,icon5,icon6;list=new JList(iconnames); / iconnames list.setCellRenderer(new OwnCellRenderer(icons)

30、; / list /OwnCellRenderer this.getContentPane().add(new JScrollPane(list); / list JScrollPane 4 MainFrame jbInit() jComboBox1jLabel1 5 JComboBoxDemo ComboxListener ActionListener 9class ComboxListener implementionListener/* ActionListener */ public void actionPerformed(ActionEvent e)boolean isItemPr

31、esent = false;/ isItemPresent false for(int i=0;i<combox.getItemCount();i+)if(combox.getItemAt(i).equals(combox.getSelectedItem() isItemPresent=false;private void jbInit() throws Exception /setIconImage(Toolkit.getDefaultToolkit().createImage(MainFrame.class.getResource("Your Icon"); co

32、ntentPane = (JPanel) this.getContentPane();/ jLabel1 jLabel1.setFont(new java.awt.Font("Dialog", 0, 14); jLabel1.setHorizontalAlignment(SwingConstants.CENTER); jLabel1.setText(" ");/ jComboBox1 jComboBox1.setFont(new java.awt.Font("Dialog", 0, 14);/*JComboBox true URL*/

33、jComboBox1.setEditable(true);jComboBox1.seumRowCount(5); / 5 jComboBox1.configureEditor(jComboBox1.getEditor(),defaultEdit); /咬 defaultEdit ComboBoxEditor comboxEditor=jComboBox1.getEditor();/咬 ComboBoxEditor Component editorComp = comboxEditor.getEditorComponent();/ editorComp.setBackground(Color.w

34、hite); editorComp.setForeground(Color.red); editorComp.setFont(new Font("Dialog",Font.PLAIN,14);/ jComboBox1 ActionListener,ComboxListener ActionListener / jComboBox1.addActionListener(new ComboxListener()contentPane.add(jLabel1, BorderLayout.WEST); contentPane.add(jComboBox1, BorderLayout

35、.CENTER);/*""*/private JLabel jLabel1 = new JLabel();/*咬*/ private String defaultSites=",",",","/*/咬*/private String defaultEdit="/* JComboBox defaultSites */ private JComboBox jComboBox1 = new JComboBox(defaultSites); 5 Microsoft Word Borland JBuilder 1-5 wai

36、ting 0 1-5 乬 JFrame JWindow Window swing 1-5 java.awt MediaTracker 1 Project JSpleshWindowDemo咬2 Application JSpleshWindowDemo MainFrame乬 JSpleshWindowDemo10break;/ isItemPresent JComboBox if(!isItemPresent)combox.insertItemAt(combox.getSelectedItem(),0); isItemPresent=false; 3 SpleshWindow.java java.swing.J

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论