Vous êtes sur la page 1sur 5

TelaDados.java package exercicio; import javax.swing.JFrame; /** * * @author Edverto Martins */ @SuppressWarnings("serial") public class TelaDados extends javax.swing.

JPanel { public TelaDados() { initComponents(); } private void initComponents() { new javax.swing.ButtonGroup(); lbEscala = new javax.swing.JLabel(); lbLados = new javax.swing.JLabel(); txEscala = new javax.swing.JTextField(); txLados = new javax.swing.JTextField(); btDesenhar = new javax.swing.JButton(); btSair = new javax.swing.JButton(); txValor = new javax.swing.JTextField(); lbDescricao = new javax.swing.JLabel(); lbRotacao = new javax.swing.JLabel(); lbTranslacao = new javax.swing.JLabel(); lbEscalt = new javax.swing.JLabel(); setPreferredSize(getMaximumSize()); lbEscala.setText("Escala"); lbLados.setText("Quantidade de Lados"); btDesenhar.setIcon(new javax.swing.ImageIcon("C:\\Users\\Edverto Martins\\Documents\\NetBeansProjects\\CG\\src\\exercicio\\New Folder\\button_ok.png")); // NOI18N btDesenhar.setText("Desenhar"); btDesenhar.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btDesenharActionPerformed(evt); } }); btSair.setIcon(new javax.swing.ImageIcon("C:\\Users\\Edverto Martins\\Documents\\NetBeansProjects\\CG\\src\\exercicio\\New Folder\\exit.png")); // NOI18N btSair.setText("Sair"); btSair.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btSairActionPerformed(evt); } }); lbDescricao.setText("Digite o Valor Para Operao:"); lbRotacao.setText("1 - Rotao"); lbTranslacao.setText("2 - Translao");

Page 1

TelaDados.java lbEscalt.setText("3 - Escala"); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(lbEscala) .addComponent(txEscala, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(61, 61, 61) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(txLados, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(lbLados)) .addContainerGap(12, Short.MAX_VALUE)) .addGroup(layout.createSequentialGroup() .addComponent(lbDescricao) .addContainerGap(88, Short.MAX_VALUE)) .addGroup(layout.createSequentialGroup() .addComponent(lbRotacao) .addContainerGap(174, Short.MAX_VALUE)) .addGroup(layout.createSequentialGroup() .addComponent(lbEscalt) .addContainerGap(184, Short.MAX_VALUE)) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) .addComponent(txValor, javax.swing.GroupLayout.Alignment.LEADING) .addComponent(lbTranslacao, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addContainerGap(162, Short.MAX_VALUE))) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addComponent(btDesenhar) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(btSair) .addGap(42, 42, 42)))) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(lbEscala) .addComponent(lbLados)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(txLados, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) Page 2

TelaDados.java .addComponent(txEscala, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(29, 29, 29) .addComponent(lbDescricao) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(lbRotacao) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(lbTranslacao) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(lbEscalt) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(txValor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(btDesenhar) .addComponent(btSair)) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); } private void btDesenharActionPerformed(java.awt.event.ActionEvent evt) { // Inicializa os Objetos JFrame frame = new JFrame(); ColorJPanel colorJPanel = new ColorJPanel(); //Cria a Variavel para o numero de lados int vertices = 0; //recebe o valor da escala e lados colorJPanel.SetEscala(Integer.parseInt(txEscala.getText())); vertices = Integer.parseInt(txLados.getText()); //cria o vetor com numero de lados double Vx[] = new double[vertices]; double Vy[] = new double[vertices]; //recebe os pontos reais adicionando no vetor for (int i = 0; i < vertices; i++) { Vx[i] = Double.parseDouble(JOptionPane.showInputDialog("Digite x " + (i + 1) + ": ")); Vy[i] = Double.parseDouble(JOptionPane.showInputDialog("Digite y " + (i + 1) + ": ")); } //coloca os valores dos pontos no vetor principal colorJPanel.setVx(Vx); colorJPanel.setVy(Vy); colorJPanel.setVertices(vertices); //variavel de escolha para transformao int escolha = Integer.parseInt(txValor.getText()); //cria double double //cria double double vetor para tratamento do poligono e recebe os valores do vetor principal vetorx[]=colorJPanel.getVx(); vetory[]=colorJPanel.getVy(); um vetor auxiliar para as transformaes vetorRx[]= new double [vertices]; vetorRy[]= new double [vertices];

colorJPanel.setEscolha(escolha); Page 3

TelaDados.java switch (escolha) { case 1: int angulo = Integer.parseInt(JOptionPane.showInputDialog("Digite o valor da Rotao:")); for (int i = 0; i < colorJPanel.getVy().length; i++) { vetorRx[i]=((vetorx[i] - vetorx[0]) * Math.cos((Math.PI*angulo) / 180) - (vetory[i] - vetory[0]) * Math.sin((Math.PI*angulo) / 180)) + vetorx[0]; vetorRy[i]=((vetory[i] - vetory[0]) * Math.cos((Math.PI*angulo) / 180) + (vetorx[i] - vetorx[0]) * Math.sin((Math.PI*angulo) / 180)) + vetory[0]; } colorJPanel.setVRx(vetorRx); colorJPanel.setVRy(vetorRy); break; case 2: double transx = Double.parseDouble(JOptionPane.showInputDialog("Digite translao de x:")); double transy = Double.parseDouble(JOptionPane.showInputDialog("Digite translao de y:")); for (int i = 0; i < colorJPanel.getVx().length; i++) { vetorRx[i] = (vetorx[i] + transx); vetorRy[i] = (vetory[i] + transy); } colorJPanel.setVRx(vetorRx); colorJPanel.setVRy(vetorRy); break; case 3: double escalax = Double.parseDouble(JOptionPane.showInputDialog("Digite escala de x:")); double escalay = Double.parseDouble(JOptionPane.showInputDialog("Digite escala de y:")); for (int i = 0; i < colorJPanel.getVx().length; i++) { vetorRx[i] = ((vetorx[i] - vetorx[0]) * escalax) + vetorx[0]; vetorRy[i] = ((vetory[i] - vetory[0]) * escalay) + vetory[0]; } colorJPanel.setVRx(vetorRx); colorJPanel.setVRy(vetorRy); break; default: JOptionPane.showMessageDialog(null, "Opo no encontrada"); break; } frame.add(colorJPanel); frame.setVisible(true); } private void btSairActionPerformed(java.awt.event.ActionEvent evt) { System.exit(0); } private private private private private private private private private private private } Page 4 javax.swing.JButton btDesenhar; javax.swing.JButton btSair; javax.swing.JLabel lbDescricao; javax.swing.JLabel lbEscala; javax.swing.JLabel lbEscalt; javax.swing.JLabel lbLados; javax.swing.JLabel lbRotacao; javax.swing.JLabel lbTranslacao; javax.swing.JTextField txEscala; javax.swing.JTextField txLados; javax.swing.JTextField txValor;

a a

a a

TelaDados.java

Page 5