Topic: [j2se]急 .问一个关于GlassPane的问题

  Print this page

1.[j2se]急 .问一个关于GlassPane的问题 Copy to clipboard
Posted by: yudinosaur
Posted on: 2005-09-27 11:35

1这个程序为什么只显示GlassPane上的效果,却把后边的东西全部遮住了啊,高手指点啊!
2还有想请教一下谁有关于JAVA格式规范的资料,能提供一下吗?(感觉写JAVA时前后文顺序不一样会有很大影响).
程序:

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class GlassPaneTest extends JFrame {
  private JLayeredPane jlp;
  public JButton[] jb=new JButton[5];
  public static void main(String args[]){
    GlassPaneTest test=new GlassPaneTest();
    test.setSize(300,200);
    test.setVisible(true);
  }
  public GlassPaneTest(){
    String[] layer={"default","palette","modal","popup","drag"};
    jlp=getLayeredPane();
    for(int i=0;i<5;i++){
      jb[i]=new JButton(layer[i]);
      jb[i].setBounds(i*50,i*20,80,60);
      jlp.add(jb[i]);
      jlp.setLayer(jb[i],i*100);
      
    }
    GlassPane glass=new GlassPane(jlp);

    setGlassPane(glass);
    glass.setVisible(true);
  }

}
class GlassPane extends Component implements MouseListener,MouseMotionListener{
  private int mx,my;
  private JLayeredPane jlp;
  public GlassPane(JLayeredPane p){
    mx=my=-99;
    jlp=p;
    addMouseListener(this);
    addMouseMotionListener(this);
  }
  public void paint(Graphics g){
    g.fillOval(mx-5,my-5,10,10);
  }
  public void mouseClicked(MouseEvent e){
    redispatchMouseEvent(e);
  }
  public void mouseEntered(MouseEvent e){
    redispatchMouseEvent(e);
  }
  public void mouseExited(MouseEvent e){
    redispatchMouseEvent(e);
  }
  public void mousePressed(MouseEvent e){
    redispatchMouseEvent(e);
  }
  public void mouseReleased(MouseEvent e){
    redispatchMouseEvent(e);
  }
  public void mouseDragged(MouseEvent e){
    redispatchMouseEvent(e);
  }
  public void mouseMoved(MouseEvent e){
    mx=e.getX();
    my=e.getY();
    repaint();
  }
  public void redispatchMouseEvent(MouseEvent e){
    Point point=e.getPoint();
    Component component=jlp.getComponentAt(point);
    if(component!=null)
      component.dispatchEvent(new MouseEvent(component,e.getID(),e.getWhen(),e.getModifiers(),point.x,point.y,e.getClickCount(),e.isPopupTrigger()));
  }
}

2.Re:[j2se]急 .问一个关于GlassPane的问题 [Re: yudinosaur] Copy to clipboard
Posted by: snowbug
Posted on: 2005-09-30 04:52

glasspane.setOpaque(false)


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923