JAVA Swing教学PPT
- 格式:ppt
- 大小:644.00 KB
- 文档页数:35
JAVA开发培训讲义(Swing入门).pptSwing初级知识的事件机制桌面应用程序展示界面所用一套组件。
与平台无关丰富的层次结构适应编写丰富用户感受的界面是我们开发软件的最主要界面表现形式Component Container JComponentJCheckBox JRadioButton JButtonWindowFrame JFrameJMenuBarJToolBarJTabbedPanelJComboBoxJLabelJProcessBarJTableJTreeJTextField类型|长宽Key | Focus | paint上层组件的基类行高|颜色|字体|布局|类最基本的事件:Mouse|Key | Focus |paintpaintComponents(Graphics g)|如果有子组件8 int Sy = (rec.height -hh)/2;9 if ( im instanceof ImageIcon ){10 ImageIcon pImage = (ImageIcon)im;g.drawImage(pImage.getImage(), Sx, Sy,ww,hh,this);14 im.paintIcon( null,g2, Sx, Sy );2 public void mousePressed(MouseEvent e);3 public void mouseReleased(MouseEvent e);4 public void mouseEntered(MouseEvent e);Listener(…)加入事件侦听JComponent.addMouseListener( Listener(…)加入事件侦听JComponent.addKeyListener()加入事件侦听它组件|显示图片套的方式实现复杂界面布局于分组组件布局1 border1 = BorderFactory.createEtchedBorder(Color.white,new Color(148, 145, 140));2 titledBorder1 = new TitledBorder(border1,"带标题的Panel");容纳更多的信息图标、标题之前标签内容”);2 CLCaption.setText(“新的标签内容”);3 CLCaption.setIcon(…);2 CEField.addCaretListener(new CaretListener() {public void caretUpdate(CaretEvent e) {如果改变了内容,就可以即时更新label 显示的内容label.setText(textField.getText());8 CEField.select(0,0);。