Java_GUI中实现paintComponent方法并画背景图片和曲线的方法
2015-10-21 14:41
190 查看
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<Point2D> list = new ArrayList<Point2D>(); 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(i<list.size()-2){ start = list.get(i); end = list.get(i+1); line = new Line2D.Double(start,end); g2.draw(line); i+=1; } i = 0; } } public void run(){ try { if(dir==null&&Name==null){ return; } while(count!=0) { if(Flag==false) {list.clear();break;} boolean flag_1 =true; synchronized(obj){ list.clear(); i=0; } if(flag ==true){ start_x = 7 ;start_y = 350; end_x = 70;end_y = 350; start = new Point2D.Double(start_x,start_y); end = new Point2D.Double(end_x,end_y); list.add(start); list.add(end); flag = false; }else{ start_x = 7 ;start_y = 350; end_x = 7;end_y = 350; start = new Point2D.Double(start_x,start_y); end = new Point2D.Double(end_x,end_y); list.add(start); list.add(end); } FileReader file = null; try{ file = new FileReader(dir+"\\"+Name); }catch (FileNotFoundException e){ e.printStackTrace(); } BufferedReader bufr = new BufferedReader(file); String line = null; int x = 0; int cc = 0; int dd = 0; double [] a = new double[4000]; while((line = bufr.readLine())!=null){ if(flag_1 == true){ flag_1 = false; line = ""; continue; } else{ String s = null; Fun_Split f = new Fun_Split(); s = f.SplitDemo_line(line," +", 1); double value = Integer.parseInt(s); if(x<4000){ a[x++] = value; } else{ double [] b = new double[4000]; double [] c = new double[2000]; double [] d = new double[1000]; b = new FECG().ECG(a); for(int i=0;i<4000;i+=2){ c[cc++] = (b[i]+b[i+1])/2; } for(int i=0;i<2000;i+=2){ d[dd++] = (c[i]+c[i+1])/4; } for(int i=0;i<1000;i++){ value = (d[i]+150)*1.5; if(value>350){ 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; } }
相关文章推荐
- Android UI 设计(12):ListView 练习(制作水果选择菜单)
- Android UI 设计(13):AutoCompleteTextView
- Android UI 设计(14):GridView 控件
- [LeetCode-232] Implement Queue using Stacks(两个栈实现一个队列)
- 未来蓝牙将会分为三种:。Bluetooth Smart Ready、Bluetooth Smart、以及标准 Bluetooth
- UITextField去除用户SB而输入空格,和设置智能输入数字的方法
- IOS--UI之间属性传值
- 关于java StringBuilder初始化的一个坑
- Android设计模式之建造者模式builder
- 蒙板_upView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
- Could notconnect to ASM due to following error ORA-01031:insufficientprivileges
- request.getRequestdispacher("result.jsp“).forward(request,response)与response.sendRedirect()重定向
- ueditor上传视频控件,如何获得上传文件的路径?
- JAVA三星题之Eight Queens
- 简单阐述下OC中UIImage三种创建方式~~~
- iOS:模态弹出窗控制器UIPopoverPresentationController
- UIImagePickerController详解
- '<', hexadecimal value 0x3C, is an invalid attribute character. Line 21, position 29.
- 最长单调递增公共子序列(路径记录+poj2127+zoj2432)Greatest Common Increasing Subsequence
- Greatest Common Increasing Subsequence(最长单调递增公共子序列+hdu1423)