问题描述
- 怎么将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);
}}
为什么这么写曲线不会缩小 求大神给个缩小曲线的代码
解决方案
只能修改关键参数重绘啊