Java_GUI中实现paintComponent方法并画背景图片和曲线的方法

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.Line2D;
import java.awt.geom.Point2D;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;

import javax.swing.ImageIcon;
import javax.swing.JPanel;
public class PaintComponentTestData extends JPanel implements Runnable{
			Object obj = new Object();
			private static final long serialVersionUID = 1L;
			private Line2D line;
			private Point2D start;
			private Point2D end;
			
			private String dir = null;
			private String Name = null;
			double start_x = 7 ,start_y = 350;
			double end_x = 70,end_y  = 350;
			int i=0,count = 1;
			boolean flag = true;
			boolean Flag = true;
			public ArrayList list = new ArrayList();
			ImageIcon MyImage = null;
			PaintComponentTestData(String dir,String Name){
				this.dir = dir;
				this.Name = Name;
				MyImage = new ImageIcon("Face-MyWindow.gif");
			}
			public void paintComponent(Graphics g){
					super.paintComponent(g);
					g.drawImage(MyImage.getImage(),0,0,this.getWidth(),this.getHeight(),null);
					float lineWidth =2f;
					Graphics2D g2 = (Graphics2D)g;
					g2.setStroke(new BasicStroke(lineWidth));
					g2.setColor(Color.black);
					synchronized(obj){
						while(i350){
												value =700-value;
											}
											end_y= value;
											end_x +=1.5;
											if(end_x>680) break;
											list.add(new Point2D.Double(end_x,end_y));
											repaint();
											try{
												Thread.sleep(8);
											}catch(InterruptedException e){
												e.printStackTrace();
											}
										}
										if(x>=4000){
											break;
										}
									}
								}
							}
						}
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			public void setFlag(boolean Flag){
				this.Flag = Flag;
			} 
		}

你可能感兴趣的:(java,gui,Java)