Pessoal,
Alguns pepinos foram ficando para trás. Agora preciso que o meu bimput (JButton) após pressionado desenhe uma linha com drawLine() dentro de uma TextArea.
No meu pgm tenho o método Paint que desenha o triangulo incialmente, mas depois como preciso desenhar as linhas cortando o triangulo então declarei localmente a variavel g da Classe Graphics para poder chamar o método g.drawLine(); porém dá erro e abortar.
Vou postar somente as partes que interessam okei?!
Este é o triangulo desenhado dentro da TextArea
private class MyTextArea extends JTextArea {
public MyTextArea(int rows, int columns) {
super(rows, columns);
}
public void paint(Graphics g) {
super.paint(g);
// Metade horizontal e metade vertical
int meioHor = 195;
int meioVer = 235;
// Desenha o triangulo na parte inferior da janela da JTextArea
g.setColor(Color.red); // lado esquerdo
g.drawLine(meioHor, meioVer, 30, 471 - 30);
g.setColor(Color.black);
g.drawString(svertice1, 170, 222);
g.setColor(Color.green);
g.drawLine(30, 471 - 30, 390 - 30, 471 - 30);// base do triangulo
g.setColor(Color.black);
g.drawString(svertice2, 12, 454);
g.setColor(Color.blue); // lado direito
g.drawLine(meioHor, meioVer, 390 - 30, 471 - 30);
g.setColor(Color.black);
g.drawString(svertice3, 350, 454);
}
}
Agora o actionPerformed com o JButton
public void actionPerformed(ActionEvent ev) {
Object src = ev.getSource();
final int TOTCOAL1 = 1, TOTCOAL2 = 0, TOTCOAL3 = 1;
final int TOTCOALIZAO = 8;
final int TOT12 = 4, TOT13 = 3, TOT23 = 5;
if (src == bimput) {
// primeiro valor constante
int somaA = -1;
int opa = listaA.getSelectedIndex();
somaA = opa + TOTCOAL1;
String sla = String.valueOf(opa);
int difA = TOTCOALIZAO - somaA;
String txt12Z = String.valueOf(difA);
tpos12_Z.setHorizontalAlignment((int) JComponent.CENTER_ALIGNMENT);
tpos12_Z.setAlignmentX(JComponent.CENTER_ALIGNMENT);
tpos12_Z.setEditable(false);
tpos12_Z.setText(txt12Z);
String output = "\nValor da SomaA: " + somaA + "\tDifA: " + difA + "\ttpos12_Z: " + tpos12_Z.getText();
///////////////////////////////////////////////////
int somaB = -1;
int opb = listaB.getSelectedIndex() + 1;
String slb = String.valueOf(opb);
somaB = opb + TOTCOAL2;
int difB = TOTCOALIZAO - somaB;
// segundo valor constante
String txt21Z = String.valueOf(difB);
tpos21_Z.setHorizontalAlignment((int) JComponent.CENTER_ALIGNMENT);
tpos21_Z.setAlignmentX(JComponent.CENTER_ALIGNMENT);
tpos21_Z.setEditable(false);
tpos21_Z.setText(txt21Z);
output += "\nValor da SomaB: " + somaB + "\tDifB: " + difB + "\ttpos21_Z: " + tpos21_Z.getText();
//////////////////////////////////////////////////////
// primeiro valor constante
int somaC = -1;
int opc = listaC.getSelectedIndex();
somaC = opc + TOTCOAL3;
String slc = String.valueOf(opc);
int difC = TOTCOALIZAO - somaC;
String txt13X = String.valueOf(difC);
tpos13_Z.setHorizontalAlignment((int) JComponent.CENTER_ALIGNMENT);
tpos13_Z.setAlignmentX(JComponent.CENTER_ALIGNMENT);
tpos13_Z.setEditable(false);
tpos13_Z.setText(txt13X);
output += "\nValor da SomaC: " + somaC + "\tDifA: " + difC + "\ttpos13_Z: " + tpos13_Z.getText();
///////////////////////////////////////////////////
int somaD = -1;
int opd = listaD.getSelectedIndex() + 1;
String sld = String.valueOf(opd);
somaD = opd + TOTCOAL3;
int difD = TOTCOALIZAO - somaD;
String txt31Y = String.valueOf(difD);
// terceiro valor constante
tpos31_Y.setHorizontalAlignment((int) JComponent.CENTER_ALIGNMENT);
tpos31_Y.setAlignmentX(JComponent.CENTER_ALIGNMENT);
tpos31_Y.setEditable(false);
tpos31_Y.setText(txt31Y);
output += "\nValor da SomaD: " + somaD + "\tDifD: " + difD + "\ttpos31_Y: " + tpos31_Y.getText();
//////////////////////////////////////////////////////
int somaE = -1;
int ope = listaE.getSelectedIndex() + 1;
String sle = String.valueOf(ope);
somaE = ope + TOTCOAL2;
int difE = TOTCOALIZAO - somaE;
String txt23X = String.valueOf(difE);
// segundo valor constante
tpos23_Z.setHorizontalAlignment((int) JComponent.CENTER_ALIGNMENT);
tpos23_Z.setAlignmentX(JComponent.CENTER_ALIGNMENT);
tpos23_Z.setEditable(false);
tpos23_Z.setText(txt23X);
output += "\nValor da SomaE: " + somaE + "\tDifE: " + difE + "\ttpos23_Z (calculado): " + tpos23_Z.getText();
//////////////////////////////////////////////////////
int somaF = -1;
int opf = listaF.getSelectedIndex();
String slf = String.valueOf(opf);
somaF = opf + TOTCOAL3;
int difF = TOTCOALIZAO - somaF;
String txt32Y = String.valueOf(difF);
// segundo valor constante
tpos32_X.setHorizontalAlignment((int) JComponent.CENTER_ALIGNMENT);
tpos32_X.setAlignmentX(JComponent.CENTER_ALIGNMENT);
tpos32_X.setEditable(false);
tpos32_X.setText(txt32Y);
output += "\nValor da SomaF: " + somaF + "\tDifF: " + difF + "\ttpos32_X (calculado): " + tpos32_X.getText();
tareadesenho2.setText(output);
Font negrito = new Font("SansSerif", Font.BOLD, 14);
JTextArea outputArea = new JTextArea(8, 25);
JScrollPane scroller = new JScrollPane(outputArea);
String output3 = "";
if ((somaA > TOT12) || (somaB > TOT12) || (somaC > TOT13) || (somaD > TOT13) || (somaE > TOT23) || (somaF > TOT23))
{
output3 += "ATENÇÃO - Violação de Restrição" +
"\nExcedido o valor da função característica!!!" +
"\nRedefina coordenadas válidas levando em" +
"\nconsideração o conceito de superaditividade e " +
"\nde conjunto vazio" ;
outputArea.setFont(negrito);
outputArea.setText(output3);
JOptionPane.showMessageDialog(null, outputArea,
"Explicação do Jogo", JOptionPane.INFORMATION_MESSAGE);
tpos12_Z.setText("");
}
return;
}
PS.: Espero não assustar com o tanto de variavel aqui, mas faz parte da lógica, o que preciso é logo após o ultimo String output poder desenhar ao menos uma linha cortando o triangulo da TextArea.
Obrigada sempre!
sds