lizhizuoyongzhe 2015-06-03 10:19 采纳率: 20%
浏览 1671

怎么将java swing中画的曲线缩小啊

public class PGraph extends javax.swing.JPanel {

/** Creates new form PGraph */
public PGraph() {
    initComponents();
}
public PGraph(double[] a,double[] b){
    initComponents();
}
private double[] c;
private double[] d;
private AffineTransform at = new AffineTransform();   

/** This method is called from within the constructor to
 * initialize the form.
 * WARNING: Do NOT modify this code. The content of this method is
 * always regenerated by the Form Editor.
 */
//GEN-BEGIN:initComponents
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
    this.setLayout(layout);
    layout.setHorizontalGroup(layout.createParallelGroup(
            javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 400,
            Short.MAX_VALUE));
    layout.setVerticalGroup(layout.createParallelGroup(
            javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 300,
            Short.MAX_VALUE));
}// </editor-fold>
//GEN-END:initComponents

//GEN-BEGIN:variables
// Variables declaration - do not modify
// End of variables declaration//GEN-END:variables
public void paint(java.awt.Graphics g){
    super.paint(g);
    Graphics2D g2 = (Graphics2D) g;
    g2.setBackground(Color.white);
    g2.setColor(Color.red);

// this.setBounds(250, 250, 200, 300);
double maxx=this.getHeight();
double maxy=this.getWidth();
double xx=this.getX();
double yy=this.getY();
System.out.println(maxx+"能不能");
System.out.println(this.getX()+"能不能2");
g2.translate(0, maxx-20);
g2.setBackground(Color.white);
g2.setColor(Color.green);
g.drawLine(0, 0, 0, -(int)maxx);
g.drawLine(0, 0, (int)maxy, 0);
g2.setColor(Color.BLACK);
g.drawLine(20, 0, 20, 10);
for(int i=0;i<101;i++){

g.drawString(i+"", i*30, 20);
g.drawString(i+"", 10, -i*30);
}
g.drawLine(0, -20, 10, -20);
g.setColor(Color.red);
double[] lea=new double[100];
double[] leak=new double[100];
for(int f=0;f<100;f++){
leak[f]=f*30;
}
SPBPXiShu spb=new SPBPXiShu();
double u=0;
for(int i=0;i<100;i++){
lea[i]=u*30;
u+=3.4;
}
c=leak;
d=lea;
for(int i=1;i<c.length;i++){

g.drawLine((int)c[i-1], (int)-d[i-1], (int)c[i], (int)-d[i]);
}

g2.rotate(Math.toRadians(90));
// g2.scale(1/10, 1/10);
at=g2.getTransform();
at.scale(1/2.0, 1/2.0);
}

}

为什么这么写曲线不会缩小 求大神给个缩小曲线的代码

  • 写回答

1条回答 默认 最新

  • 大树底下的苹果 2015-06-26 08:03
    关注

    只能修改关键参数重绘啊

    评论

报告相同问题?

悬赏问题

  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)