?? c3.java~1~
字號:
package java2d;
import java.awt.*;
import java.sql.*;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Arc2D;
import java.awt.geom.AffineTransform;
import java.awt.geom.Line2D;
import java.awt.geom.Rectangle2D;
import java.util.*;
import java.sql.Connection;
public class C3 extends AnimatingSurface {
//public long sleepAmount = 500;
private Connection con;
private String samptime,disptime;
private int aw,ah;
private int columnInc;
private int pts[];
private int ptNum;
private float rtd;
private double doubleResult;
private Rectangle graphOutlineRect = new Rectangle();
private Rectangle2D BartRect = new Rectangle2D.Float();
private Rectangle2D muRect = new Rectangle2D.Float();
private Line2D graphLine = new Line2D.Float();
private Color graphColor = new Color(46, 139, 87);
private Color mfColor = new Color(0, 100, 0);
private float rectW=(float)40;
//量程
private int MI=10;
public C3() {
setBackground(Color.white);
name="電流3";
if (Java2Demo.connection!=null)
{
con=Java2Demo.connection;
}
}
public void reset(int w, int h) {
}
public void step(int w, int h) {
}
private void getdata(){
if (Java2Demo.datapool!=null)
{
rtd=Java2Demo.datapool.getdataF("I3","current_table");
realdata=rtd;
samptime=Java2Demo.datapool.getdataT("current_table");
disptime=samptime.substring(11,19);
System.out.println(disptime);
}
}
public void render(int w, int h, Graphics2D g2) {
g2.setBackground(Color.black);
g2.clearRect(0,0,w,h);
g2.setColor(graphColor);
//draw grahpicoutlinerect
int graphX=20;
int graphY=30;
//int graphW=w-graphX-5;
int graphW=w-graphX-20;
int graphH=h-graphY-5;
//
System.out.println("the width is:"+graphW);
int LT=graphW/2;
g2.setColor(Color.gray);
g2.fill3DRect(graphX, graphY, graphW, graphH,true);
//plot
g2.setColor(Color.yellow);
g2.drawString("電流3 實時數據 單位:毫安",graphX+graphW/4,graphY/2);
int xcenter=graphX+graphW/2,ycenter=graphY+graphH/2+30;
g2.setColor(Color.darkGray);
g2.fill3DRect(xcenter-80,ycenter-100, 160,170,true);
g2.setColor(Color.red);
g2.fillOval(xcenter,ycenter-20,3,3);
//plot Arc
g2.setColor(Color.red);
g2.drawArc(xcenter-80,ycenter-100,160,160,15,150);
//g2.setColor(Color.darkGray);
//g2.fillArc(xcenter-40,ycenter-60,80,80,15,150);
//繪刻度
g2.setColor(Color.yellow);
g2.drawString("0",xcenter-80,ycenter-27);
g2.drawLine(xcenter-80,ycenter-40,xcenter-80+(int)(Math.cos(Math.PI/12)*10),ycenter-40+(int)(Math.sin(Math.PI/12)*10));
g2.drawString(""+MI/2,xcenter+3,ycenter-100+10);
g2.drawLine(xcenter,ycenter-100,xcenter,ycenter-100+9);
g2.drawString(""+MI,xcenter+65,ycenter-27);
g2.drawLine(xcenter+80,ycenter-40,xcenter+80-(int)(Math.cos(Math.PI/12)*10),ycenter-40+(int)(Math.sin(Math.PI/12)*10));
//get data
getdata();
//動態繪針
int Xpoint=xcenter,Ypoint=ycenter-20;//指針起點
double angle=rtd*Math.PI/12; //實際值換算后的角度
g2.drawLine(Xpoint,Ypoint,Xpoint-(int)(Math.cos(Math.PI/12+angle)*60),Ypoint-(int)(Math.sin(Math.PI/12+angle)*60));
//繪制分刻度
//plot data
int T[]=new int[4];
T=parseF(rtd);
drawDigit(g2,T[0],graphX+graphW/2-40,graphY+graphH-40,15,20);
drawDigit(g2,T[1],graphX+graphW/2-20,graphY+graphH-40,15,20);
g2.setColor(new Color(160,82,45));
g2.fillRect(graphX+graphW/2,graphY+graphH-24,5,5);
drawDigit(g2,T[2],graphX+graphW/2+10,graphY+graphH-40,15,20);
drawDigit(g2,T[3],graphX+graphW/2+30,graphY+graphH-40,15,20);
//set samptime
g2.setColor(Color.yellow);
g2.drawString(disptime,graphX+graphW/2-27,graphY+12);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -