A cópia do código é a seguinte:
Package GraphicsCanvas;
importar java.awt.borderlayout;
importar java.awt.canvas;
importar java.awt.color;
importar java.awt.graphics;
importar java.awt.image;
importar java.awt.event.actionEvent;
importar java.awt.event.actionListener;
importar javax.swing.jbutton;
importar javax.swing.jframe;
importar javax.swing.jlabel;
importar javax.swing.jpanel;
importar javax.swing.jtextfield;
importar javax.swing.timer;
importar javax.swing.uimanager;
/**
* Medidor de pressão arterial simulado, alta pressão, baixa pressão
*
* @Author Fan Junbin
* @Time 2013-12-10
*/
classe pública Blood estende JFrame {
private estático final serialversionUid = 1L;
Imagem privada iBuffer;
myCanvas BloodCanvas = New MyCanvas ();
Private JTextfield HighPressText, LowPressText;
// comprimento e largura da tela
private final int Canvas_width = 400;
private final int canvas_height = 800;
// o comprimento e a largura da concha de vidro e as coordenadas iniciais
PRIVADO FINAL INT BLOOD_WIDTH = 30;
PRIVADO FINAL Int Blood_Height = 650;
PRIVADO FINAL Int Blood_x = Canvas_width / 2 - Blood_width / 2;
PRIVADO FINAL INT BLOOD_Y = 50;
// Tamanho do quadro e coordenadas iniciais
private final int frame_width = 120;
PRIVADO FINAL INT Frame_Height = 720;
private final int estrutura_x = canvas_width / 2 - estrutura_width / 2;
private final int frame_y = sangue_y - 20;
// As coordenadas horizontais e verticais e o comprimento da linha de 0
final privado int zoreline_y = sangue_y + blood_height - 10;
Final privado int zoreline_x = canvas_width / 2 + blood_width / 2;
private final int line_length = 8;
// entrada de alta tensão e baixa tensão
private int HighPressinput, LowPressinput;
// altura dinâmica de colunas de mercúrio de alta e baixa pressão
int highPressHeight = 0;
int lowpressHeight = 0;
int startlow = sangue_y;
// Timer de mercúrio alto e baixo
Timer HighPresstimer, LowPresstimer;
public Blood () {
Super ("Model-Freedomano do Monitor de pressão arterial personalizada");
this.setDefaultCloseoperation (exit_on_close);
this.setBounds (300, 50, Canvas_width, Canvas_Height + 20);
// Adicione o controle ao norte da estrutura
Jpanel toppanel = new jpanel ();
this.add (toppanel, borderlayout.north);
HighPressText = novo JTextfield (5);
LowPressText = novo JTextField (5);
JButton PressButton = New Jbutton ("Show");
PressButton.addactionListener (new ActionListener () {
@Override
public void ActionPormed (ActionEvent Arg0) {
highPressInput = Integer.ParseInt (HighPressText.getText ());
lowPressInput = Integer.ParseInt (LowPressText.getText ());
ActionListener HighPressTaskPerformer = new ActionListener () {
public void ActionPerformed (ActionEvent EVT) {
// Aumente a altura em 1 pixel/0,01s e interrompa o tempo até que os requisitos de entrada sejam atendidos.
HighPressHeight += 1;
BloodCanvas.Repaint ();
if (highPressHeight == HighPressinput * 2) {
highPresstimer.stop ();
// O timer de coluna de mercúrio de baixa pressão é aninhado dentro do timer de alta pressão, em sequência (primeiro pressão primeiro, depois baixa pressão)
startLow = zoreline_y - highpressHeight;
ActionListener LowPressTaskPerformer = new ActionListener () {
public void ActionPerformed (ActionEvent EVT) {
LowPressHeight += 1;
BloodCanvas.Repaint ();
if (LowPressHeight == Zoreline_Y
- LowPressinput * 2 - StartLow)
lowPresstimer.stop ();
}
};
LowPresstimer = novo temporizador (10, LowPressTaskPerformer);
lowpresstimer.start ();
}
}
};
// Defina o ouvinte de eventos que executa a cada 0,01 segundos
HighPresstimer = novo temporizador (10, HighPressTaskPerformer);
highPresstimer.start ();
}
});
toppanel.add (New Jlabel ("Valor de Alta Tensão", Jlabel.Center));
toppanel.add (HighPressText);
toppanel.add (New Jlabel ("Valor de baixa tensão", jlabel.center));
topPanel.add (LowPressText);
// toppanel.add (New Jlabel ("Frequência cardíaca", jlabel.center));
toppanel.add (PressButton);
// Adicione tela à área central
this.add (BloodCanvas, borderlayout.center);
this.setResizable (false);
this.setVisible (true);
}
/**
* Redrato de tela do medidor de pressão arterial
*/
classe mycanvas estende a tela {
public void Paint (Gráfico G) {
// Desenhe fronteiras
g.setColor (color.black);
g.Draw3Drect (Frame_X, Frame_Y, Frame_width, Frame_Height, True);
// Draw Glass Shell
g.setColor (color.orange);
g.fill3drect (sangue_x, blood_y, blood_width, sangue_height, true);
// coluna de mercúrio de alta pressão
g.setColor (color.red);
G.Fill3DRect (Blood_X, Zoreline_Y - HighPressHeight, Blood_width,
alta pressão, verdadeiro);
// coluna de mercúrio de alta pressão de baixa pressão
g.setColor (color.orange);
g.fill3drect (sangue_x, startlow, blood_width, baixa pressão, true);
// Desenhe a bola de mercúrio na parte inferior
g.setColor (color.red);
G.FILLOVAL (CANVAS_WIDTH / 2 - 30, ZORELINE_Y - 5, 60, 60);
// O carrapato e as coordenadas iniciais da linha 0 da escala à direita (a coordenada vertical da linha de escala é gradualmente alterada por line_y)
int rightstartDegree = 0;
int line_y = zoreline_y;
para (; line_y> blood_y; line_y -= 2) {
// 2 pixels são um índice mínimo de 1 grau
g.setColor (color.black);
g.Drawline (zoreline_x, line_y, zoreline_x + line_length, line_y);
// Desenhe ticks de 10 graus a cada 10 índices mínimos
if (line_y % 20 == 10) {
g.setColor (color.blue);
G.Drawline (zoreline_x, line_y,
Zoreline_x + line_length * 2, line_y);
G.DrawString (RightStartDegree + "", Zoreline_X
+ Line_length * 3, line_y + 4);
RightstartDegree += 10;
}
}
// O carrapato e as coordenadas iniciais da linha 0 da esquerda (a coordenada vertical da linha de escala é gradualmente alterada por line_y)
int leftstartDegree = 0;
int leftline_y = zoreline_y;
para (; leftline_y> blood_y; leftline_y -= 6) {
// 6 pontos de pixels são um índice mínimo de 1 grau
g.setColor (color.black);
G.Drawline (Blood_X, Leftline_Y, Blood_x - Line_length,
leftline_y);
// Desenhe ticks de 10 graus a cada 10 índices mínimos
if (leftline_y % 20 == 10) {
g.setColor (color.blue);
G.Drawline (Blood_X, Leftline_Y, Blood_x - Line_length * 2,
leftline_y);
G.DrawString (LeftStartDegree + "", Blood_x - Line_length
* 4, leftline_y + 4);
leftstartDegree += 10;
}
}
}
/**
* Tecnologia de buffer duplo: a velocidade de cálculo complexa é mais lenta que a exibição da tela, e o buffer é usado para resolver o problema do tremor
*/
@Override
public void update (gráfico g) {
if (iBuffer == null) {
iBuffer = createImage (this.getSize (). Largura,
this.getSize (). altura);
}
Gráficos gbuffer = ibuffer.getgraphics ();
gbuffer.setColor (getbackground ());
gbuffer.fillRect (0, 0, this.getSize (). largura, this.getSize (). altura);
tinta (Gbuffer);
gbuffer.dispose ();
G.Drawimage (iBuffer, 0, 0, este);
}
}
public static void main (string [] args) {
// Defina a aparência da interface para a aparência do sistema
tentar {
Uimanager.setLookAndFeel (uimanager.getSystemLookAndFeelClassName ());
} catch (Exceção e) {
E.PrintStackTrace ();
}
sangue novo();
}
}