Topic: 请看这个JAVA程序为什么不能用相对坐标来画?

  Print this page

1.请看这个JAVA程序为什么不能用相对坐标来画? Copy to clipboard
Posted by: 22750124
Posted on: 2005-07-17 19:48

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();
  }
}

2.Re:请看这个JAVA程序为什么不能用相对坐标来画? [Re: 22750124] Copy to clipboard
Posted by: 22750124
Posted on: 2005-07-17 19:51

谢谢大家了~
此程序目的是想用相对坐标画12的长方形,Height为随机的
(顺便问一下。有没有可以画带阴影的柱形的方法~感谢了)


   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