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

您没有登录

» Java开发网 » Java GUI 设计  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 请看这个JAVA程序为什么不能用相对坐标来画?
22750124





发贴: 17
积分: 0
于 2005-07-17 19:48 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
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

class CropPicturePanel extends JPanel
{
  int xOne=((int)this.getSize().getWidth())*(1/25),
    xTwo=((int)this.getSize().getWidth())*(3/25),
    xThree=((int)this.getSize().getWidth())*(5/25),
    xFour=((int)this.getSize().getWidth())*(7/25),
    xFive=((int)this.getSize().getWidth())*(9/25),
    xSix=((int)this.getSize().getWidth())*(11/25),
    xSeven=((int)this.getSize().getWidth())*(13/25),
    xEight=((int)this.getSize().getWidth())*(15/25),
    xNine=((int)this.getSize().getWidth())*(17/25),
    xTen=((int)this.getSize().getWidth())*(19/25),
    xEleven=((int)this.getSize().getWidth())*(21/25),
    xTwelve=((int)this.getSize().getWidth())*(23/25);
  
  int width=((int)this.getSize().getWidth())*(1/50);
  
  int heightOne=(int)this.getSize().getHeight()*(19/20)*(int)Math.random(),
    heightTwo=(int)this.getSize().getHeight()*(19/20)*(int)Math.random(),
    heightThree=(int)this.getSize().getHeight()*(19/20)*(int)Math.random(),
    heightFour=(int)this.getSize().getHeight()*(19/20)*(int)Math.random(),
    heightFive=(int)this.getSize().getHeight()*(19/20)*(int)Math.random(),
    heightSix=(int)this.getSize().getHeight()*(19/20)*(int)Math.random(),
    heightSeven=(int)this.getSize().getHeight()*(19/20)*(int)Math.random(),
    heightEight=(int)this.getSize().getHeight()*(19/20)*(int)Math.random(),
    heightNine=(int)this.getSize().getHeight()*(19/20)*(int)Math.random(),
    heightTen=(int)this.getSize().getHeight()*(19/20)*(int)Math.random(),
    heightEleven=(int)this.getSize().getHeight()*(19/20)*(int)Math.random(),
    heightTwelve=(int)this.getSize().getHeight()*(19/20)*(int)Math.random();
    
  int yOne=(int)this.getSize().getHeight()-heightOne,
    yTwo=(int)this.getSize().getHeight()-heightTwo,
    yThree=(int)this.getSize().getHeight()-heightThree,
    yFour=(int)this.getSize().getHeight()-heightFour,
    yFive=(int)this.getSize().getHeight()-heightFive,
    ySix=(int)this.getSize().getHeight()-heightSix,
    ySeven=(int)this.getSize().getHeight()-heightSeven,
    yEight=(int)this.getSize().getHeight()-heightEight,
    yNine=(int)this.getSize().getHeight()-heightNine,
    yTen=(int)this.getSize().getHeight()-heightTen,
    yEleven=(int)this.getSize().getHeight()-heightEleven,
    yTwelve=(int)this.getSize().getHeight()-heightTwelve;
    
    public CropPicturePanel()
    {
      repaint();
    }
  
  public void paintComponent(Graphics g)
  {
    g.drawRect(xOne,yOne,width,heightOne);
    g.drawRect(xTwo,yTwo,width,heightTwo);
    g.drawRect(xThree,yThree,width,heightThree);
    g.drawRect(xFour,yFour,width,heightFour);
    g.drawRect(xFive,yFive,width,heightFive);
    g.drawRect(xSix,ySix,width,heightSix);
    g.drawRect(xSeven,ySeven,width,heightSeven);
    g.drawRect(xEight,yEight,width,heightEight);
    g.drawRect(xNine,yNine,width,heightNine);
    g.drawRect(xTen,yTen,width,heightTen);
    g.drawRect(xEleven,yEleven,width,heightEleven);
    g.drawRect(xTwelve,yTwelve,width,heightTwelve);
  }
}

public class CropPicture extends JFrame
{
  public CropPicture()
  {
    JLabel titleLabel=new JLabel("2005年石油产量图",JLabel.CENTER);
    CropPicturePanel p=new CropPicturePanel();
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container c=this.getContentPane();
    c.add(p,BorderLayout.CENTER);
    c.add(titleLabel,BorderLayout.NORTH);
    this.setSize(500,350);
    this.setVisible(true);
  }
  
  public static void main(String[] args)
  {
    new CropPicture();
  }
}




SWT Designer v1.2.3 Released!

话题树型展开
人气 标题 作者 字数 发贴时间
3705 请看这个JAVA程序为什么不能用相对坐标来画? 22750124 3469 2005-07-17 19:48
2585 Re:请看这个JAVA程序为什么不能用相对坐标来画? 22750124 67 2005-07-17 19:51

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