Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Java GUI 设计  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
话题被移动
该话题已被移动 - littledeer1974 , 2005-09-27 14:12
如果您尚不清楚该话题被移动的原因,请参考论坛规则以及本版公告或者联系本版版主。
作者 [j2se]急 .问一个关于GlassPane的问题
yudinosaur





发贴: 2
积分: 0
于 2005-09-27 11:35 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
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()));
  }
}


littledeer1974 edited on 2005-09-27 14:12


CJSDNer6月14日北京聚会花絮

话题树型展开
人气 标题 作者 字数 发贴时间
3526 [j2se]急 .问一个关于GlassPane的问题 yudinosaur 3084 2005-09-27 11:35
2663 Re:[j2se]急 .问一个关于GlassPane的问题 snowbug 26 2005-09-30 04:52

flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   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