Gerandpo um grafico atraves de dados fornecidos pelo usuário

2 respostas
R

Olá Pessoal..

estou fazendo um trabs pra facul que lê 3 pontos e gera um triângulo em um grafico.
Consegui fazer a leitura de dados, validações e até os cálculos* (*não está no arquivo mas funciona). depois disso o programa deverá abrir uma tela com a descrição dos valores e o gráfico.
Não estou conseguindo fazer com que esta tela abra com o conteudo que eu desejo, no caso a descrição dos valores e o grafico.

Podem me ajudar??
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
import javax.swing.JOptionPane;

/*
 
 Matriz DADOS:
 *Coluna 0 --> X (Ax, Bx, Cx)
 *Coluna 1 --> Y (Ay, By, Cy)
 *Coluna 2 --> m (Coeficientes Angulares)

 */

public class Trab01 extends JFrame {
   private JDesktopPane AREA,AREA2;
   private JTextField DADO[][] = new JTextField[3][2];
   private Double DADOS[][] = new Double[3][2];
   private JLabel LABEL1,LABEL2,LABEL3,LABEL4,LABEL5,LABEL6,LABEL7,LABEL8,LABEL9;
  private JButton BOTAO;
  private Container CONTEUDO, CONTEUDO2;
  private JPanel LDADOS, GRAFICO;
  private JTextArea LISTA;
  String SAIDA = "Listagem de Dados\n";
    	
  public Trab01()
  {
    super("Entrada de Dados");
    
    AREA = new JDesktopPane();
    getContentPane().add(AREA);
	    
	CONTEUDO =getContentPane();
	CONTEUDO.setLayout(null); //layout nulo
	
	LABEL1 = new JLabel("Entrada de Dados");
	CONTEUDO.add(LABEL1);
	LABEL1.setBounds(10,10,400,10);
	
	LABEL2 = new JLabel("Digite valores entre -5 e 5.");
	CONTEUDO.add(LABEL2);
	LABEL2.setBounds(10,20,400,20);
	
	LABEL3 = new JLabel("Ax: ");
	LABEL3.setBounds(50,50,50,20); 
	DADO[0][0]=new JTextField(5);
	DADO[0][0].setBounds(80,50,50,20);
    CONTEUDO.add(LABEL3);
	CONTEUDO.add(DADO[0][0]);
	

	LABEL4 = new JLabel("Ay: ");
	LABEL4.setBounds(50,80,50,20);	
	DADO[0][1]=new JTextField(5);
	DADO[0][1].setBounds(80,80,50,20);
    CONTEUDO.add(LABEL4);
	CONTEUDO.add(DADO[0][1]);	
	
	LABEL5 = new JLabel("Bx: ");
	LABEL5.setBounds(50,110,50,20);	
	DADO[1][0]= new JTextField(5);
	DADO[1][0].setBounds(80,110,50,20);
	CONTEUDO.add(LABEL5);
	CONTEUDO.add(DADO[1][0]);
	
	LABEL6 = new JLabel("By: ");
	LABEL6.setBounds(50,140,50,20);	
	DADO[1][1]= new JTextField(5);
	DADO[1][1].setBounds(80,140,50,20);
    CONTEUDO.add(LABEL6);
	CONTEUDO.add(DADO[1][1]);	
		
	LABEL7 = new JLabel("Cx: ");
	LABEL7.setBounds(50,170,50,20);
	DADO[2][0]= new JTextField(5);
	DADO[2][0].setBounds(80,170,50,20);
	CONTEUDO.add(LABEL7);
	CONTEUDO.add(DADO[2][0]);
		
	LABEL8 = new JLabel("Cy: ");
	LABEL8.setBounds(50,200,50,20);
	DADO[2][1]= new JTextField(5);
	DADO[2][1].setBounds(80,200,50,20);
    CONTEUDO.add(LABEL8);
	CONTEUDO.add(DADO[2][1]);

    BOTAO = new JButton("OK");
    BOTAO.setBounds(50,250,100,20);
	CONTEUDO.add(BOTAO);
	BOTAO.addActionListener
	(
		new ActionListener()
    	{
			public void actionPerformed (ActionEvent event)
    		{
    			
    			TestaValores();
    			//JOptionPane.showMessageDialog(null,"TESTE!");
    		}
    	}
	);

    setSize(250,400);
    setVisible(true);
  
  }
  
  public void TestaValores ()
  {
  		DADOS[0][0]=Double.parseDouble(DADO[0][0].getText());
  		DADOS[0][1]=Double.parseDouble(DADO[0][1].getText());
  		DADOS[1][0]=Double.parseDouble(DADO[1][0].getText());
		DADOS[1][1]=Double.parseDouble(DADO[1][1].getText());
    	DADOS[2][0]=Double.parseDouble(DADO[2][0].getText());
    	DADOS[2][1]=Double.parseDouble(DADO[2][1].getText());	

		while (DADOS[0][0] < -5 || DADOS[0][0] > 5)
		{
			DADOS[0][0]=Double.parseDouble(JOptionPane.showInputDialog("Digite novamente o valor de Ax: \n(Entre -5 e 5)"));
			
		}

		DADO[0][0].setText(Double.toString(DADOS[0][0]));
		DADO[0][0].setEditable(false);
		
		while (DADOS[0][1] < -5 || DADOS[0][1] > 5)
		{
			DADOS[0][1]=Double.parseDouble(JOptionPane.showInputDialog("Digite novamente o valor de Ay: \n(Entre -5 e 5)"));
		}

		DADO[0][1].setText(Double.toString(DADOS[0][1]));
		DADO[0][1].setEditable(false);
				
		while (DADOS[1][0] < -5 || DADOS[1][0] > 5)
		{
			DADOS[1][0]=Double.parseDouble(JOptionPane.showInputDialog("Digite novamente o valor de Bx: \n(Entre -5 e 5)"));
		}

		DADO[1][0].setText(Double.toString(DADOS[1][0]));
		DADO[1][0].setEditable(false);

		while (DADOS[1][1] < -5 || DADOS[1][1] > 5)
		{
			DADOS[1][1]=Double.parseDouble(JOptionPane.showInputDialog("Digite novamente o valor de By: \n(Entre -5 e 5)"));
		}

		DADO[1][1].setText(Double.toString(DADOS[1][1]));
		DADO[1][1].setEditable(false);		

		while (DADOS[2][0] < -5 || DADOS[2][0] > 5)
		{
			DADOS[2][0]=Double.parseDouble(JOptionPane.showInputDialog("Digite novamente o valor de Cx: \n(Entre -5 e 5)"));
		}

		DADO[2][0].setText(Double.toString(DADOS[2][0]));
		DADO[2][0].setEditable(false);
				
		while (DADOS[2][1] < -5 || DADOS[2][1] > 5)
		{
			DADOS[2][1]=Double.parseDouble(JOptionPane.showInputDialog("Digite novamente o valor de Cy: \n(Entre -5 e 5)"));
		}

		DADO[2][1].setText(Double.toString(DADOS[2][1]));
		DADO[2][1].setEditable(false);
		
		SAIDA+="Ax:"+DADOS[0][0]+"\n Ay: "+DADOS[0][1]+"\n";
		SAIDA+="Bx:"+DADOS[1][0]+"\n By: "+DADOS[1][1]+"\n";
		SAIDA+="Cx:"+DADOS[2][0]+"\n Cy: "+DADOS[2][1];
				
		
		
	    BOTAO.setLabel("LISTA DADOS E GRÁFICO");
	    BOTAO.setBounds(20,250,200,20);
	    BOTAO.addActionListener
		(
			new ActionListener()
    		{
				public void actionPerformed (ActionEvent event)
    			{
  	  				
    				Listagem();
    				
    			}
    		}
		);		

		
  }
  
  public void Listagem()
  {
		//JOptionPane.showMessageDialog(null,"TESTE!");
//		super("Listagem de Dados e Gráfico");
		
		
		
		AREA2 = new JDesktopPane();
    	getContentPane().add(AREA2);
	    
		CONTEUDO2 =getContentPane();
		CONTEUDO2.setLayout(null); //layout nulo
		
		
//		GRAFICO = new JPanel();
//		GRAFICO.setBackground(Color.cyan);
		
		//GRAFICO.paint();
		
		LISTA = new JTextArea();
		LISTA.setText(SAIDA);
		LISTA.setEditable(false);
		
		LDADOS = new JPanel();
		LDADOS.setLayout(null);
		LDADOS.add(LISTA);
		
//		CONTEUDO.add(GRAFICO);
		CONTEUDO2.add(LDADOS);
		
		setSize(800,600);
		setVisible(true);
  }
/*
  public void paint(Graphics g)
  {
  	super.paint(g);
  
  	g.drawLine(300,50,300,550);
  	g.drawLine(50,300,550,300);
  	g.translate(400,300);
  	g.setColor(Color.red);
  	
  	g.drawLine(100,100,200,200);
  	g.drawLine(200,200,150,150);
  	g.drawLine(150,150,100,100);


//  	g.drawLine((DADOS[0][0]*100),(DADOS[0][1]*100),(DADOS[1][0]*100),(DADOS[1][1]*100));//verificar associação para valores entre -5 e 5
//  	g.drawLine((DADOS[1][0]*100),(DADOS[1][1]*100),(DADOS[2][0]*100),(DADOS[2][1]*100));
//  	g.drawLine((DADOS[2][0]*100),(DADOS[2][1]*100),(DADOS[0][0]*100),(DADOS[0][1]*100));

  }
*/
  
  public static void main (String Args[])
  {
  	Trab01 application = new Trab01();
  	application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  }
  
}
[size="11"][color="red"]* Editado: Lembre-se de utilizar BBCode em seus códigos - Ratinho[/color][/size] :joia:

2 Respostas

Z

falaê, raptatinha...

teste com as seguintes modificações:

public void Listagem() 
	{ 
	  //JOptionPane.showMessageDialog(null,"TESTE!"); 
	//      super("Listagem de Dados e Gráfico"); 
	   
	   
	   
	  AREA2 = new JDesktopPane();
	  getContentPane().add(AREA2);
	   
	  CONTEUDO2 =getContentPane();
	  CONTEUDO2.setLayout(null); //layout nulo
	   
	   
	//      GRAFICO = new JPanel(); 
	//      GRAFICO.setBackground(Color.cyan); 
	   
	  //GRAFICO.paint(); 
	   
	  LISTA = new JTextArea(); 
	  LISTA.setText(SAIDA);
	  LISTA.setEditable(false);
	  LISTA.setBounds(300,20,200,200);   // AQUI
	  
	  LDADOS = new JPanel();
	  LDADOS.setLayout(null);
	  LDADOS.add(LISTA);
	  
	//      CONTEUDO.add(GRAFICO); 
	  //CONTEUDO2.add(LDADOS);
	  
	  add(LISTA);   // AQUI
	   
	  setSize(800,600); 
	  setVisible(true);
	}

espero ter ajudado.

R

Oioioi… zafenate

Muito Obrigada pela ajuda… mas consegui fazer de outra forma… dá uma olhada:

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.text.*;

/*
 
 Matriz DADOS:
 *Coluna 0 --> X (Ax, Bx, Cx)
 *Coluna 1 --> Y (Ay, By, Cy)

 */

public class Trab01 extends JFrame 
{
  private JDesktopPane AREA, AREA2;
  private JTextField DADO[][] = new JTextField[3][2];
  public int DADOS[][] = new int [3][2];
  private JLabel LABEL1, LABEL2, LABEL3, LABEL4, LABEL5, LABEL6, LABEL7,LABEL8, LABEL9;
  private JButton BOTAO;
  private Container CONTEUDO;
  String MAB, MABR, MBC, MBCR, MAC, MACR, SAIDA="Listagem de Dados\n";
  int mAB=1, mBC=1, mAC=1;
  Double LAB, LBC, LAC;
  JTextArea LISTA = new JTextArea();


    	
  public Trab01()
  {
   	super("Entrada de Dados");
    
    AREA = new JDesktopPane();
    getContentPane().add(AREA);
	
	CONTEUDO =getContentPane();
	CONTEUDO.setLayout(null);
	
	LABEL1 = new JLabel("Entrada de Dados");
	CONTEUDO.add(LABEL1);
	LABEL1.setBounds(10,10,400,10);
	
	LABEL2 = new JLabel("Digite valores entre -5 e 5.");
	CONTEUDO.add(LABEL2);
	LABEL2.setBounds(10,20,400,20);
	
	LABEL3 = new JLabel("Ax: ");
	LABEL3.setBounds(50,50,50,20);
	DADO[0][0]=new JTextField(5);
	DADO[0][0].setBounds(80,50,50,20);
    CONTEUDO.add(LABEL3);
	CONTEUDO.add(DADO[0][0]);
	
	LABEL4 = new JLabel("Ay: ");
	LABEL4.setBounds(50,80,50,20);
	DADO[0][1]=new JTextField(5);
	DADO[0][1].setBounds(80,80,50,20);
    CONTEUDO.add(LABEL4);
	CONTEUDO.add(DADO[0][1]);
	
	LABEL5 = new JLabel("Bx: ");
	LABEL5.setBounds(50,110,50,20);
	DADO[1][0]= new JTextField(5);
	DADO[1][0].setBounds(80,110,50,20);
	CONTEUDO.add(LABEL5);
	CONTEUDO.add(DADO[1][0]);
	
	LABEL6 = new JLabel("By: ");
	LABEL6.setBounds(50,140,50,20);
	DADO[1][1]= new JTextField(5);
	DADO[1][1].setBounds(80,140,50,20);
    CONTEUDO.add(LABEL6);
	CONTEUDO.add(DADO[1][1]);
	
	LABEL7 = new JLabel("Cx: ");
	LABEL7.setBounds(50,170,50,20);
	DADO[2][0]= new JTextField(5);
	DADO[2][0].setBounds(80,170,50,20);
	CONTEUDO.add(LABEL7);
	CONTEUDO.add(DADO[2][0]);
	
	LABEL8 = new JLabel("Cy: ");
	LABEL8.setBounds(50,200,50,20);
	DADO[2][1]= new JTextField(5);
	DADO[2][1].setBounds(80,200,50,20);
    CONTEUDO.add(LABEL8);
	CONTEUDO.add(DADO[2][1]);

    BOTAO = new JButton("OK");
    BOTAO.setBounds(50,250,100,20);
	CONTEUDO.add(BOTAO);
	BOTAO.addActionListener
	(
		new ActionListener()
    	{
			public void actionPerformed (ActionEvent event)
    		{
    			
    			TestaValores();

    		}
    	}
	);

    setSize(250,400);
    setVisible(true);

  }
  
    public void TestaValores ()
  {
  		DADOS[0][0]=Integer.parseInt(DADO[0][0].getText());
  		DADOS[0][1]=Integer.parseInt(DADO[0][1].getText());
  		DADOS[1][0]=Integer.parseInt(DADO[1][0].getText());
		DADOS[1][1]=Integer.parseInt(DADO[1][1].getText());
    	DADOS[2][0]=Integer.parseInt(DADO[2][0].getText());
    	DADOS[2][1]=Integer.parseInt(DADO[2][1].getText());	

		while (DADOS[0][0] < -5 || DADOS[0][0] > 5)
		{
			DADOS[0][0]=Integer.parseInt(JOptionPane.showInputDialog("Digite novamente o valor de Ax: \n(Entre -5 e 5)"));
			
		}

		DADO[0][0].setText(Integer.toString(DADOS[0][0]));
		DADO[0][0].setEditable(false);
		
		while (DADOS[0][1] < -5 || DADOS[0][1] > 5)
		{
			DADOS[0][1]=Integer.parseInt(JOptionPane.showInputDialog("Digite novamente o valor de Ay: \n(Entre -5 e 5)"));
		}

		DADO[0][1].setText(Integer.toString(DADOS[0][1]));
		DADO[0][1].setEditable(false);
				
		while (DADOS[1][0] < -5 || DADOS[1][0] > 5)
		{
			DADOS[1][0]=Integer.parseInt(JOptionPane.showInputDialog("Digite novamente o valor de Bx: \n(Entre -5 e 5)"));
		}

		DADO[1][0].setText(Integer.toString(DADOS[1][0]));
		DADO[1][0].setEditable(false);

		while (DADOS[1][1] < -5 || DADOS[1][1] > 5)
		{
			DADOS[1][1]=Integer.parseInt(JOptionPane.showInputDialog("Digite novamente o valor de By: \n(Entre -5 e 5)"));
		}

		DADO[1][1].setText(Integer.toString(DADOS[1][1]));
		DADO[1][1].setEditable(false);		

		while (DADOS[2][0] < -5 || DADOS[2][0] > 5)
		{
			DADOS[2][0]=Integer.parseInt(JOptionPane.showInputDialog("Digite novamente o valor de Cx: \n(Entre -5 e 5)"));
		}

		DADO[2][0].setText(Integer.toString(DADOS[2][0]));
		DADO[2][0].setEditable(false);
				
		while (DADOS[2][1] < -5 || DADOS[2][1] > 5)
		{
			DADOS[2][1]=Integer.parseInt(JOptionPane.showInputDialog("Digite novamente o valor de Cy: \n(Entre -5 e 5)"));
		}

		DADO[2][1].setText(Integer.toString(DADOS[2][1]));
		DADO[2][1].setEditable(false);
		
		SAIDA+="A("+DADOS[0][0]+","+DADOS[0][1]+"); B("+DADOS[1][0]+","+DADOS[1][1]+"); C("+DADOS[2][0]+","+DADOS[2][1]+")\n";
		
		//coeficiente angular da reta AB: A(Ax, Ay) - B(Bx, By)
		if (DADOS[0][1] == DADOS[1][1]) //reta horizontal
		{
			MAB="0";
			MABR="Horizontal";
		}
			else if (DADOS[0][0] == DADOS[1][0]) //reta vertical

			{
				MAB="Coeficiente Angular não existe";
				MABR="Vertical";
			}
				else if ((DADOS[0][1] < DADOS[1][1] && DADOS[0][0] > DADOS[1][0])||(DADOS[1][1] < DADOS[0][1] && DADOS[1][0] > DADOS[0][0]))// reta decrescente
				{
					MAB=Integer.toString((DADOS[1][1]-DADOS[0][1])/(DADOS[1][0]-DADOS[0][0]));
					mAB=Integer.parseInt(MAB);
					MABR="Decrescente";
				}
					else if ((DADOS[0][1] < DADOS[1][1] && DADOS[0][0] < DADOS[1][0])||(DADOS[1][1] < DADOS[0][1] && DADOS[1][0] < DADOS[0][0]))// reta crescente
					{
						MAB=Integer.toString((DADOS[1][1]-DADOS[0][1])/(DADOS[1][0]-DADOS[0][0]));
						mAB=Integer.parseInt(MAB);
						MABR="Crescente";
					}
		
		//coeficiente angular da reta BC: B(Bx, By) - C(Cx, Cy) 
		if (DADOS[1][1] == DADOS[2][1]) //reta horizontal 
		{
			MBC="0";
			MBCR="Horizontal";
		}
			else if (DADOS[1][0] == DADOS[2][0]) //reta vertical 
			{
				MBC="Coeficiente Angular não existe";
				MBCR="Vertical";
			}
				else if ((DADOS[1][1] < DADOS[2][1] && DADOS[1][0] > DADOS[2][0])||(DADOS[2][1] < DADOS[1][1] && DADOS[2][0] > DADOS[1][0]))// reta decrescente MBCR=3
				{
					MBC=Integer.toString((DADOS[2][1]-DADOS[1][1])/(DADOS[2][0]-DADOS[1][0]));
					mBC=Integer.parseInt(MAB);
					MBCR="Decrescente";
				}
					else if ((DADOS[1][1] < DADOS[2][1] && DADOS[1][0] < DADOS[2][0])||(DADOS[2][1] < DADOS[1][1] && DADOS[2][0] < DADOS[1][0]))// reta crescente MBCR=4
					{
						MBC=Integer.toString((DADOS[2][1]-DADOS[1][1])/(DADOS[2][0]-DADOS[1][0]));
						mBC=Integer.parseInt(MAB);
						MBCR="Crescente";
					}
							
		//coeficiente angular da reta AC: A(Ax, Ay) - C(Cx, Cy)
		if (DADOS[0][1] == DADOS[2][1]) //reta horizontal
		{
			MAC="0";
			MACR="Horizontal";
		}
			else if (DADOS[0][0] == DADOS[2][0]) //reta vertical
			{
				MAC="Coeficiente Angular não existe";
				MACR="Vertical";
			}
				else if ((DADOS[0][1] < DADOS[2][1] && DADOS[0][0] > DADOS[2][0])||(DADOS[2][1] < DADOS[0][1] && DADOS[2][0] > DADOS[0][0]))// reta decrescente
				{
					MAC=Integer.toString((DADOS[2][1]-DADOS[0][1])/(DADOS[2][0]-DADOS[0][0]));
					mAC=Integer.parseInt(MAB);
					MACR="Decrescente";
				}
					else if ((DADOS[0][1] < DADOS[2][1] && DADOS[0][0] < DADOS[2][0])||(DADOS[2][1] < DADOS[0][1] && DADOS[2][0] < DADOS[0][0]))// reta crescente
					{
						MAC=Integer.toString((DADOS[2][1]-DADOS[0][1])/(DADOS[2][0]-DADOS[0][0]));
						mAC=Integer.parseInt(MAB);
						MACR="Crescente";
					}
				
		SAIDA+="Coeficientes Angulares\n";
		SAIDA+="\nReta AB: "+MAB+"\n";
		SAIDA+="Reta BC: "+MBC+"\n";
		SAIDA+="Reta AC: "+MBC+"\n";
		
		if (MAB.equals("0"))
		{
			SAIDA+="Equação da reta que passa por AB é y ="+DADOS[0][1]+" que é uma reta"+MABR+".\n";
		}
			else if (MAB.equals("Coeficiente Angular não existe"))
			{
				SAIDA+="Equação da reta que passa por AB é x ="+DADOS[0][0]+" que é uma reta"+MABR+".\n";
			}
				else
				{
					if ((DADOS[0][0]*mAB+DADOS[0][1])>0)
					{
						SAIDA+="Equação da reta que passa por AB é y="+mAB+"x+"+(DADOS[0][0]*mAB+DADOS[0][1])+" que é uma reta"+MABR+".\n";
					}
					else
					{
						SAIDA+="Equação da reta que passa por AB é y="+mAB+"x-"+(DADOS[0][0]*mAB+DADOS[0][1])+" que é uma reta"+MABR+".\n";
					}
				}
					
		if (MBC.equals("0"))
		{
			SAIDA+="Equação da reta que passa por BC é y ="+DADOS[1][1]+" que é uma reta"+MBCR+".\n";
		}
			else if (MBC.equals("Coeficiente Angular não existe"))
			{
				SAIDA+="Equação da reta que passa por BC é x ="+DADOS[1][0]+" que é uma reta"+MBCR+".\n";
			}
				else
				{
					if ((DADOS[1][0]*mBC+DADOS[1][1])>0)
					{
						SAIDA+="Equação da reta que passa por BC é y="+mBC+"x+"+(DADOS[1][0]*mBC+DADOS[1][1])+" que é uma reta"+MBCR+".\n";
					}
					else
					{
						SAIDA+="Equação da reta que passa por BC é y="+mBC+"x-"+(DADOS[1][0]*mBC+DADOS[1][1])+" que é uma reta"+MBCR+".\n";
					}
				}

		if (MAC.equals("0"))
		{
			SAIDA+="Equação da reta que passa por AC é y ="+DADOS[2][1]+" que é uma reta"+MACR+".\n";
		}
			else if (MAC.equals("Coeficiente Angular não existe"))
			{
				SAIDA+="Equação da reta que passa por AC é x ="+DADOS[2][0]+" que é uma reta"+MACR+".\n";
			}
				else
				{
					if ((DADOS[2][0]*mAC+DADOS[2][1])>0)
					{
						SAIDA+="Equação da reta que passa por AC é y="+mAC+"x+"+(DADOS[2][0]*mAC+DADOS[2][1])+" que é uma reta"+MACR+".\n";
					}
					else
					{
						SAIDA+="Equação da reta que passa por AC é y="+mAC+"x-"+(DADOS[2][0]*mAC+DADOS[2][1])+" que é uma reta"+MACR+".\n";
					}
				}								
/*		
		//verificação se o triângulo é retangulo
		if (  ( (Integer.parseInt(MAB))*(Integer.parseInt(MBC)) ) == -1)||(  ( (Integer.parseInt(MAB))*(Integer.parseInt(MAC)) ) == -1)||(( (Integer.parseInt(MBC))*(Integer.parseInt(MAC)) ) == -1))
		{
			
			SAIDA+="Os pontos informados geram um triângulo retângulo!\n";
		}
			else
			{
				SAIDA+="Os pontos informados não geram um triângulo retângulo!\n";
			}
*/

		
		LAB=Math.sqrt(Math.pow(DADOS[0][0]-DADOS[1][0],2)+Math.pow(DADOS[0][1]-DADOS[1][1],2));
		LBC=Math.sqrt(Math.pow(DADOS[1][0]-DADOS[2][0],2)+Math.pow(DADOS[1][1]-DADOS[2][1],2));
		LAC=Math.sqrt(Math.pow(DADOS[0][0]-DADOS[2][0],2)+Math.pow(DADOS[0][1]-DADOS[2][1],2));
		
		SAIDA+="Lado AB: "+LAB+"\n Lado BC: "+LBC+"\n Lado AC: "+LAC;

		
		
		LISTA.setText(SAIDA);
		LISTA.setEditable(false);
	    BOTAO.setLabel("LISTA DADOS E GRÁFICO");
	    BOTAO.setBounds(20,250,200,20);
	    BOTAO.addActionListener
		(
			new ActionListener()
    		{
				public void actionPerformed (ActionEvent event)
    			{
    				JOptionPane.showMessageDialog(null,LISTA);
    				Grafico grafico = new Grafico(DADOS);       \\CHAMANDO A CLASSE

    			}
    		}
		);		
		

  }
   
 
  public static void main (String Args[])
  {
  	Trab01 application = new Trab01();
  	application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  }
 
}

e o arquivo que gera o grafico:

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

/*
 
 Matriz DADOS:
 *Coluna 0 --> X (Ax, Bx, Cx)
 *Coluna 1 --> Y (Ay, By, Cy)
 *Coluna 2 --> m (Coeficientes Angulares)

 */

public class Grafico extends JFrame 
{
  private JDesktopPane area;
  private JLabel label;
  int DADOS[][] = new int[3][2];

  	
  public Grafico(int DADOS[][])
  {
  	
  	this.DADOS = DADOS;
  	
    setSize(600,600);
    setVisible(true);
    
  }  
  
  public void paint(Graphics g)
  {
  	super.paint(g);
  	
  	g.drawLine(300,50,300,550);
  	g.drawLine(50,300,550,300);
  	g.setColor(Color.red);
  	//g.drawLine((DADOS[0][0]*100),(DADOS[0][1]*100),(DADOS[1][0]*100),(DADOS[1][1]*100));
  	
  }
      
}

Valeu mesmo pelo help!!

Beijux…
Até mais!!

Criado 14 de maio de 2006
Ultima resposta 15 de mai. de 2006
Respostas 2
Participantes 2