public class DoGraph extends javax.swing.JFrame {
/** Creates new form Back */
;
public DoGraph() {
initComponents();
this.setSize(600, 400);
}
// public void paint(java.awt.Graphics g) {
// super.paint(g);
// Graphics2D g2 = (Graphics2D) g;
// g2.setBackground(Color.white);
// }
private void initComponents() {
// addWindowListener(new java.awt.event.WindowAdapter() {
// public void windowClosing(java.awt.event.WindowEvent evt) {
// exitForm(evt);
// }
// });
javax.swing.JPanel background=new Back();
this.getContentPane().add(background);
}
/** Exit the Application */
private void exitForm(java.awt.event.WindowEvent evt) {
System.exit(0);
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
new DoGraph()
.setVisible(true);
}
}
public class Back extends javax.swing.JPanel {
public Back() {
// this.setVisible(true);
}
public void paint(java.awt.Graphics g) {
super.repaint();
super.paint(g);
Graphics2D g2 = (Graphics2D) g;
this.setOpaque(true);
this.setBounds(100, 150, 200, 200);
double maxx=getHeight();
double maxy=getWidth();
System.out.println(maxx+"能不能");
// System.out.println(maxy+"能不能");
// System.out.println(getX());
// System.out.println(getY());
g2.translate(100+maxy/2, 150+maxx/2);
g2.setBackground(Color.white);
g2.setColor(Color.green);
g2.drawLine(0, 0, 0, -(int)maxx);
g2.drawLine(0, 0, (int)maxy, 0);
g2.setColor(Color.red);
int[] a=new int[10];
for(int i=0;i<10;i++){
a[i]=i;
}
int[] b=new int[10];
b[0]=0 ;
b[1]=16 ;
b[2]=18 ;
b[3]=46 ;
b[4]=55 ;
b[5]= 76;
b[6]= 88;
b[7]= 38;
b[8]= 10;
b[9]= 20;
for(int i=0;i<9;i++){
g2.drawLine(a[i], -b[i], a[i+1], -b[i+1]);
}
g2.rotate(Math.toRadians(90));
}
}
运行的时候为什么曲线闪一下就没了,而且控制台输出了两次